in reply to OO-call bug uncovered & autovivified functions: defined? exists?

I don't think it makes semantic sense for exists to be applied to functions. Exists applies to aggregates (hashes originally, later extended to arrays, where the semantics are slightly more dubious).

What's the matter with defined &foo?

Exists can't be applied to simple vars since there isn't sufficient state stored to be able to distingish between 'always been undef' and 'had a value, now undef'.

Dave.

  • Comment on Re: OO-call bug uncovered & autovivified functions: defined? exists?
  • Download Code

Replies are listed 'Best First'.
Re^2: OO-call bug uncovered & autovivified functions: defined? exists?
by Sidhekin (Priest) on Oct 28, 2007 at 22:47 UTC

    I don't think it makes semantic sense for exists to be applied to functions.

    Nonetheless there are semantics for it.

    sub E; # exists, but not defined sub D { 1 }; # exists _and_ defined # sub N does _not_ exist $\="\n"; print exists(&N) ? "N exists" : "N doesn't exist"; print exists(&E) ? "E exists" : "E doesn't exist"; print exists(&D) ? "D exists" : "D doesn't exist"; print defined(&N) ? "N is defined" : "N is not defined"; print defined(&E) ? "E is defined" : "E is not defined"; print defined(&D) ? "D is defined" : "D is not defined"; __END__ N doesn't exist E exists D exists N is not defined E is not defined D is defined

    print "Just another Perl ${\(trickster and hacker)},"
    The Sidhekin proves Sidhe did it!

Re^2: OO-call bug uncovered & autovivified functions: defined? exists?
by lodin (Hermit) on Oct 29, 2007 at 00:23 UTC

    Assuming of course, that &foo is equivalent to "simple var" in your sense. If you see globs as aggregates then defined &foo makes sense. And it's easy to see globs as aggregates, as you can do *foo{THING}. So defined (and exists) applied to global things would just translate to check the "slot in the glob" determined by sigil. Now, I don't know what really goes on down there in perl land, but from the outside this picture works for me.

    lodin