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 13:06:51 +0200
User-agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu)

Le 17/10/2018 à 16h46, Yuri Khan a écrit :
> On Wed, Oct 17, 2018 at 4:23 PM Garreau, Alexandre
> <address@hidden> wrote:
>>
>> Something such as the C “do” construct might overcomplicate the
>> language, while I think normal `while' and `until' are not only simpler
>> but also superior: with those you have the case of 0 loops, in which
>> basically works as a when.
>
> The post-condition loop enables the “at-least-once” case, which is
> also occasionally useful, e.g.: Attempt an API call until it succeeds.

(…or “until” a non-blocking I/O function blocks)

And no, there’s the no-body form of `while'/`until' which are handy for
that:

(until (call args))
(while (io args))

Or, if you need more instructions because your API is complex:

(until (progn (foo) (call args)))

(while (progn (bar) (io args)))

I’ve saw this form of code idiomatic in basic software such as
coreutils, inetutils, etc.

>> > 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.
>>
>> Which languages?  I looked again in bash to be sure, and bash doesn’t do
>> that.
>
> + Well, you mentioned the C ‘do’/‘while’, for one; it is a
> continuation post-condition loop. C++, Java, PHP, Javascript and many
> other languages inherited that.
> + Pascal has ‘repeat’/‘until’ (a termination post-condition loop), and
> it was my first association for the name ‘until’.
> + In Perl, both ‘while’ (continuation) and ‘until’ (termination) can
> be used as pre-conditions and post-conditions.

The keyword is “can”.  There’s no “until cond do thing done” where the
until is placed before and by itself makes it a post-cond.  You usually
have a special keyword for trigering post-cond, such as “do” or
“repeat”.  Also “loop” in some language I forgot (basic? sql?)

I’m almost sure cl-loop has it.  So it’s even compatible with the last.

> − Bash’s ‘until’/‘do’/‘done’ is a termination pre-condition loop, you’re 
> right.

Doesn’t one of the languages you mentioned have a “until” using a
pre-cond rather than a post-cond?



reply via email to

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