develooper Front page | perl.perl6.language | Postings from June 2005

caller and want

Thread Next
Gaal Yahas
June 8, 2005 11:21
caller and want
Message ID:
A06 and S06 are in disagreement about the "caller" builtin, and I need
help understanding either one.

A06 [plus updates] stipulates this signature for caller:

multi *caller (?$where = &?CALLER::SUB, Int +$skip = 0, Str +$label)
    returns CallerContext { ... }

In S06 it's (I infer):

multi *caller (Class ?$kind = Code, Int +$skip = 0, Str +$label) { ... }

I'm assuming S06 is the more correct; A06 said that $where "says where
to stop when scanning up the call stack" but it only makes sense to me
if it says where to *start* scanning.

In the Synopsis version, does $kind imply a filtering condition on *all*
stack frames it encounters, or just on where the first one is? That is,
if we have this contrived example:

sub    p() { caller(Sub, :skip<1>).sub.say }
method a() { p() }
sub    b() { a() }
method c() { b() }
sub    d() { c() }

Does this start looking upwards for a Sub, find &b, skip one caller and
print "c"? Or does it find &b, skip one *Sub*, and print "d"?

I'm not sure how this selection mechanism is meant to be used.

Other questions:

- A06 stipulates "CallerContext" but to be more in line with the latest
  S29 draft, we've used "Control::Caller". Okay to use that?
- AES does not enumerate the complete member set. We can use that now :)

- S06 stipulates the method for sub name is "sub". I find "subname" to
  be more appealing. Okay to use that?

- Perhaps caller.sub could be made to return the code ref itself, which
  given introspective capabilities can be a fun thing. At the very
  least, we want to be able to call .arity on the result of a caller,
  but if that, why not also get the signature information, and while
  we're at it -- the actual runtime parameters (if still available, and
  if this doesn't turn out too hard to implement)?

S06's "want" is much simpler than A06's. Can it for now be considered
complete? (I'm asking because A06 links "want" intimately to "caller"
and that appears to no longer be the case.)

Gaal Yahas <>

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About