Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Autoboxing ... "Yes We Can" ( or how I learned to love TIMTOWTDI ;)

by LanX (Saint)
on Dec 16, 2013 at 12:33 UTC ( [id://1067324]=note: print w/replies, xml ) Need Help??


in reply to Re: Autoboxing ... "Yes We Can" ( or how I learned to love TIMTOWTDI ;)
in thread Autoboxing ... "Yes We Can" ( or how I learned to love TIMTOWTDI ;)

My last answer was more about the general properties of method-syntax.

But there is also a very specific Perl issue, which became clearer after playing around.

Perl has a syntactical ambiguity between scalars and one element lists.

So writing something like $ref->functionality clearly operates on the referenced elements while  functionality $ref might operate on the "listed" reference itself.

Methodcall gives us an opportunity to add new flavors of grep which operate on references without the need to rename it grepref.

Think of a hashgrep which could be written  $href->grep sub { $_->key =~ /x/ }

(the need to write sub is due to another syntactic ambiguity: "block" vs "literal hash")

background

For instance it's not trivial/possible to augment the classical

 grep BLOCK  LIST

to also mean

 grep BLOCK AREF

Because it's not possible to rule out that  grep {...} $aref means "operate on the list with the one element $aref".

Languages where "everything is an object/reference" w/o lists don't have this abiguity.

They need workarounds for lists, for instance do some JS dialects introduce list-assignments by using array syntax:

 [a,b] = [b,a] ;// swap elements Mozilla JS 1.7

Cheers Rolf

( addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1067324]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 14:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found