Barth, something's not quite right. I've compiled and installed the trunk version of fpc, but it won't recognize this syntax.<div><br></div><div>paycheck.pas:</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">unit Paycheck;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">interface</font></div><div><font class="Apple-style-span" face="'courier new', monospace">type</font></div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-tab-span" style="white-space:pre"> </span>TArray<T> = array of T;</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">...</font></div><div><br></div><div>Trace:</div><div><br></div><div><div><font class="Apple-style-span" face="'courier new', monospace">fpc example.pas</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">Compiling example.pas</font></div><div><font class="Apple-style-span" face="'courier new', monospace">Compiling paycheck.pas</font></div>
<div><font class="Apple-style-span" face="'courier new', monospace">paycheck.pas(4,8) Fatal: Syntax error, "=" expected but "<" found</font></div><div><font class="Apple-style-span" face="'courier new', monospace">Fatal: Compilation aborted</font></div>
</div><div><br></div><div>Either my syntax is wrong, or trunk doesn't have the syntax, or I'm having trouble getting the trunk version.</div><div><br></div>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 Tue, Oct 18, 2011 at 3:55 PM, 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;">
<div class="im">On 18.10.2011 21:30, Jonas Maebe wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On 18 Oct 2011, at 20:03, Andrew Pennebaker wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
In particular, if anyone knows a way to implement a general concatenation<br>
function Concat(Arr1, Arr2), let me know.<br>
</blockquote>
<br>
I'm under the impression that you are trying to program in a statically typed language the same way as you'd use a dynamically typed language. Even with generic functions (which, as mentioned before, are not yet supported by FPC) you'd have to explicitly instantiate such a function for every type you'd want to do this for.<br>
</blockquote>
<br></div>
At least in theory it should work with generic functions (and using the Delphi compatible generic syntax):<br>
<br>
=== source begin ===<br>
<br>
type<br>
TGenArray<T> = array of T; // this should work in trunk already<br>
<br>
function Concat<T>(Arr1, Arr2: TGenArray<T>): TGenArray<T>;<br>
begin<br>
SetLength(Result, Length(aArray1) + Length(aArray2));<br>
if Length(aArray1) > 0 then<br>
Move(aArray1[0], Result[0], Length(aArray1) * SizeOf(T));<br>
if Length(aArray2) > 0 then<br>
Move(aArray2[0], Result[Length(aArray1)], Length(aArray2) * SizeOf(T));<br>
end;<br>
<br>
var<br>
arr1, arr2, res: array of Integer;<br>
begin<br>
// init arr1<br>
...<br>
// init arr2<br>
...<br>
res := Concat<Integer>(arr1, arr2);<br>
...<br>
end.<br>
<br>
=== source end ===<br>
<br>
(tested using a non generic integer version)<br>
<br>
Regards,<br><font color="#888888">
Sven</font><div><div></div><div class="h5"><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></div>