[fpc-pascal] How can I implement "thrice" in Free Pascal?

Andrew Pennebaker andrew.pennebaker at gmail.com
Mon Oct 31 08:52:29 CET 2011

Sven, recap: I want to make a GenArray function that returns an array
populated by a generator anonymous function. For example, GenString would
generate a random string by doing GenArray(GenChar). Users could create
their own generators, e.g. GenTree wrapping around GenArray(GenLeaf),
GenGraph wrapping around GenArray(GenNode) and GenArray(GenEdge), etc.


unit Paycheck;
    generic TArray<T> = array of T;
    generic TFn<T> = function() : T;
function GenInt () : TFn<integer>;
function GenBool() : TFn<boolean>;
function GenChar() : TFn<char>;
function GenArray(gen : TFn<T>) : TArray<T>;
function GenString() : TFn<string>;
{ ... }

I'm getting compiler errors for the generics.

$ fpc example.pas
Free Pascal Compiler version 2.7.1 [2011/10/31] for i386
Copyright (c) 1993-2011 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling example.pas
Compiling paycheck.pas
paycheck.pas(6,25) Error: Generics without specialization cannot be used as
a type for a variable
paycheck.pas(6,25) Fatal: Syntax error, ";" expected but "<" found
Fatal: Compilation aborted


Andrew Pennebaker

On Fri, Oct 21, 2011 at 9:47 AM, Sven Barth <pascaldragon at googlemail.com>wrote:

> Am 20.10.2011 17:08, schrieb Andrew Pennebaker:
>  2.6, eh? Awesome.
>> I'm using the SVN trunk, but it's not working for me for some reason.
>> I'll just wait for v2.6 then.
> Didn't you just say that you're using 2.4.4? Trunk is currently 2.7.1.
> Regards,
> Sven
> ______________________________**_________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.**org<fpc-pascal at lists.freepascal.org>
> http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20111031/8f986e72/attachment.html>

More information about the fpc-pascal mailing list