0
|
3392 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# Question on evalution

Posted 10 years ago
 Hi all, analysing some code for learning the WL properly I came across the following "feature": {a, Sequence @@ {}, b}  and {a, Sequence[], b}  both give the identical result (namely {a,b}). But e.g. inside an "If"-statement this makes obviously a big difference: If[# < 1, Sequence @@ {}, #] & /@ {0.5, 1.5}  gives {1.5}, which is the expected result. But the use of If[# < 1, Sequence[], #] & /@ {0.5, 1.5}  results in {0.5, Null}, which is kind of the opposite of what was wanted. In trying to understand this "Trace[]" might be helpful: It seems to me that in the "Sequence@@{}"-case the If-statement is evalutated first (?) and in the "Sequence[]"-case the arguments of the If-statement - as a sequence - are evalutated first (?). In general my feeling is that in WL there is nothing which is not clever in some way! But where is here the underlaying concept? Many thanks for any comment! Henrik
2 Replies
Sort By:
Posted 10 years ago
 If has the HoldRest attribute, which prevents the evaluation of Apply (@@). It does not have the SequenceHold attribute which would prevent the Sequence[] splicing. In[1]:= SetAttributes[If, SequenceHold]; If[# < 1, Sequence[], #] & /@ {0.5, 1.5} Out[2]= {1.5} 
Posted 10 years ago
 Many thanks for this quick and profound answer, Ilian!I was wrongly looking at the attributes of Sequence[] and Apply[] ...Henrik