Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: multiple method calls against the same object, revisited

by TimToady (Parson)
on Dec 25, 2004 at 18:51 UTC ( #417421=note: print w/ replies, xml ) Need Help??


in reply to multiple method calls against the same object, revisited

In Perl 6 that's probably written like this:

given Gtk2::Window.new( "toplevel" ) { .signal_connect( :delete{ Gtk2.main_quit } ); .set_title( "Test" ); .border_width( 15 ); .add( given Gtk2::Button.new( "Quit" ) { .signal_connect( :clicked{ Gtk2.main_quit } ); $_; } ); .show_all; }
Though I could see extending the but operator to take a topicalized closure so we don't have to put the ugly $_ at the end:
Gtk2::Window.new( "toplevel" ) but { .signal_connect( :delete{ Gtk2.main_quit } ); .set_title( "Test" ); .border_width( 15 ); .add( Gtk2::Button.new( "Quit" ) but { .signal_connect( :clicked{ Gtk2.main_quit } ); } ); .show_all; }
Merry Christmas!!!


Comment on Re: multiple method calls against the same object, revisited
Select or Download Code
Re^2: multiple method calls against the same object, revisited
by gaal (Parson) on Dec 25, 2004 at 19:27 UTC
    Pascal! :)

    Maybe an "on a" modifier?

    .signal_connect( :clicked{ Gtk2.main_quit } ) on Gtk2::Button.new( "Quit" );

    Indirect object syntax would make that sounds even more like English. But this is probably stretching it too far anyway.

      But how would you do multiple calls against the same thing?

      { .signal_connect( :delete{ Gtk2.main_quit } ); .set_title( "Test" ); .border_width( 15 ); .add( .signal_connect( :clicked{ Gtk2.main_quit } ) on Gtk2::Butto +n.new( "Quit" ) ); .show_all; } on Gtk2::Window.new( "toplevel" );

      There is a simple analogon in Perl5:

      my $window = map { $_->signal_connect( delete_event => sub { Gtk2->main_quit } ); $_->set_title( "Test" ); $_->set_border_width( 15 ); $_->add( map { $_->signal_connect( clicked => sub { Gtk2->main_quit } ); $_; } Gtk2::Button->new( "Quit" ) ); $_->show_all(); $_; } Gtk2::Window->new( "toplevel" );

      Meh. It puts things in the wrong order IMO.

      Makeshifts last the longest.

Re^2: multiple method calls against the same object, revisited
by Aristotle (Chancellor) on Dec 25, 2004 at 23:26 UTC

    Yeah, I knew that Perl6 would make that much nicer in the form of your first example. :-) I have to say that the but example is a lot nicer, though. Lovely!

    Except it's going to be a while yet. :-( So some way to make this nicer in Perl5 will have to do for the time being. Of my attempts so far I think this is by far the most likeable.

    Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2014-07-11 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (232 votes), past polls