and/or now short-circuit

Updated to reflect that and/or actually short-circuit now.
This commit is contained in:
Brendan Curran-Johnson 2014-03-14 16:53:10 -05:00
parent a11f92da37
commit a210a673a2

View File

@ -151,20 +151,14 @@ case the first false value will be returned. Examples of usage:
=> (and True [] False True) => (and True [] False True)
[] []
.. note:: `and` shortcuts and stops evaluating parameters as soon as the first .. note::
false is encountered. However, in the current implementation of Hy
statements are executed as soon as they are converted to expressions. `and` shortcuts and stops evaluating parameters as soon as the first
The following two examples demonstrates the difference. false is encountered.
.. code-block:: clj .. code-block:: clj
=> (and False (print "hello")) => (and False (print "hello"))
hello
False
=> (defn side-effects [x] (print "I can has" x) x)
=> (and (side-effects false) (side-effects 42))
I can has False
False False
@ -919,21 +913,13 @@ parameter will be returned.
1 1
.. note:: `or` shortcuts and stops evaluating parameters as soon as the first .. note:: `or` shortcuts and stops evaluating parameters as soon as the first
true is encountered. However, in the current implementation of Hy true is encountered.
statements are executed as soon as they are converted to expressions.
The following two examples demonstrates the difference.
.. code-block:: clj .. code-block:: clj
=> (or True (print "hello")) => (or True (print "hello"))
hello
True True
=> (defn side-effects [x] (print "I can has" x) x)
=> (or (side-effects 42) (side-effects False))
I can has 42
42
print print
----- -----