libera/#lisp - IRC Chatlog
Search
19:48:00
mfiano
The unfortunate truth is that not everyone follows good style conventions that were put in place early on, leading to some very confusing code by those that expect them.
19:48:50
mfiano
Lisp being as flexible as it is, means you can do as you wish. Just know that if you expect it to be read by others, it might gather some unwanted feedback when asking for help on IRC and such.
19:49:43
mfiano
Also there's #commonlisp for that. This channel is about the Lisp family in general.
19:52:05
andreyorst
Clojure for example doesn't have this side-effecting convention for `when`, and the most used linter encourages replacing all single-branch `if` forms to `when` forms
19:52:43
andreyorst
I don't remember seeing that in Scheme when I've read SICP, but I may be misremembering, it was quite some time ago
19:56:14
thermo
famicom_guy: i also find that ,@(when flag `(one or more forms)) can be a useful idiom in macroprogramming, but imo it's an exception and to be used sparingly
19:57:20
mfiano
You can check out cltl or cltl2 or the subject, for example: https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node84.html
20:02:09
sham1
At least with Scheme, one probably wouldn't want to use (when ...) and (unless ...) when they want to use the return values of the arm being evaluated, since it's unspecified in both R7RS (they were not in R5RS and I'll assume they were not in earlier revisions either), although the return value *is* specified in R6RS
20:03:24
sham1
Well, the return value is specified in R6RS as far as it being the return value(s) of the last expression of the (when ...) and (unless ...) body when the condition is what one would expect
20:04:32
sham1
But yeah, you probably do want to be explicit about it, and do `if`s if you want to have a specific value returned for when a condition is true and false, instead of relying on whatever implicit return value you get out of `when` and `unless`
20:05:51
mfiano
I'm not familiar with Scheme, or its history here. It's interesting to know that it was unspecified earlier. I do know that Common Lisp took some inspiration from Scheme (and a few other Lisps).
20:06:53
mfiano
If that is the case, this style convention may be older than I thought. I am not too familiar with pre-ANSI Lisp.
20:17:08
sham1
Well for what it's worth, R5RS is from 1998, which is 4 years after ANSI common lisp, so one could easily also argue that the influence of CL is why R6 and R7 adopted `when` and `unless`. Anyway, (WHEN) and (UNLESS) are proper ancient. They existed at or probably before Emacs 1.1, which is like pre-GNU, so they are probably from MacLisp or its contemporaries
20:35:11
jcowan
The trouble with using the result of when/unless in R6RS Scheme is that if the test is satisfied/unsatisfied, you get the value of the last expression, but if the test is unsatisfied/satisfied, you get an arbitrary value -- which might happen to be the same as the value of the last expression. So in R7RS we switched to saying that the value is always arbitrary.
20:39:21
jcowan
The same argument applies for a single-branched `if`: if the first argument is true, you get the second argument, otherwise you get an arbitrary value -- which might happen to be the same as the second argument. And if you want more than one side-effecting expression, you would have to wrap them in progn/begin if you use single-branched if, whereas when/unless allows it directly.
20:58:20
jcowan
A line from the Spice Lisp manual: Since most-positive-fixnum is more than 100 million, you shouldn't need to use bignums unless you are counting the reasons to use Lisp instead of Pascal.
22:57:37
tfeb
jcowan: FWIW when and unless were in lisp machine lisp by 1983, see http://www.bitsavers.org/pdf/mit/cadr/chinual_5thEd_Jan83/chinualJan83_04_FlowOfCtl.pdf
2:07:16
White_Flame
instead of (when (foo) (bar)), you should use (and (foo) (bar)), because it's one character shorter