develooper Front page | perl.perl5.porters | Postings from August 2010

Re: mauve::reftype()

Thread Previous | Thread Next
From:
demerphq
Date:
August 30, 2010 08:01
Subject:
Re: mauve::reftype()
Message ID:
AANLkTinqToJbW3KUMYjVuHrgFoh+ctPV5qQMfLZEJd+g@mail.gmail.com
On 30 August 2010 16:46, Zsbán Ambrus <ambrus@math.bme.hu> wrote:
> On Mon, Aug 30, 2010 at 2:16 PM, Ben Morrow <ben@morrow.me.uk> wrote:
>> Quoth ambrus@math.bme.hu:
>>>
>>> LVALUE (C<< (&{sub { *x = \$_[0] }}(substr("",0)), \$x) >>)
>>
>> It doesn't need to be that complicated. \substr("", 0) will do just
>> fine. I don't think it's worth trying to include a '\$x' where it adds
>> that much complication.
>
> True, that should be simplified, my error.
>
>>> GLOB (C<< \($x = *y) >>)
>>
>> I presume you included $x in the example because you think this is
>> 'really' a SCALAR ref? I disagree. Globrefs are different from scalar
>> refs in important ways; apart from anything else, they've got their own
>> deref operator.
>
> The point here is this.  Any of SCALAR, REF, GLOB, VSTRING, LVALUE can
> be returned by reftype(\$y), depending on the current contents of $y,
> but the other types like ARRAY can't.  Phrasing in another way, if you
> have a reference $x and reftype($x) once returns SCALAR or GLOB, it
> could later return the other one even if you don't assign to $x
> meanwhile (eg. you don't execute $x = []) just because the value of
> some other scalar changes.  As for a GLOB, I assume you understand
> that's returned when $x is a reference to a scalar that's set to a
> glob, not when $x is itself a glob, eg. for $x = \*y, but not for $x =
> *y.  As I said earlier,

Yes, but it still needs to be dereferenced with a * as I recall.
(havent verified).

>
> On Mon, Aug 30, 2010 at 11:07 AM, Zsbán Ambrus <ambrus@math.bme.hu> wrote:
>> could we finally have a reftype that does away with the
>> REF/GLOB/LVALUE/whatever madness and just returns SCALAR for any
>> scalar, independent of what value it has?  The precise invariant I'd
>> like is that refaddr($x) remains constant when you assign to $x but
>> not to $x.
>
>>> REGEX (C<< qr// >>)
>>
>> A REGEX, OTOH, could reasonably be considered a SCALAR ref. It's derefed
>> with $, the result fits in a scalar variable, &c.
>
> Hmm, true.  In this case, maybe the entry should say
>
> REGEX (C<< \($x = ${qr//}) >>)
>
> Though I don't really understand how that works.  What do you even get
> if you dereference a regexp with ${...}, and how can you use that
> value?

You should get a string. Its basically a special form of SCALAR.

And I agree with you, well mostly. I think that GLOB is distinct from
SCALAR, and I think that REF is logically distinct from SCALAR, in
that a SCALAR dereftype would imply that once dereferenced the item
will not be a reference anymore, whereas REF says that once
dereferenced you will still need to dereference further to get at the
base "item".

So to me: the "dereftype" values would be:

SCALAR, VSTRING, LVALUE. REGEX => SCALAR
REF => REF
GLOB => GLOB
ARRAY => ARRAY
HASH => HASH

others: afaik no dereferencing syntax is provided, so probably have
them return "" in a hypothetical "dereftype".

Yves


-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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