How to read user input in Lisp

I've not worked with LispWorks, so it's only a guess.

When compiler traverses your code it gets to the line (setq a (read)), it tries to read input, but there is no input stream while compiling, thus you get an error.

Write a function:

(defvar a)

(defun my-function ()
  (setq a (read))

It should work.


This should evaluate properly in your Lisp:

(defun read-3-numbers-&-format-sum ()
  (flet ((prompt (string)
           (format t "~&~a: " string)
           (finish-output)
           (read nil 'eof nil)))
    (let ((x (prompt "first number"))
          (y (prompt "second number"))
          (z (prompt "third number")))
      (format t "~&the sum of ~a, ~a, & ~a is:~%~%~a~%"
              x y z (+ x y z)))))

Simply evaluate the above function definition, then run the form:

(read-3-numbers-&-format-sum)

at your LispWorks interpreter.