Message Boards Message Boards

0
|
5309 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Build a list of HoldForm[symbol]?

Posted 5 years ago

I have a list of symbols {sym1,sym2, sym3,...} I would like to have Mathematica build the list {HoldForm[sym1],HoldForm[sym2],HoldForm[sym3], ...} The purpose is to build a list for use in Switch. to allow print of the symbol associated with a computed value. How does one prevent Mathematica from evaluating the symbol I want to place in the HoldForm?

choices = Riffle[varlist, holdlist];
v[value_] := Apply[Switch, Flatten[{value, choices, _, none}]];
POSTED BY: Douglas Kubler
4 Replies
Posted 5 years ago

Yes thank you, excellent. Just what I wanted - a list of symbols in the same order as the values. Nesting is not necessary. res1 for the values and res3 for the symbols. res2 is an interesting in-between result.

ClearAll[myList];
Attributes[myList] = HoldAll;
sym1 = 1;
sym2 = 2;
sym3 = 3;
res1 = List[sym1, sym2, sym3]            
res2 = myList[sym1, sym2, sym3]          
res3 = HoldForm /@ res2 
Print[res1[[1]], " ", res2[[2]], " " res3[[3]]]
POSTED BY: Douglas Kubler

A List is just a function which does not do anything besides being a container (well, sort of). In this way you can define you own "List function" with special properties, e.g.:

ClearAll[myList];
Attributes[myList] = HoldAll;

Then you can do:

l1 = {1, 2, 3};
l2 = {4, 5, 6};
List[l1, l2]            (* Out:  {{1,2,3},{4,5,6}}   (clearly!)  *)
myList[l1, l2]          (* Out:  myList[l1,l2] *)
func /@ myList[l1, l2]  (* Out:  myList[func[l1],func[l2]] *)

Is it this you have in mind?

POSTED BY: Henrik Schachner
Posted 5 years ago

So far as I know, the only way to construct HoldForm[symbol] is to manually enter (type) it. Any programmatic use of a symbol is replaced by its evaluation, e.g. if you try to Map HoldForm on a list of symbols you get each evaluation of each symbol, not the symbol names. All examples are examples of failure.
(Try? Holding a list of symbols holds the list name, not the list members.)

POSTED BY: Douglas Kubler

Hello, I didnt understand your question. Did you try to use Hold?

Could you insert your full code here?

Thanks.

POSTED BY: Estevao Teixeira
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract