Front page | perl.perl5.porters |
Postings from April 2015
Re: Is there a clever way to null out non-void subs?
Thread Previous
|
Thread Next
From:
Eric Brine
Date:
April 23, 2015 03:16
Subject:
Re: Is there a clever way to null out non-void subs?
Message ID:
CALJW-qErpzD9MCSL0o00FA4=-mmP=BcZstvUgVEmG666sFzHkg@mail.gmail.com
This would be trivial for a call checker wouldn't it?
On Tue, Apr 21, 2015 at 9:07 PM, Tom Christiansen <tchrist@perl.com> wrote:
> I've been pondering a particular puzzle for about a week, and I
> keep coming back to a dive into either the core perl guts or else
> source filters. I can't find anything on the net about it.
>
> Thinking about how sub () {23} functions get replaced with their
> return values by the compiler, and how never looks at if (0) blocks,
> I took to wondering if there isn't some easy way to take code like
>
> debug("Hello there %s, how are you?", somebody(42));
>
> and "retroactively" null it out so that it it ripe for pruning and
> doesn't cost anything to speak of. Preferably something that could
> be done with just core facilities, but this is not a strict requirement.
>
> You can't just do
>
> *debug = sub () { 0 };
>
> before the compiler gets to it because of the mismatched prototype.
>
> Plus you have the problem of wasted evaluation of somebody(42).
>
> The other easy approach of magically replacing it with
>
> if (0) { debug("Hello there %s, how are you?", somebody(42)) }
>
> would work, but nobody wants to type all that gunk.
>
> Is there a way to do this using some dirty hacking in the C API, or
> will it require something like Filter::cpp or Text::cpp, at which point
> it becomes "easy", but . . . well, text filters.
>
> I've looked pretty hard for anything like this, including using the
> cood CPAN grepper, and the most I have come if stuff that turns something
> like DEBUGGING into a void function that evals to 0 or 1 and then they
> go wrapping their calls to it.
>
> I want to avoid that and just write
>
> _ASSERT( length($x) % 2 == 0 );
>
> and then have those go completely away the way you can in C. I don't
> like the existing Perl stuff, because it never goes all the way away.
>
> Do I have to use the cpp to do this, or is there something in the
> Perl guts that would work?
>
> Lacking that, is there anything we can add to the core to *make* it work!?
>
> I will entertain any idea, no matter how crazy. :)
>
> Thanks much,
>
> --tom
>
Thread Previous
|
Thread Next