From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Garreau\, Alexandre" Newsgroups: gmane.emacs.devel Subject: Re: Why is there no `until' in elisp? Date: Wed, 17 Oct 2018 13:06:51 +0200 Message-ID: <87k1mgg7ck.fsf@portable.galex-713.eu> References: <87murdu6to.fsf@portable.galex-713.eu> <87lg6xgc58.fsf@portable.galex-713.eu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1539774305 12837 195.159.176.226 (17 Oct 2018 11:05:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 17 Oct 2018 11:05:05 +0000 (UTC) User-Agent: Gnus (5.13), GNU Emacs 25.1.1 (i686-pc-linux-gnu) Cc: Stefan Monnier , Emacs developers To: Yuri Khan Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 17 13:05:00 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gCjdL-0003BZ-OW for ged-emacs-devel@m.gmane.org; Wed, 17 Oct 2018 13:04:59 +0200 Original-Received: from localhost ([::1]:35439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCjfS-0001Js-5W for ged-emacs-devel@m.gmane.org; Wed, 17 Oct 2018 07:07:10 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gCjfM-0001JY-CX for emacs-devel@gnu.org; Wed, 17 Oct 2018 07:07:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gCjfL-000267-Ea for emacs-devel@gnu.org; Wed, 17 Oct 2018 07:07:04 -0400 Original-Received: from portable.galex-713.eu ([2a00:5884:8305::1]:41924) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gCjfI-00021E-K0 for emacs-devel@gnu.org; Wed, 17 Oct 2018 07:07:01 -0400 Original-Received: from localhost ([::1] helo=portable.galex-713.eu) by portable.galex-713.eu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gCjf9-0004QE-JU; Wed, 17 Oct 2018 13:06:52 +0200 X-GPG-FINGERPRINT: E109 9988 4197 D7CB B0BC 5C23 8DEB 24BA 867D 3F7F X-Accept-Language: fr, en, it, eo In-Reply-To: (Yuri Khan's message of "Wed, 17 Oct 2018 16:46:08 +0700") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:5884:8305::1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:230442 Archived-At: Le 17/10/2018 =C3=A0 16h46, Yuri Khan a =C3=A9crit=C2=A0: > On Wed, Oct 17, 2018 at 4:23 PM Garreau, Alexandre > wrote: >> >> Something such as the C =E2=80=9Cdo=E2=80=9D construct might overcomplic= ate 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 =E2=80=9Cat-least-once=E2=80=9D case,= which is > also occasionally useful, e.g.: Attempt an API call until it succeeds. (=E2=80=A6or =E2=80=9Cuntil=E2=80=9D a non-blocking I/O function blocks) And no, there=E2=80=99s 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=E2=80=99ve saw this form of code idiomatic in basic software such as coreutils, inetutils, etc. >> > However, in many languages that have an =E2=80=98until=E2=80=99 loop a= s 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=E2= =80=99t do >> that. > > + Well, you mentioned the C =E2=80=98do=E2=80=99/=E2=80=98while=E2=80=99,= for one; it is a > continuation post-condition loop. C++, Java, PHP, Javascript and many > other languages inherited that. > + Pascal has =E2=80=98repeat=E2=80=99/=E2=80=98until=E2=80=99 (a terminat= ion post-condition loop), and > it was my first association for the name =E2=80=98until=E2=80=99. > + In Perl, both =E2=80=98while=E2=80=99 (continuation) and =E2=80=98until= =E2=80=99 (termination) can > be used as pre-conditions and post-conditions. The keyword is =E2=80=9Ccan=E2=80=9D. There=E2=80=99s no =E2=80=9Cuntil co= nd do thing done=E2=80=9D 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 =E2=80=9Cdo=E2=80= =9D or =E2=80=9Crepeat=E2=80=9D. Also =E2=80=9Cloop=E2=80=9D in some language I f= orgot (basic? sql?) I=E2=80=99m almost sure cl-loop has it. So it=E2=80=99s even compatible wi= th the last. > =E2=88=92 Bash=E2=80=99s =E2=80=98until=E2=80=99/=E2=80=98do=E2=80=99/=E2= =80=98done=E2=80=99 is a termination pre-condition loop, you=E2=80=99re rig= ht. Doesn=E2=80=99t one of the languages you mentioned have a =E2=80=9Cuntil=E2= =80=9D using a pre-cond rather than a post-cond?