develooper Front page | perl.perl6.language | Postings from April 2003

Re: HELP! Type Coercions [was Re: Do we really need the dual type system?]

Thread Previous | Thread Next
From:
Damian Conway
Date:
April 18, 2003 14:24
Subject:
Re: HELP! Type Coercions [was Re: Do we really need the dual type system?]
Message ID:
3EA06D08.4030207@conway.org
Paul wrote:
> --- Austin Hastings <austin_hastings@yahoo.com> wrote:
> 
>>--- Paul <ydbxmhc@yahoo.com> wrote:
>>
>>> $x = @y; # $x now a handle on @y
>>> $x[0]++; # increments @y[0]
>>
>>I think it's C<:=> to do an explicit reference binding.
>>
>>  $x := @y; # Note ':'
>>
>>I'm not clear on what C<$x = @y;> will do,

It will assign \@y to $x.


> I thought I saw somewhere that an array would automatically yield a
> reference in that context, for some definition of "that", but you're
> right, it seems more likely that it'd just give the length.

Nope. A reference. Length is only yielded in numeric context.
Which this isn't.


>>>I suspect that you could say
>>>
>>>  my Int $i = 1;
>>>  print $i;      # all types *do* stringify, don't they?

No. Junctive types don't.



>   my Int $i = 3;
>   my Str $s = $i; # should be a no-no

Okay, I suspect. Automatic conversion.

> 
> I'd expect
> 
>   $i ~~ "123"
> 
> to fail, depending on smart-matching semantics,

It fails because $i contains 3. The smart-match:

	$i ~~ "3"

would match.


  but
> 
>   $s = "$i"; # quotes implicitly stringify
> 
> to succeed....

No. Again, "3" doesn't match "123".

Damian


PS: I'd really like to respond to more of these type threads, but writing E6 
is taking precedence just now. That doesn't mean that I don't find people's 
assumptions and confusions valuable. And I'm sure Larry does too. :-)


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