473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Code block function syntax, anonymous functions decorator

def run3( block ):
for _ in range( 3 ):
block()

run3():
normal_suite()

Introduces new syntax; arbitrary functions can follow 'colon'.

Maintains readability, meaning is consistent.

Equivalent to:

def run3( block ):
for _ in range( 3 ):
block()

@run3
def anonfunc():
normal_suite()

Simplification in cases in which decorators are use often.
Feb 6 '08 #1
2 1380
ca********@gmail.com schrieb:
def run3( block ):
for _ in range( 3 ):
block()

run3():
normal_suite()

Introduces new syntax; arbitrary functions can follow 'colon'.

Maintains readability, meaning is consistent.

Equivalent to:

def run3( block ):
for _ in range( 3 ):
block()

@run3
def anonfunc():
normal_suite()

Simplification in cases in which decorators are use often.
This is non-sensical - how do you invoke anonfunc? They would all bind
to the same name, run3. Or to no name as all, as your "spec" lacks that.

Besides, it's butt-ugly IMHO. But taste comes after proper definition...

Diez
Feb 6 '08 #2
On Feb 6, 4:59*pm, "Diez B. Roggisch" <de...@nospam.web.dewrote:
castiro...@gmail.com schrieb:


def run3( block ):
* *for _ in range( 3 ):
* * * block()
run3():
* *normal_suite()
Introduces new syntax; arbitrary functions can follow 'colon'.
Maintains readability, meaning is consistent.
Equivalent to:
def run3( block ):
* *for _ in range( 3 ):
* * * block()
@run3
def anonfunc():
* *normal_suite()
Simplification in cases in which decorators are use often.

This is non-sensical - how do you invoke anonfunc? They would all bind
to the same name, run3. Or to no name as all, as your "spec" lacks that.

Besides, it's butt-ugly IMHO. But taste comes after proper definition...

Diez- Hide quoted text -

- Show quoted text -
The fallacy here is that @run3 as described is not a typical
decorator, such one that returns a function. It is called at
"definition"-time, that is, when the function definition is executed,
and executes the code.

Feb 7 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
0
by: Dave Benjamin | last post by:
Here are some more ideas for how to implement a statement-friendly code block syntax in Python. Hopefully more "Pythonic" (that is, of or pertaining to those features noticably reminiscent of...
20
by: Hung Jung Lu | last post by:
Hi, I know people have talked about it before, but I am still really confused from reading the old messages. When I talk about code blocks, I am not talking about Lisp/Ruby/Perl, so I am not...
14
by: Sandy Norton | last post by:
If we are going to be stuck with @decorators for 2.4, then how about using blocks and indentation to elminate repetition and increase readability: Example 1 --------- class Klass: def...
8
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def...
10
by: Ron_Adam | last post by:
I'm trying to figure out how to test function arguments by adding a decorator. @decorate def func( x): # do something return x This allows me to wrap and replace the arguments with my own,...
18
by: Ralf W. Grosse-Kunstleve | last post by:
My initial proposal (http://cci.lbl.gov/~rwgk/python/adopt_init_args_2005_07_02.html) didn't exactly get a warm welcome... And Now for Something Completely Different: class autoinit(object):...
4
by: Noah | last post by:
I have a dictionary that I would like to expand to satisfy a function's agument list. I can used the ** syntax to pass a dictionary, but this only works if each key in the dictionary matches an...
3
by: Ramon Crehuet | last post by:
Dear all, I have a Fortran programming background and I have some difficulties in understading how function wrappers work. I have delved into the subject because of the new decorators, but I...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.