Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
(I've just trimmed the code back in http://perlmonks.com/?node_id=1030806 to use a closure rather than a class -- needed a class back when it was a coroutine... not so much anymore)

Here be Python...

A decorator in python is just syntactic sugar, remembering that Python has first class functions and classes:
def deco(callable): # Do something with callable retval = callable return retval @ deco def example1(): pass #...is identical to def example1(): pass example1 = deco(example1)
A decorator doesn't have to return a callable -- eg you could decorate class SomeClass with @id, and get a fairly useless number bound to the name SomeClass. And in theory you could fiddle with the code in the callable that's passed, and return the identical object but you wouldn't.

One cannot @decorate a lambda, and "_" as a name is just convention.


In reply to Re^7: RFC: Simulating Ruby's "yield" and "blocks" in Perl (Python) by MonkOfAnotherSect
in thread RFC: Simulating Ruby's "yield" and "blocks" in Perl by LanX

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2022-10-07 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (29 votes). Check out past polls.

    Notices?