[fpc-pascal] Re: Delphi's anonymous functions in Free Pascal

Roland Schäfer roland.schaefer at fu-berlin.de
Tue Oct 18 23:03:16 CEST 2011


On 10/18/2011 10:23 PM, Andrew Pennebaker wrote:
> Schäfer, thanks, that's a lot of practical information. Have you used
> Haskell QuickCheck

In fact, I have, but I don't see the connection.

> Yes, pointers are probably the only way I can implement this, for now. If at
> all possible, I'd like to use more idiomatic Pascal code.

Those sentences form a contradiction.

> but there's only so much you can do without lambdas.

I saw the l-word coming.

> If I decide to use pointers, 

... you'll end up on CodeSOD.

> what's the syntax for accepting a function
> pointer (unknown type, unknown arity) and calling the function? In C, you

In Pascal, you use procedural type variables, not function pointers; it
makes a conceptual and a practical difference. Procedural type variables
have a type (hence the name). You can push them around as untyped
Pointers, but you shouldn't. My *joke* was about turning the result type
of your functions into Pointer, so all your GenSomething functions are
of the same procedural type and can thus be accepted as an argument by
your generator... with virtually unusable results. Please, RTM.

> In C you have to know the entire function signature and explicitly cast the pointer
> to that before you can call it. Does Pascal also require this, or can I just
> accept a pointer and call it as if it were a normal function call?

If you read the aforementioned reference and meditate about it, you
might notice why you don't have to cast procedural type variables in Pascal.

Regards,
Roland



More information about the fpc-pascal mailing list