473,399 Members | 2,146 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,399 software developers and data experts.

xrange() syntactic sugar

Okay, so this is really two requests in one, and they're both kinda
outlandish, but I'm gonna post them nonetheless:

I've always thought xrange() to be ugly; it looks to be a lot of typing
just to get an efficient loop over some numbers. Since it uses the same
'parameters' as the slice operator, I was thinking it would be neat if the
slice operator were to be syntactic sugar for the xrange operator.
Example:

for i in xrange(0,8,2):
pass

is equivalent to

for i in 0:8:2:
pass

Being the syntactic sugar it is, it does nothing but save typing (and
those extra colons do look slightly messy), but it does help unify the
syntax a bit. Now part two:

xrange() objects become an acceptable list index, operating as a slice
operator does. Example:

a[0:8:2] is equivalent to a[xrange(0,8,2)]

Since (correct me if I'm wrong) xrange()s just hold the three numbers
given them, this part (at least) shouldn't be too difficult to implement.
This would then allow the unification to be complete, so a[0:8:2] is
really the list 'a' being indexed by an xrange() object. Therefore a
change in the implementation would be fully backward compatible.

This type of indexing is slightly reminiscent of that of Matlab. I'm not
sure if the new xrange syntax would cause parsing problems; it might in a
statement such as:

for a in 0:8:
2:
pass

But I doubt that would be a problem, so long as the parser gobbles up as
much as it can.

Just a humble RFC. Don't reject me too harshly, I know it's a kinda silly
feature to request :) I just wanna give it a try.
Jul 18 '05 #1
0 1407

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

Similar topics

13
by: Neil Zanella | last post by:
Hello, It seems to me that C# properties are nothing more than syntactic sugar for getters and setters. I wonder whether others hold a different point of view. Basically, what more do they have...
4
by: Bas | last post by:
Hi group, just out of curiosity, is there a list of all the syntactic sugar that is used in python? If there isn't such a list, could it be put on a wiki somewhere? The bit of sugar that I do...
13
by: Sam Kong | last post by:
Hi, While discussing C#'s using statement, a guy and I had an argument. In C# spec (15.13), there's an explanation like the following. using (R r1 = new R()) { r1.F(); } is precisely...
11
by: Helmut Jarausch | last post by:
Hi, are decorators more than just syntactic sugar in python 2.x and what about python 3k ? How can I find out the predefined decorators? Many thanks for your help, Helmut Jarausch
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.