If I set up
a = 1
Is there any command to get "a" by typing value 1?
Another example.
If
x = 3
y = 7
z = 6
then, Can I get 'xyz' by typing something like {3,7,6}?
If I set up
a = 1
Is there any command to get "a" by typing value 1?
Another example.
If
x = 3
y = 7
z = 6
then, Can I get 'xyz' by typing something like {3,7,6}?
a = 1;
Select[Names["Global`*"], Symbol[#] == 1 &]
{"a"}
Notice it may not be robust if you have a habit of writing procedures with OwnValues, e.g.: c := NotebookClose @ EvaluationNotebook[] etc.
ClearAll[a]
a := Echo["this is only echo but it may be something more damaging"];
b = 1;
Select[Names["Global`*"], Symbol[#] == 1 &]
>> this is only echo but it may be something more damaging{"b"}
To avoid this you can scan OwnValues instead of using Symbol/ToExpression:
Select[
Names["Global`*"]
, ToExpression[
#
, StandardForm
, Function[sym, MemberQ[OwnValues[sym], _ :> 1], HoldFirst]
] &
]
{"b"}
x = 3; y = 7; z = 3;, what would you expect to get back by then typing{3,7}? – Jason B. Feb 16 '18 at 22:53