Barth, something's not quite right. I've compiled and installed the trunk
version of fpc, but it won't recognize this syntax.

paycheck.pas:

unit Paycheck;
interface
type
TArray<T> = array of T;
...

Trace:

fpc example.pas
Compiling example.pas
Compiling paycheck.pas
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.

Cheers,

Andrew Pennebaker
www.yellosoft.us

On Tue, Oct 18, 2011 at 3:55 PM, Sven Barth <pascaldra...@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 ===
>
> type
>  TGenArray<T> = array of T; // this should work in trunk already
>
> function Concat<T>(Arr1, Arr2: TGenArray<T>): TGenArray<T>;
> begin
>  SetLength(Result, Length(aArray1) + Length(aArray2));
>  if Length(aArray1) > 0 then
>    Move(aArray1[0], Result[0], Length(aArray1) * SizeOf(T));
>  if Length(aArray2) > 0 then
>    Move(aArray2[0], Result[Length(aArray1)], Length(aArray2) * SizeOf(T));
> end;
>
> var
>  arr1, arr2, res: array of Integer;
> begin
>  // init arr1
>  ...
>  // init arr2
>  ...
>  res := Concat<Integer>(arr1, arr2);
>  ...
> end.
>
> === source end ===
>
> (tested using a non generic integer version)
>
> Regards,
> Sven
>
> ______________________________**_________________
> fpc-pascal maillist  -  
> fpc-pascal@lists.freepascal.**org<fpc-pascal@lists.freepascal.org>
> http://lists.freepascal.org/**mailman/listinfo/fpc-pascal<http://lists.freepascal.org/mailman/listinfo/fpc-pascal>
>
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to