unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Garreau\, Alexandre" <galex-713@galex-713.eu>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Why is there no `until' in elisp?
Date: Wed, 17 Oct 2018 02:12:13 +0200	[thread overview]
Message-ID: <87y3axjusi.fsf@portable.galex-713.eu> (raw)
In-Reply-To: <jwvwoqhzis8.fsf-monnier+gmane.emacs.devel@gnu.org> (Stefan Monnier's message of "Tue, 16 Oct 2018 17:28:28 -0400")

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	other threads:[~2018-10-17  0:12 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-16 17:42 Why is there no `until' in elisp? Garreau, Alexandre
2018-10-16 19:16 ` Eric Abrahamsen
2018-10-16 19:31   ` Garreau, Alexandre
2018-10-16 20:23     ` Eric Abrahamsen
2018-10-16 23:00       ` Garreau, Alexandre
2018-10-19 15:28   ` Stefan Monnier
2018-10-16 21:28 ` Stefan Monnier
2018-10-17  0:12   ` Garreau, Alexandre [this message]
2018-10-17  2:04     ` Stefan Monnier
2018-10-17  9:14       ` Garreau, Alexandre
2018-10-17 15:06         ` Stefan Monnier
2018-10-17 16:51           ` Garreau, Alexandre
2018-10-19 15:34     ` Stefan Monnier
2018-10-19 18:08       ` Garreau, Alexandre
2018-10-17  8:04   ` Yuri Khan
2018-10-17  9:23     ` Garreau, Alexandre
2018-10-17  9:46       ` Yuri Khan
2018-10-17 11:06         ` Garreau, Alexandre
2018-10-17 17:50         ` Paul Eggert
2018-10-17 21:15           ` Garreau, Alexandre
2018-10-17 21:35             ` Paul Eggert
2018-10-17 21:49               ` Garreau, Alexandre
2018-10-17 22:33                 ` Paul Eggert
2018-10-17 22:54                   ` Garreau, Alexandre
2018-10-17 12:41     ` Elias Mårtenson
2018-10-17 15:03     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y3axjusi.fsf@portable.galex-713.eu \
    --to=galex-713@galex-713.eu \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).