This is a style question I suppose, not sure.
Ok so I have this:
a := RandomInteger[{1, 10}];
f[a_] := a - a
f[a]
0
its ofc always going to be 0 because the 'a'-s are the same, how do I make it such that "some" 'a'-s are not the same, inside the function (I'm not sure how to explain this so bear with me)?
one way to do it ofc is just this:
a := RandomInteger[{1, 10}];
f[a_] := a - RandomInteger[{1, 10}]
f[a]
2
so now the first 'a' is the function call value of the first (and only, in this case) argument, the second 'a' is just evaluated on-the-spot and is not the same as the called 'a' (well it can be, there is a 10% chance in this case but hopefully you see what I mean)
However in this case its not immediately apparent that this second 'term' is of "type a" since its specifically restated into RandomInteger (or whatever 'a' would be, its just an example).
I am basically trying to make some kind of two different 'types' of 'a' in this case, 1 that is evaluated on function call and then another that is evaluated separately, inside the function call of the first one, if this makes sense.
Perhaps to be clearer, the second case with just using RandomInteger instead of 'a' is all fine and dandy, but it "doesn't look good" (whatever that means) I want it to have some sort of code-relation to the actual 'a' variable, that is all. So for instance if I defined a1=RandomInteger and then use that as the 'second a', its not good because now that is a new variable with no apparent connection to 'a'.
aList = Table[a, {2}]and then evaluateaList[[1]] - aList[[2]]. – J. M.'s missing motivation Jan 30 '21 at 19:54fone of theHold- attributes. For example,SetAttributes[f, HoldFirst]. This will make your original example work. – Leonid Shifrin Jan 30 '21 at 21:10Holdattributes are not as esoteric as you may think. If you want a mix, declare your functionHoldAll, but wrap the ones you want evaluated, inEvaluate, when passing to the function. You can read more aboutHold*attributes e.g. here, or in this Q / A. UsuallyHold*attributes are used to emulate pass by reference semantics and allow a function to modify its argument, but in general one can use them to pass unevaluated piece of code to a function, for whatever purpose. – Leonid Shifrin Jan 31 '21 at 16:55Holdattributes, would be to wrap the parameters you don't want to evaluate, inUnevaluatedwrapper. You can think ofUnevaluatedas a one-timeHoldattribute applied for a particular argument in a particular function call. You can read more onUnevaluatede.g. here and here. – Leonid Shifrin Jan 31 '21 at 17:03