Yuval Kogman skribis 2005-10-07 12:53 (+0200):
> On Fri, Oct 07, 2005 at 12:42:01 +0200, Juerd wrote:
> > For my Int $c = $float, though, I'd want coercion.
> > And I think it is wrong to have such a huge difference between literals
> > and values: if a variable coerces, a literal has to do so too.
> How do you tell the compiler "this must never be a float, ever"?

By cramming it into a variable that cannot hold a float.

I think there should be some syntax to disable coercion, but that
coercion must be the default behavior.

A simple operator that can be placed flexibily would certainly help.
I'll demonstrate with (!), although that's probably not the right glyph:

    sub foo (Int $foo);     # coerce, possibly lossily
    sub foo (Int(!) $foo);  # coerce, but only if possible without loss

    my Int(!) $foo = $bar; 

    my Int $foo = (!)$bar;

    sub bar (Int $foo); bar((!)$float);

Unintentionally, the (!) is always left of the sigil. I like that, even
though whitespace-wise I see it as two different things.

Maybe the default should be configurable, allowing lossy coercion being
the default default, and (?) can be used to override a current default
of disallowing lossy coercion.


Juerd
-- 
http://convolution.nl/maak_juerd_blij.html
http://convolution.nl/make_juerd_happy.html 
http://convolution.nl/gajigu_juerd_n.html

Reply via email to