Parsing ordinals

I’m wondering if there’s a simple trick for getting the parser to understand ordinal numbers. I’ve been working with this:

``Ordinal is a kind of value. Some ordinals are unordered, first, second, third, and fourth.``

But obviously this is a finite sequence. I tried specifying an ordinal as a unit:

``Ordinal is a kind of value. 999th specifies an ordinal``

But the compiler said “it looks as if you intend to give a new meaning to expressions like ‘999th’, but this is already something I recognise - specifying a number - so a more distinctive specification must be chosen.”

That made me think I could do this:

[code]Counting to is an action applying to one number. Understand “count to [number]” as counting to.

Carry out counting to:
let i be 1;
while i < the number understood:
say "[i], ";
increment i;
say “[the number understood].”;

Test me with “count to 3rd/count to third”[/code]

But I got “I didn’t understand that number.”

I’m guessing the compiler’s parser can understand ordinals, but the game parser can’t. Is that true? Is there a way around the situation?

I think that’s true. I would’ve done your Ordinal is a kind of value. Some ordinals are unordered, first, second, third, and fourth with a After reading a command when the player’s command includes “[ordinal]”, replace the matched text with the ordinal understood as a number or similar construction. I think by typecasting the ordinal to a number with To decide which number is (x - an ordinal) as a number: (- {x} -) you can get it to work. Might lose the “unordered” value, though.

EDIT TO ADD: er, the ordinal understood probably isn’t set in the ARaC rules, so my solution isn’t quite that straightforward, but I think the general idea is sound.

ARaC rules?

I did exactly this exploring the same question a couple of days ago, using “the matched text” rather than “ordinal understood” in the ARaC activity, so that will work fine.

Typecast with {x} - 1 to get 0 for unordered, 1 for first, etc.:

``To decide which number is (x - an ordinal) as a number: (- {x} - 1 -)``

–Erik

Erik, you replaced the matched text with the matched text? Huh?

Oh, and I would’ve removed the “unordered” value, or at least move it to the end of the list rather than the beginning, to save a subtraction at run-time. (Every little bit of optimization helps! )

Ron, I guess I left out the matching part. My main point was that it could be matched as text and cast back to a value. I think in fact that there’s only one way to match at this stage, with “if the player’s command includes ‘[ordinal]’”. Other phrases might work, but neither “matches the text” nor “matches the regular expression” will work with KOV tokens like “[ordinal]”. (And just plain “matches” works, as in "if the player’s command matches “[ordinal]”, but only if an ordinal is the whole of the command.)

The optimization gained by not subtracting is pretty well meaningless, I think, especially when not doing it either means losing some functionality (no “unordered”), or embracing the illogical (having unordered translate as 11, for example). But to each his own!

–Erik

The reason I put “unordered” first, originally, was so that I could add more ordinals to the end if necessary.

Yes, and that makes great sense for an extension, which I believe is what you’re planning. If you provide 10 ordinals and make the 11th unordered, thus reserving the typecast number 11 to mean <>, users will have extra hacking to do to actually add “eleventh” to the list. As it is, they need only replace your original list of ordinals with their own to expand the number of word ordinals understood.

A tip along these lines, since this kind of user-friendliness still hasn’t really burbled up into standard procedure for extensions: Put your definition of the ordinal KOV in its own section, so that users can easily replace it, e.g.:

[code]Section - Definition of the ordinal KOV

An ordinal is a kind of value. The ordinals are first, second, and third.

Section - [/code]

EDITED to add: Actually, it seems that it isn’t even necessary to hack an extension to add more values to a KOV. Your users will be able to augment the list simply by typing more of them into their own source code, e.g.:

[code]Include Ordinals by capmikee.

The ordinals are eleventh and twelfth.[/code]

–Erik