3

There exist many related posts, but has it ever been explained in a clear and detailed enough way?

Notice a variant of the question in title is

Why doesn't

lst = {a, b, c};
Thread[Unevaluated@f[lst]]

return

{f[a], f[b], f[c]}

?

  • Comments are not for extended discussion; this conversation has been moved to chat. – Kuba Jan 29 at 17:23
  • To the downvoter, I am interested in what's wrong with my question, would you please elaborate. I'm not trying to complain here, I just want improve my question if possible. – xzczd Jan 31 at 13:28
-1

ANSWERING THE QUESTION IN THE TITLE:

I'm not sure exactly what you don't understand about this, but I can take you through this step by step.

b = a is a symbol assignment. It tells Mathematica "from now on, replace b with a."

Next, f[a_] := b defines a replacement rule. The a_ is a named pattern, and it is unrelated to the symbol a mentioned in the first line. This rule is exactly the same as the rule f[x_] := b -- the rule doesn't care what you name the pattern. It tells Mathematica to "replace every expression with f as the head and one argument with b".

Finally, f[1] is evaluated. The second rule tells Mathematica to replace this with b. Then the first rule tells Mathematica to replace this with a.

I'm not sure what exactly is confusing about this. It's important to understand that Mathematica is a pattern-replacement machine.

ANSWERING THE SECOND QUESTION:

Unevaluated@f[lst] tells Mathematica not to evaluate "lst", so, as far as Thread is concerned, lst is just an undefined symbol.

So, Thread[Unevaluated@f[lst]] is evaluated the same way as Thread[f[X]] where X is just an undefined symbol, which would give f[X].

So,Thread[Unevaluated@f[lst]] gives f[lst].

Next, f[lst] is evaluated, it gives f[{a,b,c}]

  • I'm sorry, but this isn't what I'm asking for. Notice the underlying issue of the 2 specific questions is the same, and what I'm looking for is an existing answer that answers both question in a clear and detailed enough way. (If we don't have an ready-made one, I'd like to see somebody create one in the main site rather than here, of course. ) – xzczd Feb 8 at 6:13
  • …Please notice here is Meta Mathematica Stack Exchange. – xzczd Feb 8 at 6:27
  • I'm still not sure what is the underlying question. How are these two related? What output would you expect? – Charles Gillingham Feb 8 at 6:27
  • You're right, I didn't notice that. My bad. – Charles Gillingham Feb 8 at 6:28
  • You may want to read the discussion in the chat: chat.stackexchange.com/rooms/88964/… – xzczd Feb 8 at 6:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .