[Lazarus] const array syntax

John jszcmpr at netspace.net.au
Wed Jan 13 23:59:20 CET 2010


Doug Chamberlin wrote:
> Duncan Parsons wrote:
>> Must confess, I feel "arr:[0..end] of " makes more sense to me than 
>> use of "var" or "..]" The latter suggests something forgotten or a typo.
>
> I agree that just leaving out the ending limit is against the spirit 
> of Pascal.
+1
>
> I can live with the syntax of MyArray:[0..var] or MyArray:[0..end] but 
> I'd prefer a syntax that does not use a word, such as MyArray:[0..*] 
> or MyArray:[0..?]. That way there is no confusion about a user-defined 
> word and the use of the currently reserved words is not changed. In 
> other words, this is a situation that is exactly why we have 
> punctuation and not the cobol-ish "Declare MyArray to be from 0 to end 
> of TSomeType"!
>
All right, every one is having a go at this, so my suggestion is:

Option 1:

array(0..Some_constant   key_word_or_directive ) of ....

So the Key word or compiler directive tells the compiler to create and 
set "Some_constant" to the number of elements, rather than to expect to 
find the constant existing already.  (Or, if it suits the complier 
better, require the constant to be defined, just overwrite the value)

The point being that you have a definite instruction to set the value of 
the bounds, rather than just leaving something out, and you have a 
constant to use as an upper bound.

Option 2:

As it is just a convenience feature, do it in the IDE.  Given

Some_constant = 0;
array(0..Some_constant) of .....

Then have a code completion feature to reset Some_constant to the 
correct value.  (Maybe even write the Some_constant declaration if it 
doesn't exist, for that matter.)

This has the disadvantage that you have to use the Lazarus IDE (but 
then, why wouldn't you ?), and the major advantage that no one has to 
stuff around with the compiler at all - or it's specification or 
documentation, for that matter.  Much better to load conveniences into 
the IDE and keep the compiler "clean".

Just my 2c worth.

John Sunderland





More information about the Lazarus mailing list