[Python-ideas] relaxing keyword usage restrictions

Terry Reedy tjreedy at udel.edu
Fri Sep 9 18:05:52 CEST 2011

On 9/9/2011 3:21 AM, H Krishnan wrote:

>     P.S.. Yes, that's valid scheme? So what? Redefining 'define' pretty
>     much guarantees that the rest of your program will fail.
>     (define  define  3)
>     (display  (*  define  5))=>  15
>     (define  x4)=>  FAIL
>     The fact that another language allows you to shoot yourself in the
>     foot isn't a good argument that Python should allow that too.
> Yes, scheme does not have special syntax for 'keywords' but still allows
> keywords to be overridden.

In the above, 'define' is not a keyword, it is a built-in function or 
macro name. Python allows those to be over-ridden too, with the same 

list = 3
list(1,2,3) # TypeError: 'int' object is not callable

Because of its simple one-syntax-fits-all-needs design, I do not think 
Scheme has or needs functional keywords in the way Python does. For 
instance, the class statement, with it 'class' keyword, can be replaced 
by a call to the builtin 'type' class. The name 'type' can be 
over-ridden just like 'define' above.

Perhaps Scheme has value keywords like Common Lisp (NIL?), I don't know. 

"In Common Lisp, the term "keyword" (or "keyword symbol") is used for a 
special sort of symbol, or identifier. Unlike other symbols, which 
usually stand for variables or functions, keywords are self-quoting and 
evaluate to themselves. Keywords are usually used to label named 
arguments to functions, and to represent symbolic values."

Python has keyword values None, False, and True. These used to just be 
builtin identifiers that could be over-ridden, but were made keywords to 
prevent that.

 > But nothing (but syntax highlighters)

and the parser -- see my other post and Paul Moore's followup.

> will break in Python by allowing keywords as identifiers,

If you disagree, try changing the grammar to do what you want while 
keeping Python an LL(1) language.

 > and so it is a less drastic change for Python.

We seem to have different ideas of 'drastic' ;-).

Terry Jan Reedy

More information about the Python-ideas mailing list