New statement proposal for Python
David LeBlanc
whisper at oz.nospamnet
Thu Jun 14 12:19:08 EDT 2001
One thing that bugs me about Python is that there's no really good way to
have named constants so that magic numbers can be avoided. Assigning to a
variable that (should) never changes is not the same (i.e. the "should
never" part).
My proposal:
alias httpport : 80
alias astring : "Strings are ok too!"
alias alist : [a, b, c]
alias atuple : {one : 1} #etc.
alias aconstant : can be anything not containing an explict nl or #
alias true: 1 # create an alias for 1
alias true: not 0 # this is ok too, but not after the previous
# declaration!
>> error: redefinion error!
alias false: is zero # everything up to the nl or octothorpe is the
# replacement text
A reoccurance of the same label to the left of the colon in the same
scope (or should this be global?) is a redefintion error. The occurance
of a newline in the replacement text to the right of the colon is an
error _even_if_escaped_. Encoded newlines: "\n" are acceptable but are
not converted by the alias statement. In fact no processing at all of the
replacement text is ever done, although the resulting text may be
evaluated by the python parser.
There is no possiblity of substitution in these (what are essentially)
macros, nor should there ever be - this is not an analog for #define
foo(a,b,c) where one can expect a, b and c to be substituted within the
body of the define! The only purpose is to assign invariant labels to
constant values.
Of course, there might be other hidden gotchas that I haven't thougt
of...
Dave LeBlanc
More information about the Python-list
mailing list