The docs are clear that the test occurs before the bindings:
(doc if-let)
-
clojure.core/if-let
([bindings then] [bindings then else & oldform])
Macro
bindings => binding-form test
If test is true, evaluates then with binding-form bound to the value of
test, if not,
On Thursday, January 31, 2013 1:49:40 AM UTC+1, Sean Corfield wrote:
> but now that you've posted this, I
> can see some potential for confusion when folks first encounter
> if-let... Presumably the same confusion could arise for when-let?
>
yes, this is the confusion that you can incur in.
On Wednesday, January 30, 2013 8:51:47 PM UTC+1, Gary Verhaegen wrote:
> For your particular use-case, what you want is more along the lines of
>
> (if-let [errors (:password (fn-returning-errors))]
> ...)
>
yes, precisely!
mimmo
--
--
You received this message because you are subscribed
>> >>
>> >> (if-let [{errors :password} (function-returning-errors email password)]
>> >> true
>> >> false)
>> >>
>> >> In either case you never get the false branch when
>> >> function-returning-errors retu
>> wrote:
> >>
> >>> From the expansion we can see that if-let determine the result based on
> >>> the second param, in your case: {:key2 "a string"}, not the local
> >>> binding
> >>> you assumed(key1), and
> >>> I think it
e one you're
> >> looking for
> >>
> >> Mimmo
> >>
> >>
> >> On Jan 30, 2013, at 10:05 AM, James Xu
> >> wrote:
> >>
> >>> From the expansion we can see that if-let determine the result based on
> >>>
t;>
> >>> From the expansion we can see that if-let determine the result based on
> >>> the second param, in your case: {:key2 "a string"}, not the local
> >>> binding
> >>> you assumed(key1), and
> >>> I think it is reason
inding
>>> you assumed(key1), and
>>> I think it is reasonable, for example, if we have the following code:
>>>
>>> (if-let [{key1 key2} {:key2 "a string"}]
>>> true
>>> false))
>>>
>>>
>>> Should if-le
gt;>
>> Should if-let determine the result based on key1? key2? IMO {key1 key2}
>>in
>> a whole is more reaonable. And {key1 key2} == {:key2 "a string"}, then
>>the
>> result is true.
>>
>>
>>
>> On 13-1-30 下午4:51, "Mimmo Cosenza&
sumed(key1), and
>> I think it is reasonable, for example, if we have the following code:
>>
>> (if-let [{key1 key2} {:key2 "a string"}]
>> true
>> false))
>>
>>
>> Should if-let determine the result based on key1? key2? IMO {key1 key
ey1 key2} == {:key2 "a string"}, then the
> result is true.
>
>
>
> On 13-1-30 下午4:51, "Mimmo Cosenza" wrote:
>
>> Hi all,
>> I'm a little bit confused about the semantic of if-let macro.
>>
>> Suppose to call it as follows with
uot;}]
true
false))
Should if-let determine the result based on key1? key2? IMO {key1 key2} in
a whole is more reaonable. And {key1 key2} == {:key2 "a string"}, then the
result is true.
On 13-1-30 下午4:51, "Mimmo Cosenza" wrote:
>Hi all,
>I'm a little bit c
Hi all,
I'm a little bit confused about the semantic of if-let macro.
Suppose to call it as follows with map destructoring:
(if-let [{key1 :key1} {:key2 "a string"}]
true
false))
It returns true.
But,
(let [{key1 :key1} {:key2 "a string"}]
(if key1
13 matches
Mail list logo