0

Just started doing some Lisp a few minutes ago. Trying to figure out why this program won't work properly. I am using SBCL and want to prompt user, read input, then print the statement.

(defun SayHello()
    (princ "What is your name? ")
    (let ((name (read))))
    (princ "Hello: ")
    (princ name))

When I run this I receive these warnings:

; caught WARNING:
;   undefined variable: COMMON-LISP-USER::NAME
;
; compilation unit finished
;   Undefined variable:
;     NAME
;   caught 1 WARNING condition
Coldchain9
  • 1,373
  • 11
  • 31
  • 1
    Your `let` block is closed immediately- it should include `(princ "Hello: ")` and `(princ name)`. The linked question contains correct code and also includes a problem you would have to solve right after this one. – Martin Půda May 06 '23 at 17:49
  • Totally fixed it. Didnt know the ```let``` had to be in the same block as it's ```princ```. Thanks! – Coldchain9 May 06 '23 at 17:52
  • No, the variable NAME has to be used inside the LET body, since it has been defined by the LET. – Rainer Joswig May 07 '23 at 06:54

0 Answers0