Probably this question has no application but it helps understand basic issues about Attributes and functions.
I was writing a piece of code where I accidently defined a function like this:
ClearAll[f1]
SetAttributes[f1, HoldAll]
f1[list_List] := "evaluated"
When evaluated I get results as expected:
f1[{1, 2}]
(*"evaluated"*)
l={1,2};
f1[l]
(*f1[l]*)
But when I tried to check if this works with Pattern test I was surprised that evaluation happened in the function argument:
ClearAll[f2]
SetAttributes[f2, HoldAll]
f2[list_?(Head[#] == List &)] := "evaluated"
f2[{1, 2}]
(*"evaluated"*)
f2[l]
(*"evaluated"*)
Same result with Pattern Condition /;
My question is that what kind of behavior is this and why does not HoldAll hold the argument (which I understand is anything inside the brackets [] of the function) from evaluation and is this behavior same for all other Attributes?
Thank you.
PatternTestdocumentation – Simon Woods Dec 29 '15 at 22:38