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

Re: .kv ?

Thread Previous | Thread Next
From:
Curt Tilmes
Date:
September 15, 2018 02:53
Subject:
Re: .kv ?
Message ID:
CAMv20O9KZkyr+25ox2t76VeVNrMbv7cVY7FyxGx32EsweUcgKA@mail.gmail.com
On Fri, Sep 14, 2018 at 10:42 PM ToddAndMargo <ToddAndMargo@zoho.com> 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
error
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.

Curt

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About