3 ms·
Common Lisp doesn't have a top level lexical scope, which seems to be what you're looking for here. Putting something like VAR everywhere now causes issues bec
by pfdietz 3y ago
Common Lisp doesn't have a top level lexical scope, which seems to be what you're looking for here.
Putting something like VAR everywhere now causes issues because it's not a form that returns a value. Also, there's no place to hang declare forms on it. And if it's executed conditionally, what does that mean? The var is declared on one branch but not the other?
- ogogmad 3y agoWhy would a variable declaration be executed conditionally, unless you can somehow GOTO past the declaration? CL doesn't let you do that, does it? > top level lexical scope What does this mean? Every single other language lets you write: var x = y; Why is Lisp seemingly the only (imperative) language that doesn't?
- medo-bear 3y ago> Why would a variable declaration be executed conditionally, unless you can somehow GOTO past the declaration? CL doesn't let you do that, does it? http://clhs.lisp.se/Body/s_tagbod.htm#tagbody http://clhs.lisp.se/Body/s_tagbod.htm#tagbody http://clhs.lisp.se/Body/s_go.htm#go http://clhs.lisp.se/Body/s_go.htm#go
- pfdietz 3y agoOne reason to not allow this is that it breaks the equivalence that (for example) (progn <form>) is equivalent to <form>
- martinflack 3y ago^ This is huge. A lot of top-level macro usage would be really annoying to implement if wrapping a PROGN around top-level commands neutered their effect.
- HexDecOctBin 3y agoWhy is this a problem for Common Lisp, and not for the dozens of Scheme implementations that allow you to (define ...) anywhere? (never mind what the RnRS standard says) > And if it's executed conditionally, what does that mean? The var is declared on one branch but not the other? Here is some C code: if (cond()) { preamble(); int a = 5; do_stuff(a); } else { do_stuff(6); } And some Scheme code: (if (cond) (begin (preamble) (define a 5) (do-stuff a)) (do-stuff 6)) So why can't Common Lisp have the equivalent? (if (cond) (progn (preamble) (var a 5) (do-stuff a)) (do-stuff 6)) Instead, CL forces you to do this: (if (cond) (progn (preamble) (let ((a 5)) (do-stuff a))) (do-stuff 6)) Do you see the problem? Common Lisp wants you to declare every set of intermediate variables in a nested scope, leading to super-deep nesting unless you start breaking you function into small pieces for no reason (which then hurts readability). This is why languages die, when the old guard refuses to see that there are better ways of doing things than what they are used to.
- deleted 3y ago[deleted]
- medo-bear 3y ago> Do you see the problem? No. Explicit scoping is a huge plus. > This is why languages die, when the old guard refuses to see that there are better ways of doing things than what they are used to. Don't mistake this for not being able to see beyond your nose.
- HexDecOctBin 3y agoSo, every other language that doesn't create a new nested scope for every consecutive group of intermediate variables is doing it wrong? Which is to say, almost every language apart from Common Lisp. Does that sound reasonable to you?
- kragen 3y agowhile i'm not sure lisp's approach is better in this case, i do think it's fairly common that 'almost every language apart from ... lisp' 'is doing it wrong', so i don't think that would be an unreasonable position to hold on those grounds ;)
- kazinator 3y agoTXR Lisp has a form of unhinged let in the "opip syntax" that underlies all of its threading macros. https://www.nongnu.org/txr/txr-manpage.html#S-F2CAF1CB https://www.nongnu.org/txr/txr-manpage.html#S-F2CAF1CB For instance (flow 1 (+ 2) (let x) ;; x is 3 now (+ 3) (let y) ;; y is 6 (+ 4) ;; pipeline value is 10 now (+ x y)) ;; 19 returned: (+ 3 6 10) There is a (let (var1 init1) (var2 init2) ...) syntax supported also. Both these variants act as pass-through pipe elements: they bind variables that are in scope of the rest of the pipe. However, if you use the normal (let ((var init) ...) ...) syntax, then that is not special any more; it is just the regular let being threaded, like any other operator. It does not bind variables visible to the rest of the pipe. Outside of this, there are only let and let* which resemble the Common Lisp ones. Note that this construct makes sense even in pure code; it was not introduced for the sake of inserting side effects between variable definitions, but for capturing the output at specific points of the pipe, binding it to a name.
- pfdietz 3y agoThere's a de facto standard macro for Common Lisp that does something similar, called nest. It's in UIOP.