Mathematica Asked on August 14, 2021
Here is what I have tried first.
Thread[f["x", {"1", "2"}]]
{f["x", "1"], f["x", "2"]}
But the weirdest thing happened when I substituted StringJoin
for f
Thread[StringJoin["x", {"1", "2"}]]
"x12"
I thought it would be like this below
{"x1","x2"}
Is there anyone who can explain this?
Wrap StringJoin
with Unevaluated
to prevent evaluation of StringJoin
before Thread
gets to work:
Thread[Unevaluated @ StringJoin["x", {"1", "2"}]]
{"x1", "x2"}
Alternatively, you can use
Thread[foo["x", {"1", "2"}]] /. foo -> StringJoin
{"x1", "x2"}
Correct answer by kglr on August 14, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP