1

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?

tst
  • 953
  • 6
  • 13

1 Answers1

2

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

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