Question on Condition (/;)

前端 未结 2 1644
名媛妹妹
名媛妹妹 2021-02-04 12:39

Condition has attribute HoldAll which prevents evaluation of its first argument before applying the Condition. But for some reason C

2条回答
  •  说谎
    说谎 (楼主)
    2021-02-04 12:59

    Condition use often depends on what is in the left hand side, so it must evaluate the LHS at least to some degree. Consider:

    MatchQ[3, a_ /; IntegerQ[a]]
    
       True
    p = {a_, b_};
    
    MatchQ[{3, 0.2}, p /; IntegerQ[a] && b < 1]
    
       True

    Both for this and from this, I would have guessed that Condition had attribute HoldRest rather than HoldAll. It probably needs HoldAll for some internal use, perhaps related to the SetDelayed usage.

提交回复
热议问题