Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Something's wrong with the makefiles. I checked out the Subversion trunkhttp://svn.freepascal.org/svn/fpc/trunk/and ran sudo make install. Partway through the process, when I run fpc in a new terminal, I get: $ fpc Free Pascal Compiler version 2.7.1 But when make finishes installing, I run fpc again and get: $ fpc Free Pascal Compiler version 2.4.4 At some point during the installation process, an old fpc is being copied over the new. I've tried removing the old fpc. But when I rerun make install, the same thing happens. Cheers, Andrew Pennebaker www.yellosoft.us On Fri, Oct 21, 2011 at 9:47 AM, Sven Barth pascaldra...@googlemail.comwrote: Am 20.10.2011 17:08, schrieb Andrew Pennebaker: 2.6, eh? Awesome. I'm using the SVN trunk, but it's not working for me for some reason. I'll just wait for v2.6 then. Didn't you just say that you're using 2.4.4? Trunk is currently 2.7.1. Regards, Sven __**_ fpc-pascal maillist - fpc-pascal@lists.freepascal.**orgfpc-pascal@lists.freepascal.org http://lists.freepascal.org/**mailman/listinfo/fpc-pascalhttp://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
I forcibly sudo cp ppc386 /usr/local/bin/fpc, mitigating the issue. Yeah, something in the makefile installation process is definitely moving over an older version. (I deleted the whole directory for the v2.4.4 subversion, so that's not the problem.) Cheers, Andrew Pennebaker www.yellosoft.us On Mon, Oct 31, 2011 at 3:33 AM, Andrew Pennebaker andrew.penneba...@gmail.com wrote: Something's wrong with the makefiles. I checked out the Subversion trunkhttp://svn.freepascal.org/svn/fpc/trunk/and ran sudo make install. Partway through the process, when I run fpc in a new terminal, I get: $ fpc Free Pascal Compiler version 2.7.1 But when make finishes installing, I run fpc again and get: $ fpc Free Pascal Compiler version 2.4.4 At some point during the installation process, an old fpc is being copied over the new. I've tried removing the old fpc. But when I rerun make install, the same thing happens. Cheers, Andrew Pennebaker www.yellosoft.us On Fri, Oct 21, 2011 at 9:47 AM, Sven Barth pascaldra...@googlemail.comwrote: Am 20.10.2011 17:08, schrieb Andrew Pennebaker: 2.6, eh? Awesome. I'm using the SVN trunk, but it's not working for me for some reason. I'll just wait for v2.6 then. Didn't you just say that you're using 2.4.4? Trunk is currently 2.7.1. Regards, Sven __**_ fpc-pascal maillist - fpc-pascal@lists.freepascal.**orgfpc-pascal@lists.freepascal.org http://lists.freepascal.org/**mailman/listinfo/fpc-pascalhttp://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
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. paycheck.pas: unit Paycheck; interface type generic TArrayT = array of T; generic TFnT = function() : T; function GenInt () : TFninteger; function GenBool() : TFnboolean; function GenChar() : TFnchar; function GenArray(gen : TFnT) : TArrayT; function GenString() : TFnstring; { ... } I'm getting compiler errors for the generics. $ fpc example.pas Free Pascal Compiler version 2.7.1 [2011/10/31] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Darwin for i386 Compiling example.pas Compiling paycheck.pas paycheck.pas(6,25) Error: Generics without specialization cannot be used as a type for a variable paycheck.pas(6,25) Fatal: Syntax error, ; expected but found Fatal: Compilation aborted Cheers, Andrew Pennebaker www.yellosoft.us On Fri, Oct 21, 2011 at 9:47 AM, Sven Barth pascaldra...@googlemail.comwrote: Am 20.10.2011 17:08, schrieb Andrew Pennebaker: 2.6, eh? Awesome. I'm using the SVN trunk, but it's not working for me for some reason. I'll just wait for v2.6 then. Didn't you just say that you're using 2.4.4? Trunk is currently 2.7.1. Regards, Sven __**_ fpc-pascal maillist - fpc-pascal@lists.freepascal.**orgfpc-pascal@lists.freepascal.org http://lists.freepascal.org/**mailman/listinfo/fpc-pascalhttp://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 31.10.2011 08:52, schrieb Andrew Pennebaker: paycheck.pas: unit Paycheck; interface type generic TArrayT = array of T; generic TFnT = function() : T; function GenInt () : TFninteger; function GenBool() : TFnboolean; function GenChar() : TFnchar; function GenArray(gen : TFnT) : TArrayT; function GenString() : TFnstring; { ... } I'm getting compiler errors for the generics. $ fpc example.pas Free Pascal Compiler version 2.7.1 [2011/10/31] for i386 Copyright (c) 1993-2011 by Florian Klaempfl and others Target OS: Darwin for i386 Compiling example.pas Compiling paycheck.pas paycheck.pas(6,25) Error: Generics without specialization cannot be used as a type for a variable paycheck.pas(6,25) Fatal: Syntax error, ; expected but found Fatal: Compilation aborted Ok, you're experiencing two different problems here: 1. you are trying to do inline specializations in the functions GenInt, GenBool, GenChar and GenString. This is not supported in mode ObjFPC. You need to use {$mode delphi} instead (though I don't know whether this will indeed work in trunk). 2. Your function GenArray is a generic function. These are not yet supported by FPC (they are on my ToDo list though). Once they are implemented your declaration will need to look like this: function GenArrayT(gen: TFnT): TArrayT; And you will call them like this: function Foo: Integer; ... var intarray: TArrayInteger; begin intarray := GenArrayInteger(@Foo); end. This does NOT work yet. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
On 31 Oct 2011, at 08:36, Andrew Pennebaker wrote: I forcibly sudo cp ppc386 /usr/local/bin/fpc, mitigating the issue. Yeah, something in the makefile installation process is definitely moving over an older version. Create a symlink from /usr/local/bin/ppc386 to /usr/local/lib/fpc/2.7.1/ppc386 (or ppcx64 in case you're on x86-64). fpc searches for a compiler binary in the same directory as where its own binary is located. make install does not create/overwrite ppcXXX, because that changes the default compiler (which is a separate step from installing a new version in parallel with another version). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Sven, awesome! Looks like FPC will be getting some exciting features in the near future. Jonas, make install does, however, overwrite /usr/local/bin/fpc, which is not a symlink, with an old version during install. Try running fpc -version halfway and after make install. Cheers, Andrew Pennebaker www.yellosoft.us On Mon, Oct 31, 2011 at 6:09 AM, Jonas Maebe jonas.ma...@elis.ugent.bewrote: On 31 Oct 2011, at 08:36, Andrew Pennebaker wrote: I forcibly sudo cp ppc386 /usr/local/bin/fpc, mitigating the issue. Yeah, something in the makefile installation process is definitely moving over an older version. Create a symlink from /usr/local/bin/ppc386 to /usr/local/lib/fpc/2.7.1/ppc386 (or ppcx64 in case you're on x86-64). fpc searches for a compiler binary in the same directory as where its own binary is located. make install does not create/overwrite ppcXXX, because that changes the default compiler (which is a separate step from installing a new version in parallel with another version). Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
On 31 Oct 2011, at 18:29, Andrew Pennebaker wrote: Jonas, make install does, however, overwrite /usr/local/bin/fpc, which is not a symlink, with an old version during install. Try running fpc -version halfway and after make install. The fpc binary does not have a version number. It reports the version number of the compiler binary that it finds. Jonas PS: -version does not mean print the version. It means enable the e, r, s, i, o and n verbosity switches (but your /etc/fpc.cfg probably contains the -l switch, and the logo includes the version number). -iV is the command line option to make the compiler prints just its version.___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
On 31.10.2011 18:29, Andrew Pennebaker wrote: Sven, awesome! Looks like FPC will be getting some exciting features in the near future. Only time will tell whether it's the near future. Also these features are meant to be Delphi compatible (except the point that FPC will support global generic functions which Delphi does not support) Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Jonas: Thanks, I'll use fpc -iV from now on. But make install still puts an fpc binary in /usr/local/bin that reports 2.7.1 and then overwrites *something* so that a second fpc call reports 2.4.4. Cheers, Andrew Pennebaker www.yellosoft.us On Mon, Oct 31, 2011 at 1:36 PM, Jonas Maebe jonas.ma...@elis.ugent.bewrote: On 31 Oct 2011, at 18:29, Andrew Pennebaker wrote: Jonas, make install does, however, overwrite /usr/local/bin/fpc, which is not a symlink, with an old version during install. Try running fpc -version halfway and after make install. The fpc binary does not have a version number. It reports the version number of the compiler binary that it finds. Jonas PS: -version does not mean print the version. It means enable the e, r, s, i, o and n verbosity switches (but your /etc/fpc.cfg probably contains the -l switch, and the logo includes the version number). -iV is the command line option to make the compiler prints just its version.___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
On 2011-10-20 17:08, Andrew Pennebaker wrote: I'll just wait for v2.6 then. No need to wait, checkout the fixes_2_6 branch, which is currently at version 2.5.1, but will become the v2.6.0 release. This also means you will help test the future 2.6.0 release and catch any possible bugs _before_ the actual release. Lets try and make v2.6.0 a solid release because Trunk looks like it will take damn long before its kind of in a stable state. svn co http://svn.freepascal.org/svn/fpc/branches/fixes_2_6 Regards, - Graeme - -- fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/ ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 20.10.2011 17:08, schrieb Andrew Pennebaker: 2.6, eh? Awesome. I'm using the SVN trunk, but it's not working for me for some reason. I'll just wait for v2.6 then. Didn't you just say that you're using 2.4.4? Trunk is currently 2.7.1. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 19.10.2011 20:08, schrieb Andrew Pennebaker: Right, I tried just {$mode delphi} and just generic, and when both failed I tried them at the same time. Maybe I'm not using a recent enough version? Free Pascal Compiler version 2.4.4 [2011/05/01] for i386 That's why I said trunk. Trunk is the development version of the compiler. You can look for compiler snapshots on the FPC website (look at the Development page). Also you can download the sources of the compiler and compile them using your existing 2.4.4 compiler. Another possibility is to wait until the 2.6 release is released. That will contain the features as well. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
2.6, eh? Awesome. I'm using the SVN trunk, but it's not working for me for some reason. I'll just wait for v2.6 then. Cheers, Andrew Pennebaker www.yellosoft.us On Thu, Oct 20, 2011 at 2:19 AM, Sven Barth pascaldra...@googlemail.comwrote: Am 19.10.2011 20:08, schrieb Andrew Pennebaker: Right, I tried just {$mode delphi} and just generic, and when both failed I tried them at the same time. Maybe I'm not using a recent enough version? Free Pascal Compiler version 2.4.4 [2011/05/01] for i386 That's why I said trunk. Trunk is the development version of the compiler. You can look for compiler snapshots on the FPC website (look at the Development page). Also you can download the sources of the compiler and compile them using your existing 2.4.4 compiler. Another possibility is to wait until the 2.6 release is released. That will contain the features as well. Regards, Sven __**_ fpc-pascal maillist - fpc-pascal@lists.freepascal.**orgfpc-pascal@lists.freepascal.org http://lists.freepascal.org/**mailman/listinfo/fpc-pascalhttp://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
On 10/20/2011 11:08, Andrew Pennebaker wrote: 2.6, eh? Awesome. I'm using the SVN trunk, but it's not working for me for some reason. this is why the latest version of the compiler, 2.4.4 is the one supported ;) I'll just wait for v2.6 then. always another possibility... depending on the waittime, of course ;) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 18.10.2011 21:59, schrieb Jonas Maebe: On 18 Oct 2011, at 21:55, Sven Barth wrote: type TGenArrayT = array of T; // this should work in trunk already function ConcatT(Arr1, Arr2: TGenArrayT): TGenArrayT; 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; This implementation will result in crashes if T is a reference-counted type. Right... I tend to forget about these... what would the correct way to copy an array of ref counted types? E.g. an array of string? Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 18.10.2011 23:08, schrieb Andrew Pennebaker: 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 TArrayT = 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. You either need to add {$mode delphi} between unit Paycheck; and interface or you need to write it like this (though I haven't tested it): type generic TArrayT = array of T; Regards, Sven PS: It's more polite to use the first name when addressing persons in a mailing list. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
In our previous episode, Sven Barth said: This implementation will result in crashes if T is a reference-counted type. Right... I tend to forget about these... what would the correct way to copy an array of ref counted types? E.g. an array of string? copy () ? :-) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Sven, I added the {$mode delphi} macro and prefaced each type with the generic specification. I'm still getting errors. paycheck.pas: unit Paycheck; {$mode delphi} interface type generic TArrayT = array of T; generic TFnT = function() : T; ... Trace: fpc example.pas Compiling example.pas Compiling paycheck.pas paycheck.pas(5,32) Error: Identifier not found T paycheck.pas(5,32) Error: Error in type definition paycheck.pas(6,2) Error: This type can't be a generic paycheck.pas(6,33) Error: Identifier not found T paycheck.pas(7,1) Error: This type can't be a generic paycheck.pas(7,25) Fatal: Syntax error, ; expected but found Fatal: Compilation aborted Cheers, Andrew Pennebaker www.yellosoft.us On Wed, Oct 19, 2011 at 2:28 AM, Sven Barth pascaldra...@googlemail.comwrote: Am 18.10.2011 23:08, schrieb Andrew Pennebaker: 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 TArrayT = 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. You either need to add {$mode delphi} between unit Paycheck; and interface or you need to write it like this (though I haven't tested it): type generic TArrayT = array of T; Regards, Sven PS: It's more polite to use the first name when addressing persons in a mailing list. __**_ fpc-pascal maillist - fpc-pascal@lists.freepascal.**orgfpc-pascal@lists.freepascal.org http://lists.freepascal.org/**mailman/listinfo/fpc-pascalhttp://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
On 19 Oct 2011, at 09:59, Marco van de Voort wrote: In our previous episode, Sven Barth said: This implementation will result in crashes if T is a reference- counted type. Right... I tend to forget about these... what would the correct way to copy an array of ref counted types? E.g. an array of string? For-loops. copy () ? :-) copy() cannot be used to concatenate two arrays, because it is a function that returns a new array with contantes of (a potentially sub- array of) the original array. Jonas ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 19.10.2011 09:59, schrieb Marco van de Voort: In our previous episode, Sven Barth said: This implementation will result in crashes if T is a reference-counted type. Right... I tend to forget about these... what would the correct way to copy an array of ref counted types? E.g. an array of string? copy () ? :-) I thought about copy, too, but how would you implement a generic concat using copy (or even just an array of String one)? Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 19.10.2011 10:01, schrieb Andrew Pennebaker: Sven, I added the {$mode delphi} macro and prefaced each type with the generic specification. I'm still getting errors. Either add {$mode delphi} XOR generic E.g. Solution 1: unit Foo; interface type generic TGenArrayT = array of T; ... Solution 2: unit Foo; {$mode delphi} interface type TGenArrayT = array of T; I just tested. Both work. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
In our previous episode, Jonas Maebe said: Right... I tend to forget about these... what would the correct way to copy an array of ref counted types? E.g. an array of string? For-loops. copy () ? :-) copy() cannot be used to concatenate two arrays, because it is a function that returns a new array with contantes of (a potentially sub- array of) the original array. True. I only reacted on the last bit though. Create a deep copy. Not the application which copies to a certain element number. There is no procedure for that. There is a procedure to do it the other way around though (get sub array from array) called slice. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 19.10.2011 10:27, schrieb Jonas Maebe: On 19 Oct 2011, at 09:59, Marco van de Voort wrote: In our previous episode, Sven Barth said: This implementation will result in crashes if T is a reference-counted type. Right... I tend to forget about these... what would the correct way to copy an array of ref counted types? E.g. an array of string? For-loops. *sigh* For-loops it is then... copy () ? :-) copy() cannot be used to concatenate two arrays, because it is a function that returns a new array with contantes of (a potentially sub-array of) the original array. That's what I remembered about copy as well. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
In our previous episode, Sven Barth said: Right... I tend to forget about these... what would the correct way to copy an array of ref counted types? E.g. an array of string? copy () ? :-) I thought about copy, too, but how would you implement a generic concat using copy (or even just an array of String one)? (as said I only reacted on the other bit). Not without creating a compiler magic function that does it for a refcounted types as opposite to slice(). But then you start down a slippery slope trying to create a list based language, and LISP already has been invented :-) ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Right, I tried just {$mode delphi} and just generic, and when both failed I tried them at the same time. Maybe I'm not using a recent enough version? Free Pascal Compiler version 2.4.4 [2011/05/01] for i386 Cheers, Andrew Pennebaker www.yellosoft.us On Wed, Oct 19, 2011 at 4:34 AM, Sven Barth pascaldra...@googlemail.comwrote: Am 19.10.2011 10:01, schrieb Andrew Pennebaker: Sven, I added the {$mode delphi} macro and prefaced each type with the generic specification. I'm still getting errors. Either add {$mode delphi} XOR generic E.g. Solution 1: unit Foo; interface type generic TGenArrayT = array of T; ... Solution 2: unit Foo; {$mode delphi} interface type TGenArrayT = array of T; I just tested. Both work. Regards, Sven __**_ fpc-pascal maillist - fpc-pascal@lists.freepascal.**orgfpc-pascal@lists.freepascal.org http://lists.freepascal.org/**mailman/listinfo/fpc-pascalhttp://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 19.10.2011 10:49, schrieb Sven Barth: Am 19.10.2011 10:27, schrieb Jonas Maebe: On 19 Oct 2011, at 09:59, Marco van de Voort wrote: In our previous episode, Sven Barth said: This implementation will result in crashes if T is a reference-counted type. Right... I tend to forget about these... what would the correct way to copy an array of ref counted types? E.g. an array of string? For-loops. *sigh* For-loops it is then... Compared with the affort for ref. counting this is negliable imo. Modern processors don't perform that bad on a simple loop to copy memory. copy () ? :-) copy() cannot be used to concatenate two arrays, because it is a function that returns a new array with contantes of (a potentially sub-array of) the original array. That's what I remembered about copy as well. Copy does a one level deep copy. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Andrew Pennebaker wrote: thrice :: a - [a] thrice x = [x, x, x] I know the answer involves generics, but the docs don't offer examples using Free Pascal's built-in generic types. The solution would require generic functions, these are implemented in FPC trunk only. In the latest release (2.4.4) the result you want can be achieved with overloading and some copy-paste (that can be avoided using include files). See attached code for an example. However note that it does not work properly for class instances. Since they are basically pointers the output would be three pointers to the same class instance. AFAIK there is no way in FPC (and Delphi) to deep-copy arbitrary class instance because TObject does not force us to define copy constructors. program project1; uses Classes; {$mode delphi} type TIntegerArray = array of Integer; TStringArray = array of String; function Thrice(AValue: Integer): TIntegerArray; overload; var I: Integer; begin SetLength(Result, 3); for I := 0 to 2 do Result[I] := AValue; end; function Thrice(const AValue: String): TStringArray; overload; var I: Integer; begin SetLength(Result, 3); for I := 0 to 2 do Result[I] := AValue; end; var I: Integer; Thrice5: TIntegerArray; ThriceHello: TStringArray; ThriceWorld: TStringList; begin Thrice5 := Thrice(5); for I := 0 to High(Thrice5) do Write(Thrice5[I], ' '); WriteLn(); ThriceHello := Thrice('hello'); for I := 0 to High(ThriceHello) do Write(ThriceHello[I], ' '); end. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Am 18.10.2011 10:52, schrieb Vladimir Zhirov: The solution would require generic functions, these are implemented in FPC trunk only. Generic functions are NOT implemented in trunk (at least as far as I know...). Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Sven Barth wrote: Generic functions are NOT implemented in trunk (at least as far as I know...). Ouch, sorry. I read about generic procedural types at New features trunk wiki page and thought it was what OP need. Andrew, I apologize for misinformation and thanks Sven for correcting me. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Thrice is designed to work for *any* array type, e.g. arrays of arrays of arrays of bytes. Even if I hardcoded several thousand possible types, Thrice wouldn't work for custom user types. If you do find a way to make this work, please let me know. Cheers, Andrew Pennebaker www.yellosoft.us On Tue, Oct 18, 2011 at 5:39 AM, Vladimir Zhirov vvzh.li...@gmail.comwrote: Sven Barth wrote: Generic functions are NOT implemented in trunk (at least as far as I know...). Ouch, sorry. I read about generic procedural types at New features trunk wiki page and thought it was what OP need. Andrew, I apologize for misinformation and thanks Sven for correcting me. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
In particular, if anyone knows a way to implement a general concatenation function Concat(Arr1, Arr2), let me know. Cheers, Andrew Pennebaker www.yellosoft.us On Tue, Oct 18, 2011 at 1:59 PM, Andrew Pennebaker andrew.penneba...@gmail.com wrote: Thrice is designed to work for *any* array type, e.g. arrays of arrays of arrays of bytes. Even if I hardcoded several thousand possible types, Thrice wouldn't work for custom user types. If you do find a way to make this work, please let me know. Cheers, Andrew Pennebaker www.yellosoft.us On Tue, Oct 18, 2011 at 5:39 AM, Vladimir Zhirov vvzh.li...@gmail.comwrote: Sven Barth wrote: Generic functions are NOT implemented in trunk (at least as far as I know...). Ouch, sorry. I read about generic procedural types at New features trunk wiki page and thought it was what OP need. Andrew, I apologize for misinformation and thanks Sven for correcting me. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
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. More generally, concatenating arrays is an operation that is seldom done, because a) it's slow, especially once the arrays get to a certain size (lots of data copying, memory allocation operations) b) it leads to memory fragmentation (freeing the old arrays, allocating a new one) Pascal has a separate string type to optimize one common case where concatenating arrays is often required. In other cases, people generally use some form of list structure (generic or not) in case lots of insertions/deletions/concatenations are required. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
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 TGenArrayT = array of T; // this should work in trunk already function ConcatT(Arr1, Arr2: TGenArrayT): TGenArrayT; 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 := ConcatInteger(arr1, arr2); ... end. === source end === (tested using a non generic integer version) Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
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 TArrayT = 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.comwrote: 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 TGenArrayT = array of T; // this should work in trunk already function ConcatT(Arr1, Arr2: TGenArrayT): TGenArrayT; 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 := ConcatInteger(arr1, arr2); ... end. === source end === (tested using a non generic integer version) Regards, Sven __**_ fpc-pascal maillist - fpc-pascal@lists.freepascal.**orgfpc-pascal@lists.freepascal.org http://lists.freepascal.org/**mailman/listinfo/fpc-pascalhttp://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] How can I implement thrice in Free Pascal?
Haskell lets you define functions like thrice, which accepts an element of type a and returns a list of the element repeated three times, for any data type a. thrice :: a - [a] thrice x = [x, x, x] I know the answer involves generics, but the docs don't offer examples using Free Pascal's built-in generic types. Cheers, Andrew Pennebaker www.yellosoft.us ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
In our previous episode, Andrew Pennebaker said: thrice :: a - [a] thrice x = [x, x, x] I know the answer involves generics, but the docs don't offer examples using Free Pascal's built-in generic types. There is no built in list type, generic or not, and no way to define new operators. All list and collection types are library. I see no way this could work. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] How can I implement thrice in Free Pascal?
Can this be done with arrays? I didn't mean to be too specific; I'd be happy with any generic collection that could do this. Cheers, Andrew Pennebaker www.yellosoft.us On Mon, Oct 17, 2011 at 6:08 PM, Marco van de Voort mar...@stack.nl wrote: In our previous episode, Andrew Pennebaker said: thrice :: a - [a] thrice x = [x, x, x] I know the answer involves generics, but the docs don't offer examples using Free Pascal's built-in generic types. There is no built in list type, generic or not, and no way to define new operators. All list and collection types are library. I see no way this could work. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal