Is it possible to shorten the length of a (delayed) rule (i.e. lhs :> rhs
) when there are expressions which repeat several times? Those expressions involve values of the patterns matched in lhs
, so ideas that come to my mind, such as creating a pure function that takes the repeated elements as arguments, do not work.
A simple example of what I refer to can be:
Replace[ list , a_ :> {IntegerDigits[a],Length@IntegerDigits[a],IntegerDigits[a][[1]]} ]
Is there a way to write in such case IntegerDigits[a]
only once instead of three in there?
With[{rd = RealDigits[a]}, {a, Length@a, First@a}]
$\endgroup$Through[{Identity, Length, First}[RealDigits[a]]]
$\endgroup$Length@RealDigits[anything]
will always be $2$, becauseRealDigits
always returns a list of two elements. Was that supposed to beLength@First@RealDigits[a]
instead? $\endgroup$IntegerDigits
. The function doesn't directly relate to my problem, it was just a simple example to clarify a bit what I meant. $\endgroup$