Phrase kind number/real number weirdness – is this a bug?

I was fiddling around with things (just probing what works and what doesn’t) and discovered that real numbers seem to be treated as a kind of number for the purpose of covariance / contravariance of composite types. However, it doesn’t appear to actually work as one would expect. Is this a bug? More specifically, which is the bug – the fact that they’re treated as convertible, or the fact that they don’t actually convert when used as such?

Code:

To decide what number is the best integer (this is integer decision): decide on 5.
To decide what real number is the best real number (this is real decision): decide on 5.2.

fun stuff is a phrase nothing -> real number that varies. fun stuff is integer decision.

When play begins, say "fun stuff: [fun stuff applied][line break]".

I would have expected one of two outcomes from this:

  1. It fails to compile, because a number and real number are not compatible.
  2. It outputs the text “fun stuff: 5” or maybe “fun stuff: 5.0”.

But instead, it outputs the text “fun stuff: 7.0065 × 10^-45”.

I’m not sure if other composite types such as lists or relations can be coaxed into a similar outcome. It also doesn’t seem to work for phrase parameter types – I can’t assign a phrase taking a real number to a variable whose type is a phrase taking a number.

1 Like

It is a bug. I note that the other way around doesn’t work. (You can’t assign real decision to a (nothing->number) variable.)

More specifically, which is the bug – the fact that they’re treated as convertible, or the fact that they don’t actually convert when used as such?

Inform has a policy that integers can be implicitly converted to reals. That implies that your example should be legal, but I don’t know whether Graham would agree, so I don’t know the answer to your question.

1 Like

Yes indeed, it only works one way around, and only for the return value.

Known issue: I7-2170

1 Like

I looked at that but it seems to be a different problem. That’s a “doesn’t compile when it should” bug.

oops, thanks. Reported as I7-2479.

1 Like