Indefinite Articles

If you have a variable with text in it, how do you get it to have a proper a or an in front of it?

say “This is some text. It has a [awesome] in it”;

If [awesome] is apple, then it looks bad.

As easy as this:

say "This is some text. It has [an awesome] in it";

Just put the indefinite article inside the brackets, and it will adapt itself to the following word. (It doesn’t matter if you write “[an awesome]” or “[a awesome]”). See Ch. 5.3 in the built-in manual.

That only seems to work for nouns.

Oh, I misunderstood your question totally. Sorry!

The only way I know how to do this is to use indexed text, as in 19.6: Regular expression matching. (Which I think will require you to mess around with a code block, pulling character 1 of awesome and then matching it against the regular expression “”. But possibly somebody knows a neater way to do it.)

Like maga says.
And then put it all in a neat say phrase like this:

To say a/an (T - text):
	let Txt be indexed text;
	let Txt be T;
	if Txt matches the regular expression "^<aeiouAEIOU>", say "an ";
	otherwise say "a ";
	say T.

And you can go on writing

say "It has [an awesome] in it."

just as if the awesome had been an object variable rather than text.

Many thanks!

[code]To say (T - a text) with article:
let x be indexed text;
let x be T in lower case;
if character number 1 in x is a vowel, say "an ";
otherwise say "a ";
say T.

To decide whether (letter - indexed text) is a vowel:
let vowels be a list of indexed text;
let vowels be { “a”,“e”,“i”,“o”,“u”};
if the letter is listed in the vowels, yes;

No regular expressions needed.

Note that this will guess wrong on things like “uniform” and “honest,” so if you’ve got something like that in there you have to manually program in an exception.

For performance this will minimise the number of indexed text allocations:

To say a (T - a text): let x be an indexed text; now x is T; let c be character number 1 in x; if c is "a" or c is "A" or c is "e" or c is "E" or c is "i" or c is "I" or c is "o" or c is "O" or c is "u" or c is "U": say "an "; otherwise: say "a "; say T;

It’s not worth it for this example, but hand customised I6 could be even faster.

If you deal with a lot of texts with unusual articles then maybe using objects would be simpler.