Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: boolean operators
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Pierre Weis <weis@p...>
Subject: Re: boolean operators
> Is there a deep (or theoretical) reason for the particular status
> of boolean operators as "&" and "or"
> ( "prefix &" is not valid, for instance ?)

The problem is that there are no corresponding functions in Caml:
these syntactic constructs are equivalent to an if then else
expression, not to a function call to some primitive operation (as for
+ for example).

On the other hand, since Caml evaluation obeys call by value, there is
no means to define a function that does not evalute its
arguments. Hence you cannot define a function f such that
e1 & e2 could be equivalent to f e1 e2.

In effect, when e1 evaluates to false, the construct e1 & e2 returns
false and e2 is not evaluated. By contrast, the call f e1 e2 may
return some value but e2 will be evaluated before entering the body of
f.

Put it another way, & is a lazy construct: if e2 fails or does not
terminate then false & e2 evaluates to false, while any function call
with e2 as argument will fail or loop.

Pierre Weis
----------------------------------------------------------------------------
WWW Home Page: http://pauillac.inria.fr/~weis
Projet Cristal
INRIA, BP 105, F-78153 Le Chesnay Cedex (France)
E-mail: Pierre.Weis@inria.fr
Telephone: +33 1 39 63 55 98
Fax: +33 1 39 63 53 30
----------------------------------------------------------------------------