Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I'm still having trouble with this.

I still can't see what compile-time executed macros get me that C-style text-substitution macros don't?

Maybe I can see it being used to define new operators, (e.g %% to do my( $div, $rem) =  10 %% 3; print $div, $rem; # 3 1, even this could be acheived with a C-style macro, if perl required whitepace between tokens.

Even inlining functions can be easily achieved using C-style macros, though it is much better taken care of using a keyword/attribute/trait. Either marking the sub to be always inlined, or marking the use of the function to be inlined. This clearly leaves the function name intact and readily understandable to the reader.

Using a macro would to inline the sub would mean using another identifier as a substitute for the actual sub name, which is okay if people stick to some convention.

sub assert { my($x, $y, $z) = @_; if( $x ne $y ) { eval $z; } } macro ASSERT( x,y x) => { if( (x) ne (y) ) { eval (z); } }

Much better to use sub assert : inline {...}

Or  assert( 'this', 'that', "croak('assert failed')" ) : inline;

Now, the obvious (clever?) answer to my dilemma is that if P5 had 'proper' macros, I could implement either or both forms of inlining syntax shown above, and wouldn't have to petition p5p to make my case for this.

So my question becomes, assuming that a 'proper' macro facility existed or could be added to P5, what might the macro(s) to achieve the above inlining syntaxes look like?

Anyone care to speculate? Doesn't have to be fully thought through, comply with LW's high standards, etc. Just a possible syntax for adding the facility to designate and implement the inlining of functions using my syntax above.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller



In reply to Re: Re^3: Macros, LFSPs and LFMs by BrowserUk
in thread Macros, LFSPs and LFMs by stefp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (10)
    As of 2014-07-24 12:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (160 votes), past polls