How to read user input in Lisp

chope_chope picture chope_chope · Oct 3, 2014 · Viewed 11.5k times · Source

I'm very new to Lisp and am trying to write a program that simply asks a user to enter 3 numbers and then sums them and prints the output.

I've read that you can you a function like:

(defvar a)

(setq a (read))

To set a variable in Lisp, but when I try to compile my code using LispWorks I get the following error:

End of file while reading stream #<Concatenated Stream, Streams = ()>

I feel like this should be relatively simple and have no idea where I'm going wrong.

Answer

Mark Karpov picture Mark Karpov · Oct 3, 2014

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.