Simple syntax for a list with "or"?

Most of the time, ‘[the list of dishes]’ works great.

But I ran into a case where I definitely need ‘or’ instead of ‘and.’

The “dish-list” code below works, but is there a one-liner available to simplify things?

"Stuff" by Andrew Schultz

a dish is a kind of thing.

r1 is a room

the chicken is a dish in r1.
the veal is a dish in r1.
the fish is a dish in r1.

every turn:
	say "Which dish will you pick, [dish-list]?";

to say dish-list:
	let Z be the number of dishes;
	let count be 0;
	repeat with X running through dishes:
		increment count;
		say "[the x]";
		if count < z, say ", ";
		if count is z - 1, say "or ";

(Note: I had trouble following the I6 code down to WriteListR, but that could be an alternate solution, to add a flag for OR or AND. But that’d be a bit beyond me.)

1 Like

Narrator’s voice: Two years earlier… :grin:

Lab is a room.

To say or-list (l - list of values):
  now or-not-and is true;
  say l;
  now or-not-and is false.

or-not-and is initially false.

L is initially {1 , 2, 3};

For issuing the response text of the list writer internal rule response (C) when or-not-and is true: say " or ".

when play begins:
  say "[or-list L]".

Edited: Actually, this is less ugly:

list-conjunction is initially "and".

To say (l - list of values) with conjunction (t - text):
  let backup be list-conjunction;
  now list-conjunction is t;
  say l;
  now list-conjunction is backup.

To say or-list (l - list of values):
  say l with conjunction "or";

For issuing the response text of the list writer internal rule response (C): say " [list-conjunction] ".
4 Likes

Oops! Well, thanks for the quick reply. I’m bookmarking it/writing it in my big notes file this time!

I usually keep a repository of “weird stuff I will likely use again” but somehow this slipped through. Fingers crossed it won’t happen a third time.

1 Like

Shouldn’t that first block read:

To say (l - list of values) with conjunction (t - text):
  let backup be list-conjunction;
  now list-conjunction is t;
  say l;
  now list-conjunction is backup.
3 Likes

Yup! I’ve edited the post now.

2 Likes