Re: [fpc-pascal] Feature announcement: Dynamic array extensions

2018-05-24 Thread Ryan Joseph


> On May 25, 2018, at 12:43 PM, Michael Van Canneyt  
> wrote:
> 
> I think the above is "right", and completely equivalent to sets, which are in 
> some ways
> like an array: a "collection" of same typed values.
> 
> To add an element to a set you also do
>  MySet:=MySet+[aValue];
> 
> That said, sets do have
>  Include(MySet,AValue);
> to include a single value.
> 
> Maybe this syntax can be extended to dynamic arrays.

We can do + operator overloads on array classes though so it’s not totally 
crazy to see this syntax in code. Ultimately if it’s optimized well doing [xx] 
is no big problem I suppose.

Having said that my feeling with dynamic arrays is that they’re more difficult 
to use than collection classes and lack basic functionality (until perhaps just 
now) so why use them? I just got burned really bad by some call to 
FPC_INTERLOCKEDINCREMENT64 from dynamic arrays which killed performance (who 
knows why) so I had to pull them out of all my code just in case.

The procedural syntax of Insert(arr, 0, value) is less enticing than 
arr.Insert(0, value) also but again we can fix that with type helpers.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Feature announcement: Dynamic array extensions

2018-05-24 Thread Michael Van Canneyt



On Fri, 25 May 2018, Ryan Joseph wrote:





On May 25, 2018, at 1:37 AM, Sven Barth via fpc-pascal 
 wrote:

This is currently not supported. And to avoid backwards compatibility problems 
with existing operator overloads you'd probably need to convert it to a dynamic 
array first:

=== code begin ===

a += ['foo'];

=== code end ===


What is that doing being the scenes? If it’s creating a whole new array and 
appending it then it’s probably pretty inefficient and hopefully can be 
optimized away.

Since dynamic array helpers work could you expose a function that adds an
element to the array (an grows it if needed) so we could make helpers for
it?  Pushing a value to an array is perhaps the most common function used
for lists so it makes sense to get that right imo.


I think the above is "right", and completely equivalent to sets, which are in 
some ways
like an array: a "collection" of same typed values.

To add an element to a set you also do
  MySet:=MySet+[aValue];

That said, sets do have
  Include(MySet,AValue);
to include a single value.

Maybe this syntax can be extended to dynamic arrays.

Michael.___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Feature announcement: Dynamic array extensions

2018-05-24 Thread Ryan Joseph


> On May 25, 2018, at 1:37 AM, Sven Barth via fpc-pascal 
>  wrote:
> 
> This is currently not supported. And to avoid backwards compatibility 
> problems with existing operator overloads you'd probably need to convert it 
> to a dynamic array first:
> 
> === code begin ===
> 
> a += ['foo'];
> 
> === code end ===

What is that doing being the scenes? If it’s creating a whole new array and 
appending it then it’s probably pretty inefficient and hopefully can be 
optimized away.

Since dynamic array helpers work could you expose a function that adds an 
element to the array (an grows it if needed) so we could make helpers for it? 
Pushing a value to an array is perhaps the most common function used for lists 
so it makes sense to get that right imo.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Feature announcement: Dynamic array extensions

2018-05-24 Thread Anthony Walter
I just wanted to drop this trick to work around problems with record
helpers ..

If you wanted to create a record helper for a type that is not normally
allowed, or perhaps you want to have multiple record helpers for the same
type, consider defining your own separate type and make it contain said
type with implicit conversions to work around those problem.

Example:

TArray = array of T;

TArrayList = record
public
{ The array acting as a list }
var Items: TArray;
{ Convert an array to a list }
class operator Implicit(const Value: TArray): TArrayList;
{ Convert an open array to a list }
class operator Implicit(const Value: array of T): TArrayList;
{ Convert a list to an array }
class operator Implicit(const Value: TArrayList): TArray;

Then in this example you can add all the methods you want to dynamic
arrays, because you have your own type which is nothing more than an alias
to a dynamic array (array of T). Methods such as:

{ Performs a simple safe copy of up to N elements }
procedure Copy(out List: TArrayList; N: Integer);
{ Performs a fast unsafe copy of up to N elements }
procedure CopyFast(out List: TArrayList; N: Integer);
{ Returns the lower bounds of the list }
function Lo: Integer;
{ Returns the upper bounds of the list }
function Hi: Integer;
{ Reverses the items in the list }
procedure Reverse;
{ Swap two items in the list }
procedure Exchange(A, B: Integer);
{ Adds and item to the end of the list }
procedure Push(const Item: T);
{ Appends an array of items to the list }
procedure PushRange(const Collection: array of T);
{ Remove an item from the end of the list }
function Pop: T;
{ Remove an item randomly from the list }
function PopRandom: T;
{ Return a copy of the list with items passing through a filter }
function Filter(Func: TFilterFunc): TArrayList;
{ Resurn the first item matching a condition }
function FirstOf(Func: TFilterFunc): T;
{ Removes an item by index from the list and decresaes the count by one }
procedure Delete(Index: Integer);
{ Removes all items setting the count of the list to 0 }
procedure Clear;
{ Sort the items using a comparer }
procedure Sort(Order: TSortingOrder = soAscend; Comparer: TCompare =
nil);
{ Attempt to find the item using DefaultCompare }
function IndexOf(const Item: T): Integer; overload;
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Feature announcement: Dynamic array extensions

2018-05-24 Thread Sven Barth via fpc-pascal

Am 24.05.2018 um 17:27 schrieb Ryan Joseph:



On May 20, 2018, at 7:23 PM, Sven Barth via fpc-pascal 
 wrote:

The compiler now implements a "+" operator for arrays which is the same as if 
Concat() would be called on the arrays.


I haven’t built it yet but I’m curious, does += now push an element to the 
array or does this just work to concat 2 arrays? I would expect:

a: array of string = ();
a += ‘foo’;


to push a single string on the array.


This is currently not supported. And to avoid backwards compatibility 
problems with existing operator overloads you'd probably need to convert 
it to a dynamic array first:


=== code begin ===

a += ['foo'];

=== code end ===


Also can you use type helpers with dynamic arrays yet? Thinking about how to 
extend them if possible.


Type helpers for dynamic arrays are already possible in 3.0, however 
they must be named array types (both for the declaration of the helper 
as well as the array) and they must be the same type (so equal type 
declarations in different units do not work).


=== code begin ===

{$modeswitch typehelpers}

type
  TLongIntArray = array of LongInt;

  TLongIntArrayHelper = type helper for TLongIntArray
    procedure Test;
  end;

procedure TLongIntArrayHelper.Test;
begin
  Writeln(Length(Self));
end;

var
  lia: TLongIntArray = (1, 2, 3);
begin
  lia.Test;
end.

=== code end ===

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Feature announcement: Dynamic array extensions

2018-05-24 Thread Ryan Joseph


> On May 20, 2018, at 7:23 PM, Sven Barth via fpc-pascal 
>  wrote:
> 
> The compiler now implements a "+" operator for arrays which is the same as if 
> Concat() would be called on the arrays.
> 

I haven’t built it yet but I’m curious, does += now push an element to the 
array or does this just work to concat 2 arrays? I would expect:

a: array of string = ();
a += ‘foo’;


to push a single string on the array.

Also can you use type helpers with dynamic arrays yet? Thinking about how to 
extend them if possible.

Thanks.

Regards,
Ryan Joseph

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Libxml2 - How to get messages on Linux?

2018-05-24 Thread Michael Van Canneyt



On Wed, 23 May 2018, Gabor Boros wrote:


Same problem with Win64. So not Linux specific.


Are these functions callbacks ? If so, is the calling convention correct ?

Michael.


Gabor

2018. 05. 22. 10:06 keltezéssel, Gabor Boros írta:

Hi All,

I need to accomplish validate XML files with an XSD. Found libxml in 
packages and works as expected with Win32. But I have problem with 
messages on Linux 64bit. Got %s instead the real message text. I use the 
below code to get the messages. Any idea why not works with Linux64 bit?


var
   SL_Warning,SL_Error:TStringList;

procedure SchemaValidityWarningFunc(ctx: Pointer; const msg: PChar);
begin
   SL_Warning.Add(msg);
end;

procedure SchemaValidityErrorFunc(ctx: Pointer; const msg: PChar);
begin
   SL_Error.Add(msg);
end;

Gabor
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal