> As for the second decorator, sure test(lambda a: print("You are in block %s" % a)) will work,
not for me...
lanx@nc10-ubuntu:~$ python
Python 2.5.2 (r252:60911, Jan 20 2010, 23:16:55)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def rubyyielder(gen):
... def wrapped_gen(block):
... for elem in gen():
... block(elem)
... return wrapped_gen
...
>>> @rubyyielder
... def test():
... print("In test")
... yield 1
... print("back in test")
... yield 2
...
>>> test(lambda a: print("You are in block %s" % a))
File "<stdin>", line 1
test(lambda a: print("You are in block %s" % a))
^
SyntaxError: invalid syntax
I suppose the lamda syntax has more restrictions...
> If you used a non-keyword such as "send" instead of "yield" you could do Evil and avoid the first decorator. This is left as an exercise.
Simple, I can just port the semantic of my OP and let send execute the callback which is passed to @test.¹
Cheers Rolf
( addicted to the Perl Programming Language)
Update
¹) at second thought this would require a possibility to access the arguments of the caller. I suppose the caller is an object where arguments are accessible.
Update
deleted undiplomatic irony =)
-
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 How to display code and escape characters
are good places to start.
|