Question

I am a new lisp user. I have been trying to figure out how to use the lisp read command for about an hour by googling and looking for examples. I have been unsuccessful, and am finally throwing in the towel.

Can someone give me a very simple example of a lisp function that will accept 2 inputs, and add them?

My best attempt:

(defun func ()
(print "Enter first integer")
(read)
(print "Enter second integer")
(read)
(print (+ A B))
)

I have tried experimenting with (read A) or with a prefix to read (format t “~A” string) with no luck. All of the information on the internet that I have been looking for is extremely complicated, and I cannot make heads nor tails of it. Should it really be this hard? I may just be too familiar with bash/ksh/csh/sh...

Was it helpful?

Solution

You never assign the read input to your variables:

(defun func ()
  (print "Enter first integer") 
  (finish-output)
  (let ((a (read)))
    (print "Enter second integer")
    (finish-output)
    (let ((b (read)))
      (print (+ a b)))))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top