开发者

Pattern matching Inequality

开发者 https://www.devze.com 2023-01-18 19:01 出处:网络
I\'d like to extract ar开发者_开发知识库guments from instances of Inequality. Following doesn\'t work, any idea why and how to fix it?

I'd like to extract ar开发者_开发知识库guments 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}


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


Out: {1, x, 2}


Also, you can do this:

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

ADL


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]]};

0

精彩评论

暂无评论...
验证码 换一张
取 消