Non-binary values

Non-binary values pose a problem because Inform won’t allow complex If statements. For instance, you can’t say ‘If the weather is raining, snowing, or hailing, say “I’m not going outside in that!”’

What’s the best way to get around this limitation, assuming that a series of if statements would be too clumsy?

A decide phrase or a definition, probably:

[code]To decide whether there is precipitation:
if it is raining, decide yes;
if it is snowing, decide yes;
if it is hailing, decide yes;
decide no.

Carry out speeding:
if there is precipitation, now the car is wrecked.
[/code]

–Erik

Doesn’t “If the weather is raining or the weather is snowing or the weather is hailing” work? The problem isn’t that you can’t have more than two or-clauses, it’s that you have to write out the subject every time – you can’t use “or” to join the values.

It’s not completely unheard of in my experience but it is extremely rare in any programming language to be able to use ‘or’ in that way. One of the cases I guess where Inform follows suit instead of breaking with tradition.

However, it seems like it should be uniquely (or at least unusually) possible for Inform to implement this kind of grammar. Most languages have to avoid it, because they can’t resolve the ambiguity – do you mean the ‘or value’ to add to the list of previous values, or do you mean to test the ‘truth state’ (i.e. interpret it as a binary value) on its own? The latter provides an incredibly useful loophole to help write simultaneously complex and compact if conditions. Wouldn’t want to close that.

But Inform doesn’t have this loophole to begin with because you can’t test variables as truth states (I don’t think). You have to rephrase it as a ‘whether or not’ to get an actual truth state out of a conditional statement, and I think the same goes for variables. I don’t remember i7 ever accepting something like ‘if carrying capacity, say “It can hold things.”’

So there is no danger of ambiguity and it seems like going for the more fully featured use of ‘or’ that is unavailable to most languages, would be a win.

Paul.

Although one of the rare exceptions is Inform 6.

Yes indeed, that will definitely work. And thanks for mentioning it–I took the OP’s statement that “a series of if statements would be too clumsy” to be explicitly rejecting this approach, but I’ll bet that in fact it’s exactly what he was looking for.

–Erik

That’s actually probably the one place that I had seen it that kept me from typing ‘yes it’s unheard of’. I knew I had seen that somewhere…

P.

Eric’s extension Alternatives allows if-statements like that. To quote:

But it would be nice to also have an adjectival value, like so (except, you know, in a way that actually works):

Weather is a kind of value. A room has a weather. A room can be adverse. A room is adverse if the weather is raining, snowing, or hailing. Instead of going in an adverse room, say "I'm not going outside in that!"

Complicated because it would be better if the “adverse” value itself had three states instead of two (three being the largest set that can be divided up in any way by including or excluding a single element):

A room can be pleasant, neutral, or adverse. A room is pleasant if the weather is sunny. A room is adverse if the weather is raining, snowing, or hailing.

You can set that up (for a particular case) with a “Definition” adjective.

I’m quite fond of Python’s convention for using the “in” operator for iterables in this way, such as:

if weather in (snowing, raining, hailing):

The “alternatives” extension sounds like it handles things in a similar way.

This construction is extremely useful. I do it all the time in lambdamoo. It’s part of the awesome power of lists when they are treated as a central variable type.

Most of the time Python = :slight_smile:

TADS 3 can do the same thing, slightly more verbosely:

if weather is in (snowing, raining, hailing)

Unlike Python, though, it’s a special case syntax - you can’t say “if weather is in precipitationList”, for instance. (For that, you’d have to call one of precipitationList’s methods.)

For that matter, I think Inform can do that, slightly more verbosely. if the weather is listed in { snowing, raining, hailing }