[Top][All Lists]

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

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

From: Yuri Khan
Subject: Re: Why is there no `until' in elisp?
Date: Wed, 17 Oct 2018 15:04:43 +0700

On Wed, Oct 17, 2018 at 4:33 AM Stefan Monnier <address@hidden> wrote:

> > [0] such as: (defmacro until (test &rest body) (declare (indent 1))
> > `(while (not ,test) ,@body))
> I like `until`.  As a matter of fact, I think `until` is more important
> than `while` for the following reason: it should not behave like the one
> you have above but rather like:
>     (defmacro until (test &rest body)
>       (let (res)
>         (while (not (setq res ,test)) ,@body)
>         res))
> While `while` doesn't have much else to return than nil, `until` does
> have a useful value to return, which is the non-nil value that caused it
> to exit.

In both these implementations, ‘until’ is still a pre-condition loop
(same as ‘while’, but with the condition negated).

However, in many languages that have an ‘until’ loop as a language
construct, it is a post-condition loop. The body is executed first,
then the condition is evaluated.

Of course, that raises additional questions…

* Should a hypothetical ELisp ‘until’ macro implement a post-condition loop?
* If so, should the condition be passed as the last argument?
  * If so, how should indentation work? (indent the body 4 spaces,
condition 2 spaces?)
  * The macro will then have to take body and condition as a single
&rest list, and split it, right?

reply via email to

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