develooper Front page | perl.perl6.users | Postings from September 2018

Re: .kv ?

Thread Previous | Thread Next
Curt Tilmes
September 15, 2018 02:53
Re: .kv ?
Message ID:
On Fri, Sep 14, 2018 at 10:42 PM ToddAndMargo <> wrote:

> When I said "yet", I presumed the a variable can be
> redefined at will:
> $ p6 'my $x; say $x.perl;
>           $x="abc"; say $x.perl;
>           $x=Nil; say $x.perl;'
> Any
> "abc"
> Any
> And that the receiving method only cares what you feed it
> at the time it is called.

Your example doesn't limit the type.  If you limit the type, you'll get an
by assigning it something the type doesn't allow.

my Int $x;
$x = "abc"; # error can't put a string in an Int

my Int:U $x;
$x = 42; # error can't put a definite value in an Int:U

my Int:D $x = 42;
$x = Nil;   # error, can't undefine.

You're only allowed to put in things that fit.  If an argument to a routine
is limited, you can only pass in things that fit.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About