Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Specific Examples? - Re: A Macro System for Perl?

by metadoktor (Hermit)
on May 03, 2002 at 19:42 UTC ( #163882=note: print w/ replies, xml ) Need Help??

in reply to A Macro System for Perl?

Do you have any examples of how you would like to use Macros in Perl?


"The doktor is in."

Comment on Specific Examples? - Re: A Macro System for Perl?
Re: Specific Examples? - Re: A Macro System for Perl?
by samtregar (Abbot) on May 03, 2002 at 19:48 UTC
    Well, that's rather the question, isn't it? I guess at the very least I'd like to be able to write something that looks and feels like suroutine but is inlined into the code that "calls" it, thus avoiding the overhead of a real subroutine call:
    macro beep ($) { print LOG "BEEP: $_[0]\n"; }
    Then I can beep() to my heart's content without killing my program with the subroutine overhead.

    But that's just the start. Reading "On Lisp" made me realize that an expressive macro system can do more than just provide a fast, clean alternative to subroutine calls. How would this work in Perl, which is a lot more varied than Lisp? I'm not at all sure.


      I think you will be able to do this in Perl 6: sub beep ($text) is inline { print $LOG "BEEP: $text\n"; }
      I've seen examples of this (is inline) for custom operators on the perl6-language list.
        Sounds good. So how do we get it in Perl 5? I live in the present and Perl 6 just seems like a nice daydream most days.


      Keep in mind though Lisp is somewhat slow to begin with. I'd wager that mundane Perl coding would still beat profiled Lisp.


      "To be civilized is to deny one's nature."
        I wouldn't bet that. A good compiled lisp, and there are a number of them, will beat the pants off of perl for many things. (Regular expressions being a notable exception)
        Now why would you just assume that? There are some really fantastic optimizing compilers for Lisp out there, not to mention veteran Lisp hackers with 20-odd years of experience making fast Lisp code...

        That's like saying that mundane C will beat profiled Perl, which is just as false.


        Hello. One of the Monastery's resident Common Lisp users here. I'd take that wager in a second. With the exception of certain things that Perl is explicitly optimized for (like regexes, string processing and such) I'd expect a quality Lisp (e.g. Lispworks, Allegro, CMUCL) to do much better. For example, I have considerable code doing numerical computations in Lisp, and it's typically not even worth rewriting it in (for example) C to attempt to get a speed improvement.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://163882]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-09-15 09:37 GMT
Find Nodes?
    Voting Booth?

    My favorite cookbook is:

    Results (145 votes), past polls