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

Re: small Q



On Wed, 9 Aug 2000, Chris Page wrote:
> in article bruce-D726BE.09573309082000@news.akl.ihug.co.nz, Bruce Hoult at
> bruce@hoult.org wrote on 2000.08.08 14:57:
>
> > In article <87lmy7o7is.fsf@qiwi.uncommon-sense.net>, Boris Schaefer
> > <boris@uncommon-sense.net> wrote:
> > 
> >> How do you branch without "if"?
> >> In case you mean that you don't need "if" as a special form, I agree.
> > 
> > By making True and False be functions of two arguments ("then" and
> > "else") that each evaluate only one of them.  You define your comparison
> > operators to return one of these two functions, and you define "if" to
> > simply pass the then and else parts to the function returned by the
> > comparison.
> 
> Yes, but isn't this just pushing the problem around? Somewhere in there
> there has got to be a conditional operator, which is exactly what "if" is,
> no? For example, if you implement "if" with a conditional operator, how do
> you implement a conditional operator without "if"?

I think the point here is that you don't need a separate
conditional/if-thingy in addition to "lambda".  The "magic" about "if" (or
indeed most control structures with one or more "bodies") is that the
"then" and "else" bodies aren't evaluated unless and until the condition
is found to be true (respectively, false).  Expressions like

  (lambda () (body))

(aka "thunks"?) let you delay evaluation of "(body)" and the cunning
true/false/if definitions in Daniel Wang's post let you pick the right one
from two alternatives, then evaluate it (by applying the lambda to an
empty argument list).  I think Daniel's post omits some detail in terms of
how you write boolean combinators like "and" to evaluate down to his
true/false values and I'm not sure it shows how/when the "thunks" get
evaluated, but I'm no guru on this.

In languages like C/C++ (and probably countless others), you don't have
"real" lambdas to delay evaluation so I think you need special language
constructs; in Lisp, Scheme and Dylan (among others), you could just have
"lambda" under the hood, no other compiler magic needed.

BTW, just out of interest (and getting ever more OT :-) ML has lazy binary
"operators" called "orelse" and "andalso" -- are they or could they be
implemented in this way?

Hope that helped,
Hugh




References: