[Python-Dev] "declare" reserved word (was: pragma)

M.-A. Lemburg mal@lemburg.com
Fri, 01 Sep 2000 10:43:56 +0200


Greg Ewing wrote:
> 
> "M.-A. Lemburg" <mal@lemburg.com>:
> 
> > If it's just the word itself that's bugging you, then
> > we can have a separate discussion on that. Perhaps "assume"
> > or "declare" would be a better candidates.
> 
> Yes, "declare" would be better. ALthough I'm still somewhat
> uncomfortable with the idea of naming a language feature
> before having a concrete example of what it's going to be
>  used for.

I gave some examples in the other pragma thread. The main
idea behind "declare" is to define flags at compilation
time, the encoding of string literals being one of the
original motivations for introducing these flags:

declare encoding = "latin-1"
x = u"This text will be interpreted as Latin-1 and stored as Unicode"

declare encoding = "ascii"
y = u"This is supposed to be ASCII, but contains  Umlauts - error !"

A similar approach could be done for 8-bit string literals
provided that the default encoding allows storing the
decoded values.

Say the default encoding is "utf-8", then you could write:

declare encoding = "latin-1"
x = "These are the German Umlauts: "
# x would the be assigned the corresponding UTF-8 value of that string

Another motivation for using these flags is providing the
compiler with information about possible assumptions it
can make:

declare globals = "constant"

The compiler can then add code which caches all global
lookups in locals for subsequent use.

The reason I'm advertising a new keyword is that we need
a way to tell the compiler about these things from within
the source file. This is currently not possible, but is needed
to allow different modules (from possibly different authors)
to work together without the need to adapt their source
files.

Which flags will actually become available is left to 
a different discussion.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/