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.<br>
<br>paycheck.pas:<br><br><span style="font-family: courier new,monospace;">unit Paycheck;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
interface</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
type</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
generic TArray<T> = array of T;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
generic TFn<T> = function() : T;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
function GenInt () : TFn<integer>;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
function GenBool() : TFn<boolean>;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
function GenChar() : TFn<char>;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
function GenArray(gen : TFn<T>) : TArray<T>;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
function GenString() : TFn<string>;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
{ ... }</span><br clear="all"><br>I'm getting compiler errors for the generics.<br><br><span style="font-family: courier new,monospace;">$ fpc example.pas</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Free Pascal Compiler version 2.7.1 [2011/10/31] for i386</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Copyright (c) 1993-2011 by Florian Klaempfl and others</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Target OS: Darwin for i386</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Compiling example.pas</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Compiling paycheck.pas</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">paycheck.pas(6,25) Error: Generics without specialization cannot be used as a type for a variable</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">paycheck.pas(6,25) Fatal: Syntax error, ";" expected but "<" found</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Fatal: Compilation aborted</span><br><br>Cheers,<div><br></div><div>Andrew Pennebaker</div><div><a href="http://www.yellosoft.us" target="_blank">www.yellosoft.us</a></div>
<br><div class="gmail_quote">On Fri, Oct 21, 2011 at 9:47 AM, Sven Barth <span dir="ltr"><<a href="mailto:pascaldragon@googlemail.com">pascaldragon@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Am 20.10.2011 17:08, schrieb Andrew Pennebaker:<div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2.6, eh? Awesome.<br>
<br>
I'm using the SVN trunk, but it's not working for me for some reason.<br>
I'll just wait for v2.6 then.<br>
</blockquote>
<br></div>
Didn't you just say that you're using 2.4.4? Trunk is currently 2.7.1.<div><div></div><div class="h5"><br>
<br>
Regards,<br>
Sven<br>
<br>
______________________________<u></u>_________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.<u></u>org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/<u></u>mailman/listinfo/fpc-pascal</a><br>
</div></div></blockquote></div><br>