Nick Guenther wrote:
>
> On 5/23/06, prad <[EMAIL PROTECTED]> wrote:
> > On Monday 22 May 2006 17:54, you wrot
> > > You can consider short-circuiting of Boolean evaluation
> greedy, but it a
> > > feature which may also save clock cycles if the right-most
> sub-expressions
> > > are costly to evaluate.
> > >
> > thanks to all for the responses! what a great list!!
> >
> > using the links and explanations provided, i was able to
> determine that php
> > short-circuits evaluation (aka lazy evaluation):
> > http://ca3.php.net/manual/hk/migration.booleval.php
> >
> > which is nice to know since i was thinking of rewriting some
> code (but now
> > don't need to).
> >
> > i was puzzled reading something on one of the wikipedia links provided:
> > "The opposite of lazy evaluation is eager evaluation, also
> known as strict
> > evaluation. Eager evaluation is the evaluation behavior used in most
> > programming languages."
> > http://en.wikipedia.org/wiki/Lazy_evaluation
> >
> > it would seem to me that lazy evaluation makes more sense than eager
> > evaluation since it is both more logical and economical.
> >
> > i do not know much about language interpretation or compilation
> processes, but
> > how can it possibly be of any advantage to do 2 things when you
> can get away
> > doing just one?
> >
> > so why would 'most programming languages' NOT use it? there must be some
> > benefit eager evaluation offers despite what seems to be a lack
> of efficient
> > evaluation.
Boolean 'or' requires a couple of booleans in order to work.
In order to get a boolean, the expression must be evaluated.
In order to not blow up, the expression must be evaluable.
This also prevents meaningful expressions like IF A < B < C ...
or IF A or B < C ...


> >
> > is eager evaluation easier to design or implement perhaps?
>
> I think you misunderstand what eager evaluation is. Eager
> evaluation is that
> x = y + 2
> Sets x to the value of 2 more than y, or errors if y is not defined.
> Lazy evaluation just stores the literal fact that x is y + 2, and then
> only resolves the value of y + 2 when x is needed for something else.
> Language like Lisp, R (aka S) and Mathematica do lazy evaluation.
>
> Short circuiting is different from that, though related.
>
> -Nick
Related, yes.
Languages like Lisp are able to do lazy evaluation.
Most languages cannot even consider it.
Something like (setq x (+ y 2)) is NOT lazy evaluation.
(But (setq x '(+ y 2)) and a smart-alecky eval would do lazy evaluation;)
(BAH: a smart-alecky eval can make the original do lazy evaluation;)
Methinks the primary advantage of lazy evaluation is that your program
soes not blow up, at least not immediately, if you are missing something
essential to its operation.

The main reasons for using short-circuit evaluation is so that
If x!=0 and a/x > 1 then ...   doesn't blow up when x=0
(Yeah, I know, C gets confused without the parens)
(Yeah, I know, C considers = as an assignment operator rather than a
comparison)

Reply via email to