reddit / emacs

Demo of cl-loop using actual Common Lisp's loop macro

a-concerned-mother · 2022-03-22 02:47
a-concerned-mother · 2022-03-22 02:49
While not Emacs specific I hope this can help some new elisp programmers get to grips with `cl-loop`. Nearly everywhere `loop` is used should be replaced with `cl-loop`.
nv-elisp · 2022-03-22 03:51
Also noteworthy, that the CL syntax is a bit different from `cl-loop`. The former uses keywords, while the latter provides bindings via similar symbols. e.g. (loop :for i ...) ;;vs (cl-loop for i...)
00-11 · 2022-03-22 03:57
FWIW - [Don't Loop - Iterate](https://manualzz.com/doc/o/bil6g/the-iterate-manual-and-paper---common-don-t-loop--iterate)
a-concerned-mother · 2022-03-22 04:37
Nice save I forgot to mention. CL supports both but unfortunately you are right the emacs implementation doesn't support keywords.
BettaGeorge · 2022-03-22 08:55
But it's functional. Why would I want a loop construct? Edit: I stand corrected. Y'all have convinced me to go check out this "loop" magic.
SlowValue · 2022-03-22 09:19
But this `iterate` macro does not exist in Emacs, right? The links on [EmacsWiki Iterate](https://www.emacswiki.org/emacs/Iterate) are dead and there is no package on MELPA ....
janoc · 2022-03-22 12:28
LISP is not a functional language (unlike Haskell, etc.). While it can be used to program in that style, it is not required and very often inefficient to do so.
Bodertz · 2022-03-22 15:45
The link doesn't seem to be dead: https://code.google.com/archive/p/i-iterate
00-11 · 2022-03-22 16:21
Right. Until you code it... ;-) (Or `M-x report-emacs-bug`, for an enhancement request.)
SoraFirestorm · 2022-03-22 17:42
As the other reply said, Lisp isn't functional or bust - you can (and people do) use a variety of different paradigms. Secondly, Emacs Lisp (especially older/core Emacs Lisp) tends to be written in a style that is *very* imperative and not at all functional. So the reality is that `loop` is more at home in Emacs Lisp than you apparently realize. Thirdly, `loop` kicks some serious butt. It is very powerful and has a lot of great tools for all sorts of different looping constructs. It is very expressive and nice to use.
modifiedenby · 2022-03-23 03:26
Elisp lacks tail recursion.
SlowValue · 2022-03-23 11:03
I get an 404 error Page and would call that a dead link ...
Bodertz · 2022-03-23 11:05
No 404 for me.
SlowValue · 2022-03-23 11:11
Thanks for your reply. I blocked XHR of `googleapis.com`, therefore the 404 error page.
SlowValue · 2022-03-23 14:05
[There is a package (of course) which fixes that, called `tco.e`l](https://github.com/Wilfred/tco.el)
takutekato · 2022-03-23 15:46
Emacs 28 has added `named-let` which can be used just like Clojure's TCO `loop`.