Re: [fpc-pascal] Const Array Length (was Dynamic Array Length)
Rainer Stratmann wrote: Am Saturday 02 January 2010 16:34:57 schrieb JoshyFun: a: array[1..] or string = ('aaa', 'bbb', 'ccc'); That would be perfect. Then you can automatically calculate the amount: amax = sizeof( a ) div sizeof( a[ 1 ] ); If this syntax was in Pascal, would you use High(a)-Low(a)+1 rather than sizeof()? ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Const Array Length (was Dynamic Array Length)
On 03 Jan 2010, at 13:03, Frank Peelo wrote: Rainer Stratmann wrote: Am Saturday 02 January 2010 16:34:57 schrieb JoshyFun: a: array[1..] or string = ('aaa', 'bbb', 'ccc'); That would be perfect. Then you can automatically calculate the amount: amax = sizeof( a ) div sizeof( a[ 1 ] ); If this syntax was in Pascal, would you use High(a)-Low(a)+1 rather than sizeof()? Even easier is length(a) in this case. As a bonus, low/high/length won't break when you use a dynamic or open array, while C-style sizeof calculations will break in such cases. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Const Array Length (was Dynamic Array Length)
Am Sunday 03 January 2010 13:03:37 schrieb Frank Peelo: Rainer Stratmann wrote: Am Saturday 02 January 2010 16:34:57 schrieb JoshyFun: a: array[1..] or string = ('aaa', 'bbb', 'ccc'); That would be perfect. Then you can automatically calculate the amount: amax = sizeof( a ) div sizeof( a[ 1 ] ); If this syntax was in Pascal, would you use High(a)-Low(a)+1 rather than sizeof()? I think high and low has an other meaning. I C this works. There I have the idea from. Best regards, Rainer ___ 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] Const Array Length (was Dynamic Array Length)
On 03 Jan 2010, at 13:12, Rainer Stratmann wrote: Am Sunday 03 January 2010 13:03:37 schrieb Frank Peelo: Rainer Stratmann wrote: Then you can automatically calculate the amount: amax = sizeof( a ) div sizeof( a[ 1 ] ); If this syntax was in Pascal, would you use High(a)-Low(a)+1 rather than sizeof()? I think high and low has an other meaning. You might want to read the manual: http://www.freepascal.org/docs-html/ref/refsu14.html I C this works. There I have the idea from. Pascal has better ways to deal with array bounds. Jonas___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Const Array Length (was Dynamic Array Length)
Am Sunday 03 January 2010 13:19:39 schrieb Jonas Maebe: On 03 Jan 2010, at 13:12, Rainer Stratmann wrote: Am Sunday 03 January 2010 13:03:37 schrieb Frank Peelo: Rainer Stratmann wrote: Then you can automatically calculate the amount: amax = sizeof( a ) div sizeof( a[ 1 ] ); If this syntax was in Pascal, would you use High(a)-Low(a)+1 rather than sizeof()? I think high and low has an other meaning. You might want to read the manual: http://www.freepascal.org/docs-html/ref/refsu14.html Ok, I read it before. I C this works. There I have the idea from. Pascal has better ways to deal with array bounds. But at this moment it is not possible to make a const array with auto calculated range ( [ 1..] ). It would be easy to implement, I think. 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] Const Array Length (was Dynamic Array Length)
Rainer Stratmann schrieb: Pascal has better ways to deal with array bounds. But at this moment it is not possible to make a const array with auto calculated range ( [ 1..] ). It would be easy to implement, I think. But these things are not related. Calculating array bounds should not be dependend on the array type (and its declaration). When determining the number of elements in an array I therefore also think that sizeof() or High()-Low()+1 would be the best. And that should also be the case for constant arrays with auto size calculation (if someone finds the time to implement it and if it can be done easily). ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
[fpc-pascal] Const Array Length (was Dynamic Array Length)
On torstai, 31. joulukuuta 2009 16:33:50 Anthony Walter wrote: No, the compiler will not fill in the array length based on your element list. It does compute the length while compiling and *you* need to match it in your declaration. In most cases it would be better if the compiler counted the number of elements. Only in few cases the programmer really wants to limit the number to some predefined value. The currently used syntax for const array is: const a: array[1..3] of string = ('aaa', 'bbb', 'ccc'); Already years ago I proposed the following syntax in Delphi mailing list: const a: array of string = ('aaa', 'bbb', 'ccc'); It looks like a dynamic array, but obviously is not dynamic because it is constant. :-) The indexing would start from 0 like with dynamic arrays. It would not break the existing syntax and would be very intuitive. In the current syntax if I add one element, I need to change the upper bound number, too, which feels really stupid. In the proposed syntax I would not need to change any bounds. In Delphi mailing list the answers were basically like: The syntax is perfect now. Keep on changing the bounds. How about FPC? This change would not be Delphi compatible apparently. Regards, Juha Manninen ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Const Array Length (was Dynamic Array Length)
Hello FPC-Pascal, Saturday, January 2, 2010, 4:01:35 PM, you wrote: JM In most cases it would be better if the compiler counted the number of JM elements. Only in few cases the programmer really wants to limit the number to JM some predefined value. JM The currently used syntax for const array is: JM const JM a: array[1..3] of string = ('aaa', 'bbb', 'ccc'); JM Already years ago I proposed the following syntax in Delphi mailing list: JM const JM a: array of string = ('aaa', 'bbb', 'ccc'); From my point of view that's a dynamic array, if it looks like a dynamic array ir should be a dynamic array. Other pascals uses something like: a: array[1..] or string = ('aaa', 'bbb', 'ccc'); or a: array[..] or string = ('aaa', 'bbb', 'ccc'); I think that: a: array[..n] or string = ('aaa', 'bbb', 'ccc'); is not allowed. -- Best regards, JoshyFun ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Const Array Length (was Dynamic Array Length)
Juha Manninen schrieb: const a: array of string = ('aaa', 'bbb', 'ccc'); It looks like a dynamic array, but obviously is not dynamic because it is constant. :-) The indexing would start from 0 like with dynamic arrays. It would not break the existing syntax and would be very intuitive. I would appreciate such a change. I often have static lists in my programs, which need to be changed from time to time. Ok, it's not a big deal to change the upper border (and if I forget it I am reminded ;-)), but it would make life easier a bit if it could be automatic and it looks like an intuitive enhancement in the spirit of pascal. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Const Array Length (was Dynamic Array Length)
On lauantai, 2. tammikuuta 2010 17:34:57 JoshyFun wrote: From my point of view that's a dynamic array, if it looks like a dynamic array ir should be a dynamic array. It can't be dynamic because it is under const section :-) Other pascals uses something like: a: array[1..] or string = ('aaa', 'bbb', 'ccc'); or a: array[..] or string = ('aaa', 'bbb', 'ccc'); I have used only TP and Delphi and now some FPC. I didn't know of that syntax but it looks perfect. The main point is that the programmer doesn't need to calculate elements and set bounds. IMO it should be implemented in FPC. Regards, Juha Manninen ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Const Array Length (was Dynamic Array Length)
Am Saturday 02 January 2010 16:34:57 schrieb JoshyFun: a: array[1..] or string = ('aaa', 'bbb', 'ccc'); That would be perfect. Then you can automatically calculate the amount: amax = sizeof( a ) div sizeof( a[ 1 ] ); And you are free to set the number of the first array, in this case 1. Like Jürgen says it is not a big deal to change the upper border, but it would make life easier a bit. It would be a userfriendly bit. May be people from delphi switch to fpc then... (ok not only for this reason, but if there are another useful bits...) Happy new year. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] Const Array Length (was Dynamic Array Length)
Jürgen Hestermann schreef: Juha Manninen schrieb: const a: array of string = ('aaa', 'bbb', 'ccc'); It looks like a dynamic array, but obviously is not dynamic because it is constant. :-) The indexing would start from 0 like with dynamic arrays. It would not break the existing syntax and would be very intuitive. I would appreciate such a change. I often have static lists in my programs, which need to be changed from time to time. I suggest you add an entry on http://wiki.lazarus.freepascal.org/Bounties#Multi-platform_bounties, so we know how much you would appreciate it. Vincent ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal