Weird Language Features

Eric Clayberg clayberg at instantiations.com
Sun Feb 18 21:40:35 EST 2001


"Dave Cross" <dave at dave.org.uk> wrote in message
news:nnhv8t4obq30ljfgseplp7pi4khhsf9g9n at 4ax.com...
>
> [Please watch the replies on this message as it's heavily
> cross-posted]
>
> I'm doing some comparisons on programming language features and I'd be
> very interested to know how you would handle the following scenarios
> in your programming language of choice.
>
> 1/ The programmer calls a function that doesn't actually exist within
> the application (or libraries). Is the a feature whereby the
> programmer can create a "catch-all" function which is called in cases
> like these? Can this function examine the list of existing functions
> and call the most appropriate one? Or create a new function on the fly
> and install it into the application?

Smalltalk can do all of the above very easily. This general technique is
used to create generic proxies, for example. I have also played around with
"fault tolerant" apps that could automatically detect and correct spelling
errors in function calls (as a lark; never in production code).

> 2/ Can ou filter the input source code before compilation (or
> interpretation) in some way so that language keywords could be changed
> for other strings? Imagine you wanted to allow someone to program your
> language of choice in, say, French. How would you go about translating
> French keywords into ones that the compiler (or interpreter) could
> understand. What if the translation wasn't one-to-one or fixed? Could
> you put enough intelligence into the translator so that it could
> handle certain strings differently depending on where they appeared in
> the source code?

Smalltalk can also do the above very easily. Everything is Smalltalk is an
object - including the parser, the compiler, the compiled methods and the
method source. Setting up a pre-processor or modifying the actual parser is
very easy to do. Since all of Smalltalk's control structures are built in
Smalltalk itself, you can easily alias any function name or operator to
another. Enhancing the "syntax" and adding your own control structures is
also trivial.

> If you're wondering why I'm inventing these bizarre scenarios, it's
> for a paper I'm writing for this year's Perl Conference.  Perl does
> have these features (see the AUTOLOAD function and source filters) and
> I'm interested in seeing how widespread they are in other languages.
>
> Of course, if you'd like to tell me just why you consider it's a good
> thing that your language of choice doesn't have these features, then
> I'd be only too happy to hear that too.
>
> I'd just like to make it clear that I'm not interested in getting into
> "my language is better than your language" types of flamewars. I'm
> certainly not trying to argue that Perl is better than other languages
> for having these features.
>
> Thanks for your time

Thanks for the interesting thread.

-Eric





More information about the Python-list mailing list