[fpc-pascal] alias a function + overload 'in'

Jürgen Hestermann juergen.hestermann at gmx.de
Sun Dec 18 12:37:54 CET 2011


David Emerson schrieb:
 > 1. Is it possible to make an alias to a function ... so rather than just
 > re-calling with the same parameters, it's actually the same thing? 
like the way
 > we can do, e.g., type natural = cardinal, or const GG = 6, but with a 
function?

I think you can declare a type

type MyFunctionType = function(A : LongString; B : AnsiString; ...) of 
whatever;

then you can declare multiple functions of this type:

var MyFunction1,MyFunction2,MyFunction3 : MyFunctionType;

so all these variables share the same declaration and you can change it 
at a central point;




 > 2. is it possible to overload the 'in' operator, so that it may work 
(using
 > supplied code) on things that are not a pascal set?

I do not know whether it is possible but I hate such overloading. An 
operator defined by the Pascal language should not become a chimera. It 
destroys the logic of the language. If every identifier and every 
operator can get an arbitrary meaning then what is the grounding of the 
language? Hiding details with such mechanism does not help understanding 
the code, just the opposite.

Why not simply use a function for such things?



More information about the fpc-pascal mailing list