Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: "Indirect" object syntax?

by Athanasius (Archbishop)
on Nov 23, 2015 at 04:41 UTC ( [id://1148368]=note: print w/replies, xml ) Need Help??


in reply to "Indirect" object syntax?

Hello muba,

Here’s the official explanation, from perlglossary:

  • indirect object

    In English grammar, a short noun phrase between a verb and its direct object indicating the beneficiary or recipient of the action. In Perl, print STDOUT "$foo\n"; can be understood as “verb indirect-object object”, where STDOUT is the recipient of the print action, and "$foo" is the object being printed. Similarly, when invoking a method, you might place the invocant in the dative slot between the method and its arguments:
    $gollum = new Pathetic::Creature "Sméagol"; give $gollum "Fisssssh!"; give $gollum "Precious!";
  • indirect object slot

    The syntactic position falling between a method call and its arguments when using the indirect object invocation syntax. (The slot is distinguished by the absence of a comma between it and the next argument.) STDERR is in the indirect object slot here:
    print STDERR "Awake! Awake! Fear, Fire, Foes! Awake!\n";

So in the case of $cgi = new CGI;, this is actually short for something like:

@args = (); $cgi = new CGI @args;

Does an expression such as $cgi = new CGI; violate the English rule that an indirect object is not present unless a direct object is also present? Yes, unless the (null) method arguments can be said to be “understood” in this case. (Cf. the sentence “Listen to me!” in which the subject “you” is also said to be “understood.”)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: "Indirect" object syntax?
by jdporter (Paladin) on Nov 23, 2015 at 15:14 UTC
    In Perl, print STDOUT "$foo\n"; can be understood as "verb indirect-object object", where STDOUT is the recipient of the print action, and "$foo" is the object being printed.

    Except that that's wrong. "$foo" is not an object -- direct or otherwise.

    Properly,

    method $object @args;
    is "indirect object syntax", in Perl lingo, and
    $object->method( @args );
    is "direct object syntax". Same object; only the syntax is different. And English grammar terminology doesn't really apply well.

    And the fact that @larry decided in their infinite (ly mistaken) "wisdom" to coin a completely unnecessary and superfluous alternative term for object, namely "invocant", manifests their misunderstanding of what an object is, in object-oriented programming. For "invocant" means, quite simply, "caller". But in print $fh or $fh->print, $fh is not the caller, it is the receiver. It is the object, not the subject, of the action.

    I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
Re^2: "Indirect" object syntax?
by muba (Priest) on Nov 23, 2015 at 04:50 UTC
    Hope that helps,

    That explains it perfectly. Thank you!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-19 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found