3 ms·
LOOP 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 m
by edflsafoiewq 4y ago
LOOP 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.