[fpc-pascal] How can I implement "thrice" in Free Pascal?
andrew.pennebaker at gmail.com
Tue Oct 18 23:08:05 CEST 2011
Barth, something's not quite right. I've compiled and installed the trunk
version of fpc, but it won't recognize this syntax.
TArray<T> = array of T;
paycheck.pas(4,8) Fatal: Syntax error, "=" expected but "<" found
Fatal: Compilation aborted
Either my syntax is wrong, or trunk doesn't have the syntax, or I'm having
trouble getting the trunk version.
On Tue, Oct 18, 2011 at 3:55 PM, Sven Barth <pascaldragon at googlemail.com>wrote:
> On 18.10.2011 21:30, Jonas Maebe wrote:
>> On 18 Oct 2011, at 20:03, Andrew Pennebaker wrote:
>> In particular, if anyone knows a way to implement a general concatenation
>>> function Concat(Arr1, Arr2), let me know.
>> 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.
> At least in theory it should work with generic functions (and using the
> Delphi compatible generic syntax):
> === source begin ===
> TGenArray<T> = array of T; // this should work in trunk already
> function Concat<T>(Arr1, Arr2: TGenArray<T>): TGenArray<T>;
> SetLength(Result, Length(aArray1) + Length(aArray2));
> if Length(aArray1) > 0 then
> Move(aArray1, Result, Length(aArray1) * SizeOf(T));
> if Length(aArray2) > 0 then
> Move(aArray2, Result[Length(aArray1)], Length(aArray2) * SizeOf(T));
> arr1, arr2, res: array of Integer;
> // init arr1
> // init arr2
> res := Concat<Integer>(arr1, arr2);
> === source end ===
> (tested using a non generic integer version)
> fpc-pascal maillist - fpc-pascal at lists.freepascal.**org<fpc-pascal at lists.freepascal.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-pascal