Replies: 6 comments 1 reply
-
I also ran into this during some casual playing around with XCL recently. Lexical closures first appeared in scheme, but I forget if they existed in CLTL1-era Common Lisp, or if they came later. I have a vague memory they came later to CL, but I can't find a cite for that. |
Beta Was this translation helpful? Give feedback.
-
This alternate definition works as expected: 2/5> (DEFVAR HELLO (LET ((MESSAGE "Hello world")) #'(LAMBDA () (PRINT MESSAGE))))
HELLO
2/7> HELLO
#<Interpreted closure @ 166,120750>
2/8> (FUNCALL HELLO)
"Hello world"
"Hello world" |
Beta Was this translation helpful? Give feedback.
-
THe problem with DEFUNs inside lexical scope and not at top level is there is no correct way to cause the file manager (aka file package) to save the definition or LOADFNS a definition. It's a feature of Common LIsp that isn't consistent with the "residential? style, which presumes a source file contains a sequence of definitions and expressions to evaluate. The Medley Common Lisp compiler (cl:compile-file) will compile it if you make a (text) file. This requires some discussion .... are lexical closures a common style or promoted by any Common LIsp implementation or book?? What are the advantages? |
Beta Was this translation helpful? Give feedback.
-
Lexical closures around a DEFUN seem kind of esoteric. But, in general,
lexical closures around lambda, flet forms, etc seem perfectly reasonable
to me.
…On Tue, Feb 25, 2025, 4:32 PM Larry Masinter ***@***.***> wrote:
THe problem with DEFUNs inside lexical scope and not at top level is there
is no correct way to cause the file manager (aka file package) to save the
definition or LOADFNS a definition. It's a feature of Common LIsp that
isn't consistent with the "residential? style, which presumes a source file
contains a sequence of definitions and expressions to evaluate. The Medley
Common Lisp compiler (cl:compile-file) will compile it if you make a (text)
file.
This requires some discussion .... are lexical closures a common style or
promoted by any Common LIsp implementation or book?? What are the
advantages?
—
Reply to this email directly, view it on GitHub
<#2016 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB7BB4SMYQYFKG3TMYM6KUD2RUDTPAVCNFSM6AAAAABWR4MQTCVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTEMZRHEZTMMY>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
issue #2051 to document the limitations and fix the specific case of DEFUN. |
Beta Was this translation helpful? Give feedback.
-
Concerning the possible uses of toplevel closures, the maintainers of the Common Lisp Coockbook are considering covering some use cases. |
Beta Was this translation helpful? Give feedback.
-
Consider this typical (at least in textbooks) idiom for creating closures in Common Lisp (there are better uses of closures but bear with me):
When I evaluate this expression at the top level of a XCL Exec I get an error such as:
Does Medley support toplevel closures like this? Does creating these closures require a different syntax?
Beta Was this translation helpful? Give feedback.
All reactions