emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is there no `until' in elisp?


From: Garreau\, Alexandre
Subject: Re: Why is there no `until' in elisp?
Date: Wed, 17 Oct 2018 02:12:13 +0200
User-agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu)

I do also believe `until' is actually more important than `while', first of
all, as I said, we can see that because it is more used in human
language, this is also the case because `while', in its condition,
refers to a both initial and transient state, while `until' refers to
its final state, which is what should interest us the most (especially
in functional programming that should be more interested at the result
than the source).

However I believe in minimalism, and I’m surprised you found something
different and incompatible, but still, I find, very very interesting: I
think `until' should refer to the version I gave because this is
probably the one which is going to be implemented naively by most
people, also it can be useful to try to retrieve the last body return
value, just as it is with `while': it is usually something you computed,
not some potential binary boolean that you might have known since the
beginning.  And then, of course, this introduce useless discrepancy
toward symmetry within respect `while'.  So your version should have a
different (maybe longer? I hope the least) name.

A trivial symetric `while' to yours is one that keeps the last true
value: `(let (res) (while (and! res ,test) ,@body) res) (while
introducing the notation fun![0]).

It may sound artificial but it is not, look thereafter.

I recently felt a big need of a form acting both as a `when' and a
`prog1' (a `when' that returns its condition / first argument), and
symetricaly for `unless' (in the end I used a (when-let ((var val))
(prog1 var . body)), but I’m pretty unsatisfied, like always when it’s
about finding an optimum in extreme factorization, maybe sometimes it’s
not possible).  This is no different.

This also recalled me that, but this might be a separate discussion, a
long time ago, when discovering cyclic lists through experimentation, I
thought that `while' could be implemented this way: `(and (prog1 . body)
. #1), and for until: `(or (prog1 . body) . #1).

And your until is precisely that.  Now you also got your interesting
counterpart for `until'.

While my minimal `until' is to yours what `progn' is to `prog1'.  Let’s
call yours `until1', then `until' is (let (res) (until1 test (setq res
(progn . body)))) (I still fill like a relation between both might be
better and more elegantly expressed… though the same stands for
when-prog1).

Another interesting version I dreamt of is the one that returns a list
of the return value of each iteration (in may be useful in both mine and
yours version): (lazy-map (lambda (var) . body) '(cons test (or test
#0))) (or any way of stopping to map/concat when it is returning nil).

[0] so that, for any `fun' where `fun!' (an imperative, side-effects
targeted, version of fun) is undefined: (fun! var . args) stands for
(setq var (fun! var . args)), such as (+! var 1 2) is (setq var (+ var 1
2)), (not! var) is (setq var (not var)) and (and! var bool1 bool2) is
(setq var (and var bool1 bool2) (this is all equivalent to C “+=”, “!=”
and “&=” (or better: C++ “&&=”)).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]