Re: $arrayref.ref?

2005-07-31 Thread Ingo Blechschmidt
Hi,

Larry Wall wrote:
> On Sat, Jul 30, 2005 at 02:14:52PM +0200, Ingo Blechschmidt wrote:
> : http://use.perl.org/~autrijus/journal/25337:
> : > deref is now 0-level; $x = 3; $y = \$x; $y++. # now an exception
> : 
> : my $arrayref = [1,2,3];
[...]
> : say $arrayref.isa("Ref"); # true or false?
> 
> False, though tied($arrayref).isa("Ref") is probably true.

hm? I've probably misunderstood something, but I don't see any tied
variables in the snippet above -- so why should we use tied() to get at
the non-autodereffing ref of an autodereffing ref?

I thought tieing is a way to intercept further assignments -- i.e.
$some_tied_variable = ...;
will call user-defined code.

But this is not the case when dealing with simple references, right?

my $arrayref = [1,2,3];
# $arrayref contains an autodereffing Ref of Array now.
$arrayref = 42;
# $arrayref contains a simple Num now.
# The [1,2,3], which was previously stored in $arrayref,
# does not "notice" the new assignment.

Thus I propose we use tied() only to get at the underlying real contents
of a tied variable, and use
get_non_autodereffing_ref_out_of_autodereffing_ref() (with a shorter
name, of course), to convert an autodereffing ref to a
non-autodereffing ref.

my $arrayref = [1,2,3];
$arrayref.isa(Ref);  # false
tied($arrayref); # error/undef
get_non_autodereffing_ref_out_of_autodereffing_ref($arrayref).isa(Ref);
 # true

Opinions?


--Ingo

-- 
Linux, the choice of a GNU | To understand recursion, you must first
generation on a dual AMD   | understand recursion.  
Athlon!|



Re: $arrayref.ref?

2005-07-30 Thread Aankhen
On 7/30/05, Larry Wall <[EMAIL PROTECTED]> wrote:
> On Sat, Jul 30, 2005 at 02:14:52PM +0200, Ingo Blechschmidt wrote:
> : say $arrayref.isa("Ref"); # true or false?
> 
> False, though tied($arrayref).isa("Ref") is probably true.

In that case, how do you check if something is a ref?  `if (tied($foo))`?

Aankhen


Re: $arrayref.ref?

2005-07-30 Thread Larry Wall
On Sat, Jul 30, 2005 at 02:14:52PM +0200, Ingo Blechschmidt wrote:
: Hi,
: 
: http://use.perl.org/~autrijus/journal/25337:
: > deref is now 0-level; $x = 3; $y = \$x; $y++. # now an exception
: 
: my $arrayref = [1,2,3];
: 
: say $arrayref.ref;# Ref or Array?

Array.

: say $arrayref.isa("Ref"); # true or false?

False, though tied($arrayref).isa("Ref") is probably true.

: say $arrayref.isa("Array");   # false or true?

True.

: say +$arrayref;   # 3 or error?
: say $arrayref + 1;# 4 or error?

Both work.

To the first approximation, refs to scalar "non-object" values must be
explicitly derefed.  But refs to non-scalar containers are considered
objects so they will happily autoderef one level.  It's possible we
may find a way to relax the former constraint, but if so, it would
go back to one-level deref, not all levels.

Larry


$arrayref.ref?

2005-07-30 Thread Ingo Blechschmidt
Hi,

http://use.perl.org/~autrijus/journal/25337:
> deref is now 0-level; $x = 3; $y = \$x; $y++. # now an exception

my $arrayref = [1,2,3];

say $arrayref.ref;# Ref or Array?
say $arrayref.isa("Ref"); # true or false?
say $arrayref.isa("Array");   # false or true?

say +$arrayref;   # 3 or error?
say $arrayref + 1;# 4 or error?


--Ingo

-- 
Linux, the choice of a GNU | Black holes result when God divides the
generation on a dual AMD   | universe by zero.  
Athlon!|