overriding built-ins

Alex Martelli aleax at aleax.it
Tue Sep 30 10:36:08 CEST 2003


dan wrote:

> Thanks for the responses, and my apologies for getting the terminology
> confused.  What I really should have asked is this:
> 
> * Is there any way to create your own statements?
> and,
> * if so, can they override the names of built-in statements such as
> 'print'?
> 
> To which the answers seem to be, no, and definitely not (with a strong

Right.

> hint of "why would you ever want to do that"?)

Actually, I suspect it's pretty obvious to most respondents why one
might want to create their own language, embedded inside Python but
enriched and modified.  Guido himself is on record as having the far
_dream_ of one day managing to let people define "application-specific
languages" inside Python -- IF he can come up with a smart way to
do it, one that won't destroy Python's simplicity and utter
straightforwardness.  I suspect that "strong hint" reflects a deep
distrust that any such silver bullet exists, and a deep fear that in
the pursuit of such elusive goals Python's simplicity and philosophy
of "there should be only one way to do it" might be destroyed.

There exist languages which have very powerful macro systems.  Common
Lisp is the canonical example, but if you prefer syntax that is rather
more Python-like you might look into Dylan instead.  Lisp and Dylan
also share the powerful concept of "multiple dispatch", a way to do
OO that is as superior to C++'s or Python's as the latter is superior
to that of _purely_ single-inheritance languages [ones without even
such helpers as Java interfaces or Ruby mixins].  Some languages do
not really have such power, but can still come close -- e.g., in
Smalltalk, "IF" is not a _statement_, just a method to which you pass
code blocks, so there is little impediment to piling up "more of the
same" to make your own application-specific language inside it; to
a lesser extent, you can do somewhat similar things in Ruby -- and
Perl has its own inimitable way (google for "Lingua Latina Perligata"
if you're REALLY TRULY into such... ahem... divertissements:-).

A widespread feeling around the Python community is that Python's own
uniqueness is SIMPLICITY.  Python is straightforward and thereby most
productive because it DOESN'T EVEN TRY to let you bend its syntax in
strange ways (in that, it's closest to Java -- i.e., it even lacks the
puny "preprocessor" that C and C++ come with).  If you want an
application-specific language, you design and implement it in the good
old time-trusted way -- lexx and yacc, or their Python equivalents (of
which there are quite a few) -- Python stays Python, your language
is your own, and everybody (hopefully) is happy...;-).


Alex





More information about the Python-list mailing list