From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Order of logical operations
Date: Sat, 05 Jun 2004 12:44:06 +0200
Date: 2004-06-05T12:44:06+02:00 [thread overview]
Message-ID: <2idme4Fm2e5nU1@uni-berlin.de> (raw)
In-Reply-To: Um3wc.43236$3x.40166@attbi_s54
James Van Buskirk wrote:
> "Arjen Markus" <arjen.markus@wldelft.nl> 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
prev parent reply other threads:[~2004-06-05 10:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <slrncbtfkn.247.tconnors@tellurium.ssi.swin.edu.au>
[not found] ` <m11xkwd6ct.fsf@macfortran.local>
[not found] ` <slrn-0.9.7.4-31741-29330-200406040800-tc@hexane.ssi.swin.edu.au>
[not found] ` <40C0208A.80DBE53A@wldelft.nl>
2004-06-04 18:40 ` Order of logical operations James Van Buskirk
2004-06-04 20:06 ` Ed Falis
2004-06-04 21:09 ` Nick Roberts
2004-06-07 17:00 ` Warren W. Gay VE3WWG
2004-06-07 17:36 ` Ed Falis
2004-06-04 21:37 ` Björn Persson
2004-06-05 10:44 ` Dmitry A. Kazakov [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox