# Returning number representing a named value

Supposing I have a kind of value, say apple, orange and pear. I assume these are represented internally as 1, 2 and 3 respectively. Is there a phrase to return this numeric representation, e.g. “the number representation of (K - a kind of value)”?

Many thanks.

Matt

What is it that you’re trying to accomplish?

I need to extract data directly from a particular row in a large table, referenced by a named number (“a kind of value”). (For speed issues, as the tables I’m dealing with are very large, I don’t want to search the table for the named number to obtain the corresponding row, I simply want to access the row directly via the syntax “choose row N…”.)

Currently, I have simply assigned constant values:

LABEL_NAME_X is always 1.
LABEL_NAME_Y is always 2.

Etc

But this is tedious for hundreds for reference labels.

So I thought about defining all these labels as a kind of value (defined via a table). But I now need a way to convert the label to a number to use as the row lookup for another (large) table.

Hope that makes sense.

If I understand you correctly, this should work.

The idea is that the fruit names are your named numbers, and the exclamation strings are the data that you want to extract.

``````[This technique relies on the assumption that this sort of enum always starts with 1, which appears to be the case.]

A fruit is a kind of value.
Some fruits are defined by the Table of Fruits.

Table of Fruits
Fruit		Exclamation (text)
apple		"Apples ahoy!"
pear		"Ignore pears at your own peril!"
banana		"I'm going bananas!"
peach		"Peaches are peachy!"
plum		"I'm plum out of ideas!"

To decide which number is the row index of (F - a fruit):
(- {F} -).

Fruit Chamber is a room.
Alice is a woman in the Fruit Chamber.

Instead of asking Alice about "[fruit]":
let i be the row index of the fruit understood;
choose row i from the Table of Fruits;
say "'[exclamation entry]' Alice exclaims."

Test me with "ask alice about banana / ask alice about apple / ask alice about pear / ask alice about plum / ask alice about peach".``````

Edit: It’s actually easier than that.

``````A fruit is a kind of value.
Some fruits are defined by the Table of Fruits.

Table of Fruits
Fruit		Exclamation (text)
apple		"Apples ahoy!"
pear		"Ignore pears at your own peril!"
banana		"I'm going bananas!"
peach		"Peaches are peachy!"
plum		"I'm plum out of ideas!"

Fruit Chamber is a room.
Alice is a woman in the Fruit Chamber.

Instead of asking Alice about "[fruit]":
say "'[exclamation of the fruit understood]' Alice exclaims."

Test me with "ask alice about banana / ask alice about apple / ask alice about pear / ask alice about plum / ask alice about peach".``````

I’m not sure I understand what you’re asking for, MattD, but if Vince’s solution isn’t what you’re looking for, you can avoid the tedium of typing in a bunch of value assignments by having the game do it at startup. This takes a little bit of time on startup–though I expect not much, unless the tables are truly massive–but it should be a lot better than searching through the tables every time.

Toy example:

[code]Color is a kind of value. The colors are defined by the Table of Colors. A color has a number called row index.

Table of colors
color
red
orange
yellow
green
blue
violet

Table of Something Else
Text
“A”
“B”
“C”
“D”
“E”
“F”

When play begins:
let index be 1;
repeat with temp color running through colors:
now the row index of temp color is index;
increase index by 1.

Every turn:
let hue be a random color;
let lookup be the row index of hue;
choose row lookup in the Table of something else;
say “[Hue] corresponds to [text entry].”

Lab is a room.[/code]

Thank you both. I actually had thought of Matt w’s method, but didn’t like the runtime overhead, so I’ve opted for Vince’s solution (the I6 phrase did the trick nicely).

Many thanks.