Weird Language Features

Donovan Rebbechi elflord at panix.com
Sun Feb 18 23:28:52 CET 2001


On Sun, 18 Feb 2001 13:16:49 +0000, Dave Cross wrote:

>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?

Posting this from comp.lang.c++. In C++, the object model itself does 
not support this.

In both C and C++, one uses dynamic loading to get this kind of behaviour.
Indeed, interpreters written in C and C++ tend to rely heavily on dynamic
loading.

To get the kind of functionality you're talking about, one would probably
store a function table in a map/tree and one could put a "default"
method in there that acts as a catch all.

However, typically one uses exceptions to deal with failed requests, the
idea being that if a request fails, the caller is in a better position 
than the library author to work out what to do.

>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?

One could do this with macros but it's a fairly primitive solution ...

>  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 one could always write a preprocessor in perl (-;

>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.

C and C++ are standardised (as opposed to implementation defined) languages,
the former is meant to be small, the latter is big enough as it is. 
Introducing support for this kind of thing in the language (either
C or C++) would probably be a mistake IMO.

-- 
Donovan Rebbechi * http://pegasus.rutgers.edu/~elflord/ * 
elflord at panix dot com



More information about the Python-list mailing list