# Table columns and table names as phrase parameters

For a project I need tons of phrases like these ones:

``````if there is a foo corresponding to a foobar of the foobar-variable in the Table of Foo-Fighters:
say the foo corresponding to the foobar of foobar-variable in the Table of Foo-Fighters;
otherwise:
say the foo corresponding to the foobar of deafult-foobar in the Table of Foo-Fighters.

if there is a bar corresponding to a foobar of the foobar-variable in the Table of Baristas:
say the bar corresponding to the foobar of the foobar-variable in the Table of Baristas;
otherwise:
say the bar corresponding to the foobar of deafult-foobar in the Table of Baristas.``````

where only the first table column and the table name varies

I had hoped to define a simpler equivalent phrase for this:

``````To look up (TC - table column) in (T- table):
if there is a TC corresponding to a foobar of the foobar-variable in T:
say the TC corresponding to the foobar of foobar-variable in T;
otherwise:
say the TC corresponding to the foobar of deafult-foobar in T.``````

But I can’t make it work. Is that because it can’t be done or because I do it wrong?
The following, for instance, won’t compile.

``````To look up (TC - table column) in (T - table name):
if there is a TC corresponding to a foobar of the foobar-variable in T:
say the TC corresponding to the foobar of foobar-variable in T;
otherwise:
say the TC corresponding to the foobar of deafult-foobar in T.

A foobar is a kind of value. The foobars are defined by the Table of Foobars.

Table of Foobars
foobar
default-foobar
xyzzy
frotz
filfre

Foobar-variable is a foobar that varies. Foobar-variable is xyzzy.

foobar	Alpha	Beta	Gamma
default-foobar	"ett"	"två"	"tre"
frotz	--	"fem"	"sex"
xyzzy	"sju"	--	"nio"
filfre	"tio"	"elva"	--``````
1 Like

I think it’s fairly clear what I’m trying to do here:

``````The Place is a room.

To look up (TC - table column) in (T - table name):
if there is a TC corresponding to a foobar of the foobar-variable in T:
say the TC corresponding to the foobar of foobar-variable in T;
otherwise:
say the TC corresponding to the foobar of deafult-foobar in T.

A foobar is a kind of value. The foobars are defined by the Table of Foobars.

Table of Foobars
foobar
default-foobar
xyzzy
frotz
filfre

Foobar-variable is a foobar that varies. Foobar-variable is xyzzy.

foobar	Alpha	Beta	Gamma
default-foobar	"ett"	"två"	"tre"
frotz	"four"	"five"	"six"
xyzzy	"sept"	"huit"	"neuf"
filfre	"zehn"	"elf"	"zwölf"

look up Alpha in the Table of Answers.``````

– only it doesn’t work.

Does anybody know a way to make it work?

This works, via some I6 hackery:

``````To decide what text is the (TC - text valued table column) column entry:
(- {-require-ctvs}TableLookUpEntry(ct_0, {TC}, ct_1) -).

To look up (TC - table column) in (T - table name):
if there is a foobar of foobar-variable in T:
choose row with foobar of foobar-variable in T;
else:
choose row with foobar of default-foobar in T;
say TC column entry;``````
1 Like

Magnificent! Many thanks zarf!