Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interactively read in two inputs and use them in a function call

Tags:

emacs

elisp

I am currently taking a class to learn elisp so I have no experience with this language. I am trying to interactively read in two inputs (the width and length of a rectangle) and then use them to call a function to compute the area of the rectangle. The code I have is as follows:

(defun rectangle_Area(w l)
"Compute the area of a rectangle, given its width and length  interactively."
(interactive "nWidth: ")
(interactive "nLength: ")
(setq area (rectangleArea w l))      
(message "The rectangle's area is %f." area))

Currently I get a wrong number of arguments error. Like I said, I have no previous experience... all I really need to know is how to store/read in two separate values using interactive.

Thank you for any help

like image 421
ola Avatar asked Jan 21 '13 23:01

ola


Video Answer


1 Answers

C-hf interactive RET:

To get several arguments, concatenate the individual strings, separating them by newline characters.

So we have:

(defun rectangle_Area(w l)
    "Compute the area of a rectangle, given its width and length  interactively."
    (interactive "nWidth: \nnLength: ")
    (setq area (rectangleArea w l))      
    (message "The rectangle's area is %f." area))
like image 200
Anton Kovalenko Avatar answered Oct 25 '22 02:10

Anton Kovalenko