in reply to Concurrent lexical scopes?

So the the lexical subs cannot truly be lexical subs but merely scalar references to CODErefs. But this introduces the problem of namespace issues e.g

The namespace issue has nothing to do with the coderefs; the problem is that lexical variables (and by abstraction lexical subs too) are not in any namespace at all! Lexial variables exist in their lexical scope, and lexical scope doesn't give a d*mn about packages.

Anyway I don't really see that this is much of a problem - the only use for lexical subs I can see is for 'temporary' subs - you would put those somewhere where they go out of scope quickly - or 'private' subroutines, which you would put in a module anyway (and lexical scope is at most file scope)

-- Joost downtime n. The period during which a system is error-free and immune from user input.

Replies are listed 'Best First'.
Re: Re: Concurrent lexical scopes?
by broquaint (Abbot) on Jun 11, 2002 at 13:44 UTC
    The namespace issue has nothing to do with the coderefs
    It does because the 'lexical subs' are stored in coderefs which are just scalars and you can't have 2 scalars of the same name in the same lexical scope e.g
    my $foo = "I'm a string"; # this will replace previous $foo my $foo = sub { "I'm a coderef" };
    the problem is that lexical variables (and by abstraction lexical subs too) are not in any namespace at all!
    Yes they are and it is the current lexical scope's namespace (which is anonymous and inaccessible through straight perl).

    _________
    broquaint

      You're right. I guess I'm a little more tired than I thought :-)

      Anyway, I guess you're sort of stuck then. The only thing I can think of, is to use something a little more descriptive than $__name__ - how about $__lex_sub__name ?

      I think it would be quite reasonable to disallow the use of scalars called $__lex_sub__* in combination with your module.

      -- Joost downtime n. The period during which a system is error-free and immune from user input.