However, it occured to me a case in which for some reason it would have seemed natural for me to use it. Trimmed down to an absolute minimum suppose I have a class Foo:
Such that the do_cb method accepts and runs a callback. Now, if I use it like thus:# -*- Perl -*- package Foo; use strict; use warnings; sub new { bless [], shift } sub warn { shift; warn "[", __PACKAGE__, "] ", @_ } sub do_cb { my ($self, $cb)=@_; $self->$cb; } 1; __END__
then everything is fine. But if I try#!/usr/bin/perl use strict; use warnings; use Foo; my $f=Foo->new; $f->do_cb(sub { my $caller=shift; $caller->warn("no good for me\n"); }); __END__
warn $caller "no good for me\n";
instead, it doesn't work due to warn() being a builtin function. Incidentally, the latter form seems quite expressive to me in terms of message passing to the "caller" object.
So leaving aside for the moment any argument about how {risky,dangerous,error-prone,whatever} this could be (for I'm aware about them - and please do not point out I can call it "Warn" either, for I know that too), is it first of all possible, some way or another? (Especially given that in perl I can even replace most builtins with my own subs.)
UPDATE: Fixed a "minor but relevant" bug! (Thanks to Fletch.)
In reply to Speaking of indirect object notation... by blazar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |