0

Consider the following example function

(defun simple-function ()
  (dotimes (counter 10)
           (input-function)))

This requires input-function to be hard coded within the definition of simple-function. How can I have simple-function prompt the user for the function that they would want to use in place of input-function?

3

One way is to use an interactive code to prompt you for the function.

(defun  simple-function (input-function)
  (interactive "aInput function: ")
  (dotimes (counter 10)
    (funcall input-function)))

then you can write your own input like this perhaps, even using the counter variable from your loop.

(defun myfunc ()
  (message "%s: %s" counter
       (read-string "string: ")))

To use these, type M-x simple-function then you should be prompted for a function name. type myfunc, and press Enter (RET), and it should prompt you 10 times for a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.