From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1094ba,ddafdc033e838b1d X-Google-Thread: 103376,cd51fe79965e9795 X-Google-Attributes: gid1094ba,gid103376,public Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.fortran,comp.lang.ada Subject: Re: Order of logical operations Followup-To: comp.lang.fortran Date: Sat, 05 Jun 2004 12:44:06 +0200 Organization: At home Message-ID: <2idme4Fm2e5nU1@uni-berlin.de> References: <40C0208A.80DBE53A@wldelft.nl> Reply-To: mailbox@dmitry-kazakov.de Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de bbhKFENske/nroJ2DMFEbgeRCGvZBN+cW/ibYQwDpF12/ANdI= User-Agent: KNode/0.7.2 Xref: g2news1.google.com comp.lang.fortran:1705 comp.lang.ada:1120 Date: 2004-06-05T12:44:06+02:00 List-Id: James Van Buskirk wrote: > "Arjen Markus" wrote in message > news:40C0208A.80DBE53A@wldelft.nl... > >> Short-circuiting does not necessarily lead to quicker programs. >> And if you really need it, you might invent a new operator, >> like ".cand." (the implementation ought to be very simple). > > As others have pointed out such operators have to be defined > at the language level. Not necessarily. The language might support a more general concept: lazy arguments. Consider: -- This is not Ada! function "and then" (Left : Boolean; Right : lazy Boolean) return Boolean is begin if Left then return True; else return Right; -- Right is evaluated only at this point on the -- caller's context. end if; end "and then"; It is a very powerful mechanism that allows to enforce the evaluation order of subroutine arguments: -- This is not Ada! function "&" (A : String, B : lazy String) return String is Value_A : String renames A; -- This evaluates A begin return Value_A & B; -- B is evaluated after A end "&"; Now it is safe to write: ... := Read_String & Read_String & Read_String; Though, that could be tricky to implement, especially if we consider lazy arguments of recursive calls, protected operations, side effects of lazy evaluations on alien contexts and all that stuff. -- Regards, Dmitry A. Kazakov www.dmitry-kazakov.de