this post was submitted on 16 Oct 2023
1 points (66.7% liked)

Emacs

313 readers
3 users here now

A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!

Get Emacs

Rules

  1. Posts should be emacs related
  2. Be kind please
  3. Yes, we already know: Google results for "emacs" and "vi" link to each other. We good.

Emacs Resources

Emacs Tutorials

Useful Emacs configuration files and distributions

Quick pain-saver tip

founded 1 year ago
MODERATORS
 

While a for-loop is a straightforward construct in other programming languages, the loop macro, despite its power, can present challenges due to its intricacy. I find myself frustrated by its complexity.

However, its conceptual abstractions are intriguing. Take, for example, the following code snippet:

(loop for i below 10 sum i)

The utilization of the term "below" in this context is particularly striking. Contrastingly, in languages like JavaScript, I typically read "i < 10" as "i less than 10," pronouncing the two words "less than" in order to read the "<" symbol.

The act of reading "<" as "less than" momentarily interrupts my cognitive flow between the two words. The loop macro condenses it as a single word, "below," allowing me to pronounce "i < 10" more succinctly and smoothly, without interruption. Another viable alternative could be "under."

Moreover, the expression `1 < i < 10` can be read as "from 1 to 10."

(loop for i from 1 to 10 sum i)

It enhance code readability mentally and streamline cognitive processing.

top 4 comments
sorted by: hot top controversial new old
[–] save-lisp-and-die@alien.top 1 points 1 year ago (2 children)

You make a good point about readability. I find if I can't pronounce it, I don't understand the code. Saying code out loud can help me tell if it's correct.

I LOVE the hideous monstrosity that is the loop macro. You can pry that hugger from my cold dead face. Warts are the new beauty mark.

But for loop haters, there's the iterate package which I've heard is more lispy.

[–] AbstProcDo@alien.top 1 points 1 year ago

`below` and 'from to` read like a natural langugage which make the code more intuitive.

[–] uita23@alien.top 1 points 1 year ago

Nonsense. LOOP is peak lispy. It's so lispy it's standard! http://www.lispworks.com/documentation/lw51/CLHS/Body/06_a.htm

[–] github-alphapapa@alien.top 1 points 1 year ago

loop also has other conveniences like upto, downto, by, collect, concat, with VAR = FOO then BAR, etc.