Say, I want to take the first part of an operation in a function:
In: func[operexpr_] := operexpr[[1]];
func[a < b]
Out: a
But every once in a while a numerical representation of both a and b will end up being passed to the function.
Outside the function, this can be simply
In: Unevaluated[2 < 3][[1]]
Out: 2
But how do I do this in a function?
In: func[operexpr_] := Unevaluated[operexpr][[1]];
func[2 < 3]
Out: Unevaluated[True][[1]]
(* ^ doesn't work *)
In: func[operexpr_] := operexpr[[1]];
func[Unevaluated[2 < 3]]
Out: True[[1]]
(* ^ still doesn't work *)
In: func[operexpr_] := Unevaluated[operexpr][[1]];
func[Unevaluated[2 < 3]]
Out: True[[1]]
(* ^ still doesn't work *)
How do I go about this? I know it's odd that an operation with fully evaluable values on both sides will be passed to the function and have to be broken down still (most of the time the "True" result is all we need). But, I'm doing operations with inequalities and treating it this way makes the implementation easy and short (this being a nuisance), which I favour when I write in scripting languages.
Also, it makes it possible to easily debug the larger function I'm actually constructing. By passing numerical values.
func[operexpr_] := Defer[operexpr][[1, 1]]
. I would have though thatSetAttributes[func, HoldFirst]
, would work, but I guess once it hitsPart
, the expression must get evaluated in order to extract parts of it? I'm not sure. $\endgroup$