2
$\begingroup$

For example like so.

x = 10;
xi = 11;
xv = 15;

Is there an automated way to spit these numbers out maybe 1-1000.

$\endgroup$
2
  • 5
    $\begingroup$ So you've seen RomanNumeral[] already? Consider Symbol[ToLowerCase[RomanNumeral[15]]]... $\endgroup$ Commented Jul 15, 2022 at 0:53
  • $\begingroup$ @J.M. yes I saw that I just need access to the global variables or something like that. $\endgroup$
    – William
    Commented Jul 15, 2022 at 0:55

2 Answers 2

4
$\begingroup$

I advise against

The reasons I will say it is "poor advice to assign roman numerals as top variables", is that it forces you to name the variable through strings operations, you end up with meaningless variable names (hard to debug) and in a functional programming language like Mathematica, you should be avoiding variables anyhow.

String variables

In this answer Leonid Shifrin writes

Using strings and subsequently ToString - ToExpression just to generate variable names is pretty much unacceptable, or at the very least should be the last thing you try. I don't know of a single case where this couldn't be replaced with a better solution. [...] The general [reason] is that they lead us outside of the symbolic world, and involve parsing, which is bad both for performance reasons and also just because one should avoid parsing as much as possible (for example, it may be unsafe).

Meaningless variable names

The idea of using roman numerals for variables suggests there will be many variables following that pattern. If what you need is indexed variables, there are other better solutions. Otherwise, these will be just meaningless variable names, which only hinder you and other people trying to understand the code.

Lingering definitions

I think it would be better to exploit the functional style of Mathematica and avoid leaving lingering variable definitions. See this question about keeping the kernel clean.

$\endgroup$
3
$\begingroup$

RomanNumeral will produce roman numeral representation for a given integer as a string. So, you could do something like Symbol[RomanNumeral[6]] or Symbol[ToLowerCase@RomanNumeral[6]]. Whether this is a good idea depends on context. My initial knee jerk reaction is that, no, it's not a good idea, but there may be a context in which it makes sense.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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