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.
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