3 ms·
That Python snippet reminds me of my least favorite part of CL: the LOOP macro. Although calling it part of CL is a bit of a misnomer since the standard specifi
by User23 5y ago
That Python snippet reminds me of my least favorite part of CL: the LOOP macro. Although calling it part of CL is a bit of a misnomer since the standard specifies it as, paraphrasing, do loops n stuff.
- vindarel 5y agoI struggled with loop too, but I finally just learnt it by example: https://lispcookbook.github.io/cl-cookbook/iteration.html https://lispcookbook.github.io/cl-cookbook/iteration.html and it's awesome.
- aidenn0 5y agoThere's like 20 pages of details on the loop macro; certainly more than "do loops and stuff"
- aidenn0 5y agoToo late to edit. Loop takes up an entire chapter of the ANSI specification and that chapter is 30 pages long. PDF made from latex files of Final Draft; LOOP is Chapter 6: https://lisp.com.br/archive/ansi_cl_standard_draft_nice.pdf https://lisp.com.br/archive/ansi_cl_standard_draft_nice.pdf
- User23 5y agoIt's more like 3 pages, with examples, when presented formally[1]. My point though is the standard specified behavior is quite limited, but it gives implementers broad latitude to "do loops and stuff" in a non-portable way[2] while still being in some sense standard. For example, Lispworks extends LOOP over SQL queries[3]. So sure I was being a bit tongue-in-cheek, but LOOP really is a set of not particularly compatible imperative languages that happen to be embedded in the various CL implementations. This is an artifact of the CL standardization process, which was virtually taking the set union of the features of the most popular implementations of the time, except in notable cases like LOOP where it was so hairy and incompatible that the standards body had to pick a relatively minimal intersection instead. [1] http://www.lispworks.com/documentation/HyperSpec/Body/m_loop.htm http://www.lispworks.com/documentation/HyperSpec/Body/m_loop... [2] http://www.lispworks.com/documentation/HyperSpec/Body/06_ai.htm http://www.lispworks.com/documentation/HyperSpec/Body/06_ai.... [3] http://www.lispworks.com/documentation/lw50/LWRM/html/lwref-84.htm http://www.lispworks.com/documentation/lw50/LWRM/html/lwref-...
- aidenn0 5y agoI don't think your second link says what you claim it does. Aside from being explicit that using let is totally fine (good) and that types are allowed, but not required to be specified (just like everywhere else that bindings are established), it just says that implementations can optimize things (duh?) and that there is no standardized way to extend it. The last point is probably everyone's biggest beef with LOOP since it's in stark contrast to most other things in the standard which often have very good ways to extend things. I find loop to be a fairly nice DSL for iteration. It could be better, it could be worse, and I like it better than all the DO constructs.
- User23 5y ago> I don't think your second link says what you claim it does. Based on the historical context of the standardization effort, I read "There is no standardized mechanism for users to add extensions to loop." as the standards body punting and basically giving implementers free reign to include whatever extensions they like. That's certainly what they did anyhow. However on a more careful reading I agree I probably misread that particular line. That's not to say that the practical effect isn't what I observed though. It's hard to find a solid reference, but look at this mess[1]. "Each of the above three LOOP variations can coexist in the same LISP environment." gives a hint of the messiness that follows. [1] https://github.com/sbcl/sbcl/blob/master/src/code/loop.lisp https://github.com/sbcl/sbcl/blob/master/src/code/loop.lisp
- lispm 5y agoHaving different iteration constructs or having multiple versions of the same was not untypical on a Lisp Machine, which booted into a single Lisp runtime, but which contained several different Lisp dialects and their language constructs. That way one did not need to reboot the computer to use a different LOOP variant - because the Lisp image was shared in the OS. The LOOP code you mentioned came from MIT and Symbolics from the 70s/80s, when multiple Lisp dialects were under use and sometimes, on a Lisp Machine, in the same runtime. The original MIT LOOP implementation had a single source code, which could be loaded into different Lisp dialects and systems. The CL standardization of LOOP was more than ten years later.
- pfdietz 5y agoSome folks swear by ITERATE. https://common-lisp.net/~loliveira/tmp/iterate-manual/iterate.html https://common-lisp.net/~loliveira/tmp/iterate-manual/iterat... I did have an issue with ITERATE, in that it does a kind of macroexpansion that interacts poorly with macrolets.