The WORD! vs. TEXT! Representation Gap

Something that seems to come up a lot is exemplified in this issue with Rebmake regarding optimization levels.

The issue is that C compilers have optimization switches (like -O2 or -Os) which let you say how to optimize what you're building. 2 may indicate higher optimizations than 1 or 0. "s" could mean optimize for size.

When you're translating something like this into a dialect, it's tempting to think of this as being either a WORD! or an INTEGER!, and not having to put it in ditto marks (Note: I'm going to call " ditto marks from now on, to help distinguish them from the phenomenon of "quoting").

some-file.c [
    optimize: 2
]
another-file.c [
    optimize: s
]

If your dialect happens to not be evaluating the slots, this gives you a clean representation. In the particular case of Rebmake, this is often taken on the command line, and the command line processing will LOAD the thing you pass. So:

 r3 make.r optimize: s

That works. And if you said optimize: 's that would cause problems, because the shell thinks that's a quote mark that needs to be paired.

But if you're not lucky enough to be in an evaluative context, you'd need a quote mark.

But What If Optimization Gets Settings Like -O2s ?

It might seem neat to translate the string into an INTEGER! or WORD!. You could compare integers against each other (e.g. to find out that 1 is greater than or less than the optimization level)... if they were both integers. It feels nice to turn things into words.

But if you do a mapping--and don't fully control the domain you're mapping from--this can throw you a curveball. And when it does, you'll have to put it in a string. Now you've got INTEGER! [0 1 2], WORD! [s z], or TEXT! ["2s" and other illegal things]

At which point you'd probably ask: "Since I don't really control this, should I have left it as a string?" :frowning:

Should you have stayed in your lane, and let it be ["0" "1" "2" "s" "z"] to start with?

For Now, WORD! and INTEGER! Works, But...

I hit a problem because there was inconsistency when some places used "s" and others uses s.

I'm canonizing to the WORD! just to keep making progress. But this kind of issue feels like it comes up often.

1 Like