On Tuesday, May 15, 2012 3:26:52 PM UTC-4, Aaron Cohen wrote:
>
> Does the principle of least surprise suggest that multiple bindings be
> combined with AND or OR?
>
>
For `when-let', I would expect it to work like nested when-lets:
(when-let [x (exp-1)
y (exp-2 x)
z (exp-3 y)]
[x y z])
would be the same as
(when-let [x (exp-1)]
(when-let [y (exp-2 x)]
(when-let [z (exp-3 y)]
[x y z])))
For the behavior of `if-let' to not be suprising given this definition
of `when-let', I think it would have to behave similarily:
(if-let [x (exp-1)
y (exp-2 x)
z (exp-3 y)]
[x y z]
'failed)
would be the same as
(if-let [x (exp-1)]
(if-let [y (exp-2 x)]
(if-let [z (exp-3 y)]
[x y z]
'failed)
'failed)
'failed)
So, AND I guess. But later expressions can refer to earlier ones, just
like in `let'.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en