Brandon S Allbery KF8NH wrote:
I think there's a confusion about what given/when is doing.  Naïvely(?), I
expect it to be shorthand where the value for "when" is matched against the
one for "given", thus your example would be (pseudocode) "if 0 == True" and
expecting "OH NOEZ" *would* be unreasonable.

Is given/when trying to do too many things at once?

I would prefer if given/when was nothing more than an alternate syntax for if/then that does comparisons. That is, these would be equivalent:

  given $foo {
    when $bar {...}
    when $baz {...}
    default {...}
  }

  if $foo eqv $bar {...}
  else if $foo eqv $baz {...}
  else {...}

On the other hand, Perl 6 has multiple equality comparison operators, eqv, eq, ==, ===, etc, and hence ~~ semantics instead of eqv may seem to make some sense, though I think that would cause more problems.

So I think if given-when just used eqv semantics and then users explicitly coerced their arguments instead, that might be best. For example, in the general case, say they want numeric semantics and the arguments aren't necessarily already numbers:

  given +$foo {
    when +$bar {...}
    when +$baz {...}
    default {...}
  }

All this being said, I really do *not* like the idea of saying Bool is just a subset of Int as it seems to be. Bool should be disjoint from every other common type like Int/Str/etc instead.

Asking "False eqv 0" should be false, though either "False eqv ?0" or "+False eqv 0" being true is okay.

If people want ~~ semantics, let them ask for it explicitly, such as with:

  given $foo {
    when ~~ $bar {...}
    when ~~ $baz {...}
    default {...}
  }

-- Darren Duncan

Reply via email to