[erlang-questions] guard clause oddity, maybe bug (in my brain)?
Jim
jim.rosenblum@REDACTED
Sat Nov 21 05:27:42 CET 2015
Thank you both, I guess I don't fully understand the associative and precedence of these operators. Having said that it is surprising to me that
(not is_tuple(Elt)) andalso ?IS_INDEX(I)
can ever evaluate to true when Elt is a tuple. Andalso short circuits so it's curious to me that a fully parenthesized clause that evaluates to false to the left of the andalso wouldn't short circuit everything regardless of what happens to the right of the andalso.
> On Nov 20, 2015, at 3:46 PM, Pierre Fenoll <pierrefenoll@REDACTED> wrote:
>
> Dmitry is on point.
>
> 1. Remove the useless braces around not is_tuple...
> 2. Add braces around ?IS_INDEX...
>
> If that fixes it, think about moving the braces inside the macro's definition.
>
>> On 20 Nov 2015, at 16:03, Dmitry Kolesnikov <dmkolesnikov@REDACTED> wrote:
>>
>> Hello,
>>
>> How does you macro IS_INDEX looks like?
>> e.g.
>>
>> 5> A = {1}.
>> {1}
>> 6> (not is_tuple(A)) andalso is_number(A) orelse A > 1.
>> true
>>
>> but
>>
>> 8> (not is_tuple(A)) andalso (is_number(A) orelse A > 1).
>> false
>>
>>
>> Best Regards,
>> Dmitry
>>
>>
>>> On Nov 20, 2015, at 4:03 PM, jim rosenblum <jim.rosenblum@REDACTED> wrote:
>>>
>>> I have a function:
>>>
>>> walk ([I|Is], [Elt|_]=Ts) when (not is_tuple(Elt)) andalso ?IS_INDEX(I) ->
>>> Element = index_to_element(I,Ts),
>>> case
>>> ... snip ...
>>> end.
>>>
>>> This function clause gets executed even though Elt is a tuple.
>>>
>>> I have a break point within this function clause. I am looking at the
>>> debugger at the break-point within the clause, and I can plainly see that Elt
>>> IS a tuple: within the debugger I can evaluate is_tuple(Elt) and it returns true,
>>> I can evaluate (not is_tuple(Elt)) and correctly get FALSE.
>>>
>>> So.... how can I be in this clause when the guard evaluates to false?
>>>
>>> Thoughts?
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list