Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re (tilly) 1: References quick reference

by tilly (Archbishop)
on Apr 05, 2001 at 08:46 UTC ( #70008=note: print w/ replies, xml ) Need Help??


in reply to References quick reference

Well done, but you have omitted the fact that dereferencing an anonymous function means calling it:

&$aSub(@args); $aSub->(@args); # This notation due to merlyn
and at this point if people wonder why a method call looks like a dereferencing operation, they should give themselves brownie points because it is. When you call bless on a reference, it is not the reference that is blessed, it is the thing that the reference points at. And a method call is really a matter of dereferencing the reference in a way that is looking for a method. Consider:
package foo; sub bar { print "foobar strikes again!\n"; } package main; # Create and throw away an object bless \$x, "foo"; # But the blessing is not forgotten! (\$x)->bar();
This detail was pointed out to me by merlyn in chatter about a week ago. At first it surprised me, but then I thought about it and it made a lot of sense. After all if I have 10 references to the same thing, shouldn't dereferencing any of them be equivalent? Doesn't a method call look like just dereferencing...?

And so to your list you can add calling an anonymous subroutine and making a method call as dereferencing operations.


Comment on Re (tilly) 1: References quick reference
Select or Download Code
(tye)Re: References quick reference
by tye (Cardinal) on Apr 05, 2001 at 09:49 UTC

    you have omitted the fact that dereferencing an anonymous function

    Quite intentionally. I didn't want to distract from the topic: dereferencing "data structure references". I wanted people to be able to let that sink in and then never worry about it again. Perhaps a title change is in order, though I don't want a title that will scare people off either. (:

    Had I chosen to cover code references, then I would have been more detailed than what you've discussed above. I started to and then realized I didn't have handy the details required to cover that topic in a manner deserving of the label "tutorial" (and also realized that it didn't fit in anyway).

    I also didn't talk about creating references, symbolic references, blessed references, closures, ref, UNIVERSAL::isa(), references to globs, to the IO chunks of globs, to compiled regular expressions, nor to any other types of things that Perl lets you have a reference to.

    All of those break some of the above rules and discussing them would distract the reader from once and for all getting those rules down. I also lump data structure references together in my head while thinking of code references separately from glob references separately from...

    So, no, I'm not going to add your two things to my list. q-:

            - tye (but my friends call me "Tye")
Re: Re (tilly) 1: References quick reference
by demerphq (Chancellor) on Jun 28, 2003 at 09:25 UTC

    dereferencing an anonymous function

    Just to clarify, its not a question of anonymous functions (unless your definition of anonymous is the same as "reference to a"). Any valid reference to a function can be called as you say.


    ---
    demerphq

    <Elian> And I do take a kind of perverse pleasure in having an OO assembly language...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2014-12-26 09:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls