this post was submitted on 24 Nov 2023
1 points (100.0% liked)

Lisp

55 readers
3 users here now

founded 1 year ago
MODERATORS
 

I'm learning common lisp and the subtleties of scoping really troubles me. For example, running this piece of ("double-let") code

(let ((x 10))
  (funcall
    (let((x 20))
      (lambda () x ))))

gives me 20 in Clisp and 10 in SBCL. I'm not even sure this is a dynamic/lexical scoping issue, because a typical example that demonstrates scoping would concern special variables defined with defvar/defparameter, like

(defvar *x* 10)
(defun foo ()
  (let ((*x* 20))
    (bar)))
(defun bar ()
  (print *x*))
(foo)

a dynamic-binding language is supposed to give 10, and lexical-binding one 20. (BTW I tested this with Clisp and SBCL, both gave me 10.)

โ€‹

So what is causing different behavior with the "double-let" example? Does SBCL not create an closure with the lambda function?

I would appreciate it if someone would explain, or point out references.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] zyni-moe@alien.top 1 points 1 year ago

You have done something which has made x be globally special. Restart your SBCL and it will be fine.