Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • $\begingroup$ You do Module[{a}, a[1] = 7; Print[a[1]]]? $\endgroup$ Commented Oct 17, 2024 at 19:24
  • 3
    $\begingroup$ I'm tempted to vote to close. I don't think you've provided enough information to explain what the impedance is in your current situation. It's not clear to me why you'd even bother with your ToExpression["a"<>"1"] strategy when you're wanting to "localize" variables in Module, Block, or With anyway. I don't think "isn't it ridiculous?" is a legitimate question for this forum. I could come up with several ways to create some sort of indexing within these structures, but there isn't nearly enough information here for me to provide clear explanations or guidance. $\endgroup$ Commented Oct 17, 2024 at 21:14
  • 1
    $\begingroup$ Somewhat related: mathematica.stackexchange.com/q/32648/1871 mathematica.stackexchange.com/q/285628/1871 "…it is advised to use indexed variable…" Yeah so I myself tend not to make such advice these days. BTW is it an official advice? I'm under the impression that this is just something frequently suggested by some experienced users. $\endgroup$ Commented Oct 18, 2024 at 0:25
  • 1
    $\begingroup$ @xzczd I think the advice about indexed variables is being taken to broadly and too literally. The most common situation where that advice is given is as an alternative to Subscript. Subscript is really a formatting utility and doesn't really lend itself to the use of just "subscripted variable" like people want it to be--like one could write on a chalkboard in math class. $\endgroup$ Commented Oct 18, 2024 at 19:42
  • 1
    $\begingroup$ @xzczd Furthermore, in any programming language, creating list of variables like a1, a2, a3..., is a code smell. You can't say it's always bad programming, but it's bad often enough that you should be suspicious. 99% of the time, the semantic that is desired can be better represented by Indexed, Part, or down-values, or something else entirely. $\endgroup$ Commented Oct 18, 2024 at 19:47