Let's consider a function with evaluated and unevaluated arguments inside:
list1 = {1,2,3}
list2 = {x,y,z}
fun[list_]:={list,ToString@Unevaluated@list}
When I use Map over fun
I expect to get result like this:
{fun[list1],fun[list2]}
(*{{{1, 2, 3}, "list1"}, {{x, y, z}, "list2"}}*)
But instead I get this:
fun /@ {list1, list2}
{{{1, 2, 3}, "{1, 2, 3}"}, {{x, y, z}, "{x, y, z}"}}
This is surely connected with my misunderstanding of evaluation behaviour, but no obvious answer was found in Robby Villegas notebook https://library.wolfram.com/infocenter/Conferences/377/ , nor here in StackExchange. How to solve this problem?
ver. 12.1, Windows 10
EDIT
Setting attribute Listable
help a bit making unnecessary to use Map
:
SetAttributes[fun, {HoldAll, Listable}];
fun[{list1,list2}]
``
(*{{{1, 2, 3}, "list1"}, {{x, y, z}, "list2"}} *)