[PATCH] Identifiers with '?'

Michael Hudson mwh21 at cam.ac.uk
Sun May 21 15:33:07 EDT 2000


neelk at brick.cswv.com (Neel Krishnaswami) writes:

> At the risk of treading on the raging identifier-flamewar, I'd like to
> present a one-line patch that brings one of Lisp's little syntactic
> conveniences to Python -- the ability to make identifiers with a
> question mark in the name. This is very useful for naming boolean
> flags and functions.
> 
> An example will probably illustrate most easily.
> 
> Python 1.6a2 (#1, May 21 2000, 14:59:38)  [GCC 2.7.2.1] on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> Copyright 1995-2000 Corporation for National Research Initiatives (CNRI)
> >>> import types
> >>> types.IntType
> <type 'int'>
> >>> instance? = isinstance  # A var with '?' in the name
> >>>
> >>> instance?(3, types.IntType) # It can be used like any other name
> 1
> 
> I've restricted the use of '?' to the same status as numbers; you
> can't start a variable name with '?', but it can be part of the follow
> on. So 'foo?' is legal, but '?foo' isn't. (This is easy to change,
> though.) 
> 
> Patch follows, against the 1.6 alpha in CVS. The change to 1.5.2
> should be likewise obvious. Bon appetit!

Tee hee.  I have on my machine built (in the last few days) a Python
that allows one to use identifiers containing +, *, !, ?, & and @.
This means you have to space your operators properly, but is IMHO
quite a cool mod.  I can clean it up and post the patch for that if
anyone's interested...

do-great-minds-think-alike-or-fools-never-differ?-ly y'rs
M.

-- 
  Premature optimization is the root of all evil in programming.  
                                                       -- C.A.R. Hoare



More information about the Python-list mailing list