find_name doesn't obey docs on unbound

Patrick R. Michaud pmichaud at pobox.com
Sat Feb 20 15:19:57 UTC 2010


On Fri, Feb 19, 2010 at 05:26:43PM -0800, Jonathan Leto wrote:
> > There is a "find_sub_not_null" option that has the
> > same semantics as "find_name", but does throw an exception
> > if the requested symbol does not exist.  Perhaps this will
> > do what you need.  :-)
> 
> In talking to some developers, they want to be able to see if various
> types of variables are bound, not just subroutines. Is there a way to
> accomplish that currently, or does something like find_name_not_null
> need to be written ?

There's two answers to this:

1.  The "sub" in "find_sub_not_null" is a bit misleading.  The
opcode does find _any_ symbol, not just subs, and it doesn't do
any checking to verify what it has found is a sub.  (The
exception message does have "sub in it", though.  Several of
us would like to see this message changed -- it's a bit
LTA as it stands now.)

2.  The standard mechanism in Parrot for checking if a symbol 
is bound is to do a normal symbol search and then check the
result for null-ness:

    $P0 = find_name 'foo'
    if null $P0 goto foo_not_bound
  foo_is_bound:
    ...

Pm


More information about the parrot-dev mailing list