scripting language newbie - compatibility

Alex Martelli alex at magenta.com
Tue Aug 8 11:38:04 EDT 2000


"Cameron Laird" <claird at starbase.neosoft.com> wrote in message
news:5F9CA331C1AE8845.FBC506A6C7B692DE.98843FA4AFCA9804 at lp.airnews.net...
    [snip]
> Tcl does a different kind of metaprogramming.
>
> In Tcl, it's considered good style to write new control
> structures, on the order of [do ... until] or [$handle
> search $action].
>
> Python's attitude is more that, "Guido has provided".
> Control flow should involve only the elements that already
> exist.  Sophisticated programming is a matter of object
> definition, with the avant-garde occasionally indulging
> in lambda and map.

True -- the style, the _attitude_, is indeed different.
In Python, we tend to tweak/create objects to work
with the existing control structures rather than create
new ones.


> An example is currently under discussion in comp.lang.tcl.
>   $file close
> resists significant byte compilation, because $file might
> be *anything*--this command could, with little strain, have
> the effect of printing the word, "close", to the screen.

Sorry, but I don't catch the big difference wrt
    thefile.close()
which could just as easily print the word to the screen...?

class printwhateverisaskedfor:
    def __dummy(self,*args,**kwargs):
        pass
    def __getattr__(self,name):
        print name
        return self.__dummy

thefile=printwhateverisaskedfor()


It's true that in Python's "thefile.close()" our "thefile" cannot
be "just anything" -- it must be an instance of some class, or,
if it's a built-in object, then it must have a close method that
can be called without arguments.  But surely in Tcl, too, there
will be an error if 'file' currently holds, say, an integer.  So...?

One bytecompiles "lookup 'close' on object contained in 'file',
if not found raise appropriate exception, if found perform
call on it without arguments" -- more concisely, "send close
message to whatever object file currently refers to".  Maybe
the lack of the "whatever object"/"send XX message" concepts
makes a significant difference, but bytecompilation is still a
(pretty modest) win anyway, innit?


Alex






More information about the Python-list mailing list