Background:
bar := {1, 1, 1};
foo[var_] := {Hold[var], 2 var}
SetAttributes[foo, HoldAll]
foo[bar]
Result, as expected:
{Hold[bar], {2, 2, 2}}
What I then do ( which is clearly not correct, but I don't know another way ) is that I ToString
the first element of the list, i.e. Hold[bar]
and then extract the substring "bar" out of it.
What I want is just this:
f[data_?VectorQ] := f[data, name_of_data]
f[data_?VectorQ, name_?StringQ] := "Save data as name" ...
So for example:
ape = {1,2,3};
bear= {2,3,4};
f[ape] translates to f[{1,2,3"}, "ape"]
f[bear, "bird"] translates to f[{2,3,4}, "bird"]
f[ape+bear] translates to Null or False.
Question: How do I access the name of a list in a function ?