RFC: Viper: yet another python implementation

John Max Skaller skaller at maxtal.com.au
Sun Aug 15 17:28:15 CEST 1999


On Tue, 10 Aug 99 23:15:18 GMT, philh at vision25.demon.co.uk (Phil Hunt) wrote:

>In article <37b075ae.2367293988 at news.triode.net.au>
>           skaller at maxtal.com.au "John (Max" writes:
>> This is a request for comments on Viper,
>> Extensions:
>>         6) what do you want?
>
>C-style comments

	With what syntax, and why?

1. Syntax:

The C syntax doesn't support nesting; OTOH the PL/1 ML style 
(* ... *) syntax does.

	New lexicology for strings and comments is easy
enough to add, since it only affects the lexer. However, it is
also easy to create an unreadable mess if _too many_
new lexical forms are introduced.

2. Why?

One obvious reason: annotating things like function parameters
with C++/Python style comments can expand source code too much:

	def f( # a function
		a, # arg1
		b # arg2
	):

might be written

	def f /* a function */ ( a /* arg1 */, b /* arg2 */ ):

on one line with C style comments. 

>sorted dictionary loops, eg:
>for k, v in dict.sortedValues():
>where this is sorted by keys.

	Something to support dictionary iteration is
needed. My thought was:

	for k in dict: value = dict[k] ...

which is equivalent to

	keys = dict.keys()
	keys.sort()
	for k in keys: value = dict[k]

Unfortunately, you can't write

	for k in dict.keys().sort():

because the keys() refers directly to the dictionary
keys, and sort() sorts in place. Both these methods
are the way they are for efficiency. Perhaps a new
method would be a good solution (for Python 1.6 too):

	for k in dict.sorted_keys(): ...

however, there is a related idea here, that a dictionary
with all values None is isomorphic to a set. Thus

	k in dict

would mean

	k in set

which is natural notation, and 

	k in dict 

is an extension to dictionaries in which the
set is the set of keys.

John Max Skaller                ph:61-2-96600850              
mailto:skaller at maxtal.com.au       10/1 Toxteth Rd 
http://www.maxtal.com.au/~skaller  Glebe 2037 NSW AUSTRALIA




More information about the Python-list mailing list