Open lassik opened 3 years ago
lst
looks better.let
loops, I usually use iter
for tail recursion iteration. But I'm fine with any other names like loop
when there is a single loop and inner
/outer
if there are two loops. In JavaScript, I also use loop
or recur
(when using named recursive IIFE).first
and rest
names.We can create CONTRIBUTING.md
file that will list the common names. The file name is GitHub convention.
(let loop ...)
is probably the most common name to call it. I haven't seen iter
in other code bases so far.
I am not in the target demography, but I really dislike the lst
and lis
abbreviations. Even just l
is better.
The loop over x
in xs
makes much more sense to me.
Agreed on lst
, it could be an abbreviation for either last
or list
. Now we're really getting into the bikeshedding :)
For last we can just use last
, and leave lst
for list so we don't use list
name.
OK, since nobody else has commented, let's use lst
.
I'm fine with first
and rest
.
Are inner
/outer
loop
/recur
reasonable compromises. recur
is in Clojure, and I'm told recurse
sounds like "cursing again", so recur
is decent (no pun intended).
D'oh... Clojure's recur
does not allow general recursion, only tail recursion, i.e. iteration.
I think that loop
/ recur
is not a good idea because the names don't match (if they would use both in nested let's), if they were functions/macros they would do completely different things. An alternative is to always use inner
/ outer
if there are two loops (if there are more they should be extracted into functions). And if there is one loop I think that it can be anything I'm fine with both recur
/ loop
. You can pick the one you think is best.
Also need to add that the code needs to have spaces instead of tabs it may look nice in one editor but be broken on the website or in another editor. One person added a code snippet with tabs and looked like broken indentation but he only use 4 stops in the editor and I think that the browser uses 8, because replacing the tabs with 4 space fixed the indentation issue,
I think that
loop
/recur
is not a good idea because the names don't match (if they would use both in nested let's), if they were functions/macros they would do completely different things.
The idea is that looping and recursion are different things; looping is O(1) tail recursion, general recursion is O(n). But Clojure has made this confusion because its recur
is not real recursion, so I agree that it's best to avoid in a cookbook.
An alternative is to always use
inner
/outer
if there are two loops
Works for me. Or name them according to what they do.
(if there are more they should be extracted into functions).
Agreed.
And if there is one loop I think that it can be anything I'm fine with both
recur
/loop
. You can pick the one you think is best.
(let loop ...)
is probably the most standard. There's even http://letloop.xyz/ :)
Also need to add that the code needs to have spaces instead of tabs it may look nice in one editor but be broken on the website or in another editor. One person added a code snippet with tabs and looked like broken indentation but he only use 4 stops in the editor and I think that the browser uses 8, because replacing the tabs with 4 space fixed the indentation issue,
Agreed. It makes no sense to use tabs in Lisp code, since the 2-space indent is universally accepted.
We should probably decide on common names to use for variables in similar situations. For example:
list
argument to procedure (orlis
orlst
) by default?(let ((elem (car list)) (rest (cdr list))) ...)
(let loop ...)
?inner
andouter
with nested loops.loop
andrecurse
are good ways to differentiate proper tail recursion (needs O(1) stack space) from general recursion (O(n) stack space).Haskell has a convention of using
x
for a list element, andxs
for the list.xs
is meant as the plural ofx
: "multiple x's". They also usey
andys
.