Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by metadoktor (Hermit)
on May 03, 2002 at 19:42 UTC ( [id://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?

metadoktor

"The doktor is in."

  • Comment on Specific Examples? - Re: A Macro System for Perl?

Replies are listed 'Best First'.
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.

    -sam

      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.

        -sam

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

      -Lee

      "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)

        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.

        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.

        -sam

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found