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

Re: .kv ?

Thread Previous | Thread Next
From:
ToddAndMargo
Date:
September 15, 2018 03:33
Subject:
Re: .kv ?
Message ID:
86586432-fd6d-23c9-1816-95ee622026ef@zoho.com
On 09/14/2018 07:52 PM, Curt Tilmes wrote:
> 
> 
> On Fri, Sep 14, 2018 at 10:42 PM ToddAndMargo <ToddAndMargo@zoho.com 
> <mailto: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
> 

Got it!  Thank you!

$ p6 'my Int:D $x = 42; $x = Nil;'
Type check failed in assignment to $x; expected type Int:D cannot be 
itself (perhaps Nil was assigned to a :D which had no default?)
   in block <unit> at -e line 1

$ p6 'my Int:U $x = 42;'
Type check failed in assignment to $x; expected Int:U but got Int (42)
   in block <unit> at -e line 1

-T



-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When we ask for advice, we are usually looking for an accomplice.
    --  Charles Varlet de La Grange
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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