Pattern matching Inequality

二次信任 提交于 2020-02-02 02:04:29

问题


I'd like to extract arguments from instances of Inequality. Following doesn't work, any idea why and how to fix it?

Inequality[1, Less, x, Less, 2] /. Inequality[a_, _, c_, _, e_] -> {a, c, e}

回答1:


Inequality[1,Less,x,Less,2] /. HoldPattern[Inequality[a_,_,b_,_,c_]] -> {a, b, c}


Out: {1, x, 2}



回答2:


Also, you can do this:

Inequality[1, Less, x, Less, 2] /. Literal @ Inequality[ a_ , _ , c_ , _ , e_ ] -> {a, c, e}

ADL




回答3:


Why don't you use standard access to subexpression?

expr = Inequality[1, Less, x, Less, 2]; {a,c,e} = {expr[[1]], expr[[3]], expr[[5]]};



来源:https://stackoverflow.com/questions/3851390/pattern-matching-inequality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!