in reply to Re: (Segfault) Re: is_constant() - a routine that detects constant subs
in thread is_constant() - a routine that detects constant subs

I don't think that "bar" and "zip" are constants. As far as I know constants must have a prototype of "()". My is_constant() uses that to avoid testing subs that can't possibly be constants, but maybe that logic is flawed and I need to test all subs?

-sam

  • Comment on Re: Re: (Segfault) Re: is_constant() - a routine that detects constant subs

Replies are listed 'Best First'.
Re^3: (Segfault) Re: is_constant() - a routine that detects constant subs
by particle (Vicar) on May 20, 2002 at 01:20 UTC
    i'm sorry, perhaps i wasn't clear. i was using bar/baz and zip/zap as non-constant/constant pairs. you are correct in that an empty prototype is a necessary condition for a subroutine to be optimized to a constant.

    and truly, thanks for this code. i've been working on a module (possibly named Devel::TrackSub,) which will wrap all subs in any namespaces you specify. it'll be posted as soon as i finish the pod--perhaps tomorrow.

    developing this code was my first attempt at walking the symbol table, and at first seemed a little over my head. i think i've found an elegant solution that can be quite instrumental to others. i'm excited to post it soon.

    i think you've done the same here.

    ~Particle *accelerates*

Re: Re: Re: (Segfault) Re: is_constant() - a routine that detects constant subs
by Anonymous Monk on May 20, 2002 at 18:20 UTC
    As far as I know constants must have a prototype of "()".

    Right. So you can also see if no prototype is set. You can do return 0 unless defined $proto and not length $proto; to cover all alternatives. As it is now you test subroutines with no prototypes. Also, I'd prefer if $is_const was initialized to 0 since the return statements returns dito.

    Cheers,
    -Anomo