this post was submitted on 10 Oct 2023
0 points (50.0% liked)
Lisp
64 readers
3 users here now
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
You shouldn't need
funcallin your common lisp code, but the way you defined your function requires it. You havedefunalready defines a function; you don't need to also wrap the function body in alambda. This definition allows you to avoid thefuncall:Though it's worth knowing that unlike in scheme, common lisp will return the value after a
setf. There's also a convenience macro calledincfthat increments variables so you can write the whole thing like this:And your other question: Why the different placing of the let?
In common lisp,
defun,defvar,defparameter,defmacro, ... all affect global scope, no matter where they appear. scheme'sdefinedoes not affect global scope; its effects are only visible locally. This means that adefuninside of aletbody still creates a globally accessible function that closes over the variables defined in theletbindings. Scheme, by contrast, needs to have adefineat global level (or at least outside thelet) but the function body still needs to close over theletvariables.