7
$\begingroup$

I have a list {a1, a2, ...... , an}, in which all as have been initialized to a number. I want to get:

 {Unevaluated[a1], Unevaluated[a2], ...... , Unevaluated[an]}

Is there a simple way to achieve this using Map, without getting a list of Unevaluated[value of ai]?

$\endgroup$
10
$\begingroup$
unevaluatedF = Function[{x}, Unevaluated@x, {HoldFirst, Listable}];

{a1, a2, a3} = {1, 2, 3};
unevaluatedF@{a1, a2, a3}

{Unevaluated[a1], Unevaluated[a2], Unevaluated[a3]}

$\endgroup$
7
$\begingroup$

you can try also:

{a1, a2, a3} = {1, 2, 3};
Unevaluated /@ Unevaluated@{a1, a2, a3}

(*{Unevaluated[a1], Unevaluated[a2], Unevaluated[a3]}*)
$\endgroup$
  • 1
    $\begingroup$ beat me by ten seconds. +1 $\endgroup$ – Mr.Wizard May 22 '15 at 17:13
3
$\begingroup$

First a link to a presentation everyone should read:

Now some additional methods:

List @@ Unevaluated /@ Hold[a1, a2, a3]

Unevaluated /@ Unevaluated @ {a1, a2, a3}

More contrived:

Unevaluated @@@ Thread @ Hold[{a1, a2, a3}]

{Unevaluated /@ Hold[a1, a2, a3]} // ReleaseHold

Delete[{Unevaluated /@ Hold[a1, a2, a3]}, {1, 0}]
$\endgroup$
0
$\begingroup$

Is this what you're seeking?

Unevaluated /@ {a1, a2, a3, a4}

(*

{Unevaluated[a1], Unevaluated[a2], Unevaluated[a3], Unevaluated[a4]}

*)

$\endgroup$
  • 1
    $\begingroup$ Not really, a1, a2, a3 are all initialized, so if a1 = 10, I will get Unevaluated[10], which could not be used in Set $\endgroup$ – Yituo May 22 '15 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.