3 ms·
> This is like the Zig in that it's a hard-coded feature of the looping construct I think lisp’s loop isn’t hard-coded in the language, but defined in the stan
by Someone 4y ago
> This is like the Zig in that it's a hard-coded feature of the looping construct
I think lisp’s loop isn’t hard-coded in the language, but defined in the standard library. See for example the loop implementation at https://github.com/sbcl/sbcl/blob/master/src/code/loop.lisp https://github.com/sbcl/sbcl/blob/master/src/code/loop.lisp (about 2,000 lines because loop is a monster/very flexible (pick whatever you prefer. I would pick both))
- edflsafoiewq 4y agoLOOP isn't hard-coded into the language, but the possible clauses are hard-coded into LOOP. This is in contrast to ITERATE, which is an extensible CL looping macro, or the generator/iterator style popular in C++/Rust/Python/etc.
- kazinator 4y agoIn less than 400 lines of C99 preprocessing (not counting some utilities included), I made a loop macro for Awk which supports parallel and nested (cross-product) iteration, and user-definable clauses. https://www.kylheku.com/cgit/cppawk/tree/share/cppawk/include/iter.h https://www.kylheku.com/cgit/cppawk/tree/share/cppawk/includ... The bulk of the file is defining the clauses, each of which requires six lines: six simple macros have to be defined. (Kind of reminiscent of the five SETF expanders in Common Lisp for defining a new place.) This is thoroughly documented by a man page, including user-defined clauses. An complete example is given how to make a cause which iterates over alphanumeric strings, as in: BEGIN { loop (alpha_range (x, "aa0", "cc9")) print x } where x is stepped over "aa0", "aa1", ..., "aa9", ... "ab0", ..., "cc9".
- Jach 4y agoI'm a fan of Norvig's LOOP implementation from PAIP: http://www.norvig.com/paip/loop.lisp http://www.norvig.com/paip/loop.lisp It's missing some things from the full ANSI CL loop but it's just 223 code lines, and importantly not particularly clever code lines so that it serves as great instruction material for a method on how one could write one's own macro as complex as loop is.