1
$\begingroup$

I am writing a script where I need many variables and for ease of usage I denote them as f[k,l,m,n]. I create a list of 4-tuples with the integers I need and I call these values using f@@{k,l,m,n}.

My problem is that I also need to assign values but writing f@@{k,l,m,n}=1 returns an error, declaring that the Tag Apply is protected. Is there any way to overcome this or do I need to assign my values using f[k,l,m,n]=1?

$\endgroup$
2
$\begingroup$

Since Set have HoldFirst Attribute, f @@ {k, l, m, n} will not be evaluated. You can do

Evaluate[f @@ {k, l, m, n}] = 1
$\endgroup$
  • $\begingroup$ @tst You can assign like Do[Set[Evaluate[f @@ t], g[t]], {t, tuples}] in a loop, whatever the values g are ... $\endgroup$ – BoLe Jul 11 '16 at 13:35
  • $\begingroup$ I dare you to do that twice :) $\endgroup$ – Kuba Jul 11 '16 at 13:38
  • $\begingroup$ @Kuba it reminded me of what we discussed here, OP would have to come to your solution if he has to do it twice:) $\endgroup$ – happy fish Jul 11 '16 at 13:41
  • $\begingroup$ @Kuba Or this: TraceScan[# /. _[expr_] :> Unset[expr] &, f @@ {k, l, m, n}] // Quiet (but this is actually terrible) $\endgroup$ – happy fish Jul 11 '16 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.