Page 1 of 2

Allow use of [] for lists and arrays

Posted: Fri Oct 05, 2007 11:16 am
by Rescator
Allow use of [] for lists and arrays as an alias for (),
improves code readability as procedures and functions and macros can easily be distinguished from arrays and lists.

Example:

Dim MyArray.l[41]
MyArray[0] = 1
MyArray[1] = 2

Example: Multidimensional array

Dim MultiArray.b[NbColumns, NbLines]
MultiArray[10, 20] = 10
MultiArray[20, 30] = 20


Example:

NewList MyList.l[]

AddElement(MyList[])
MyList[] = 10

AddElement(MyList[])
MyList[] = 20

AddElement(MyList[])
MyList[] = 30

ForEach MyList[]
Debug MyList[]
Next

Posted: Fri Oct 05, 2007 11:29 am
by milan1612
That would really increase readability,
but the old syntax should stay valid, too (source compatibility)

Posted: Fri Oct 05, 2007 1:26 pm
by DoubleDutch
Unless Fred & Freak have something else planned for [], then it also gets my vote - but over time get rid of the old syntax?

Posted: Fri Oct 05, 2007 4:33 pm
by Demivec
Rescator wrote:Allow use of [] for lists and arrays as an alias for (),
improves code readability as procedures and functions and macros can easily be distinguished from arrays and lists.
Couldn't this be accomplished easily with 2 macros just as easily?

Code: Select all

Macro [
    (
EndMacro

Macro ]
    )
EndMacro

Posted: Fri Oct 05, 2007 4:40 pm
by #NULL
but then the static arrays in structures are messed.

Posted: Fri Oct 05, 2007 5:35 pm
by Kaeru Gaman
the macro does not work...
I tested it, surely that was my first idea... ;)

Posted: Sat Oct 06, 2007 2:40 am
by Rescator
#NULL wrote:but then the static arrays in structures are messed.
What makes you think that? As it works now macros, procedures and native functions/commands all use () and the compiler can distinguish them internally.

Good point on static arrays in structures but. When would you ever do a

;Not allowed, dynamic array
Structure blah
array.b(4)
EndStructure
Structure blah
array.b()
EndStructure
Structure blah
array()
EndStructure

;Allowed, static array
Structure blah
array.b[4]
EndStructure


? am I missing something or?
I always assumed that the only arrays allowed in structures this way was static ones so I do not see any conflict issues if [] is allowed as an alias for list and dynamic arrays.
As dynamic arrays or lists would never be used/allowed like that anyway right? So the compiler would still be able to distinguish static vs dynamic arrays and lists.

It also kind of makes sense as [] would then be used for lists, dynamic arrays, and obviously static arrays as currently.
And () would be used for procedures, functions, and macros where applicable.

Posted: Sat Oct 06, 2007 10:42 am
by #NULL
i was referring to Demivec's idea with the macro (i didn't know that it doesn't work anyway).
i like your idea in general and i didn't see problems there :)

Posted: Wed Jan 14, 2009 8:43 am
by Seymour Clufley
+1

Re: Allow use of [] for lists and arrays

Posted: Wed Jan 14, 2009 10:11 am
by gnozal
Rescator wrote:... improves code readability as procedures and functions and macros can easily be distinguished from arrays and lists.
Maybe syntax coloring could help.
Image

Re: Allow use of [] for lists and arrays

Posted: Wed Jan 14, 2009 11:07 am
by AND51
Indeed it would increase the readability of a code, but personally, I got used to ( and ).
I don't like [ and ], because the german keyboard layout is very inconvenient:

Code: Select all

Shift + 8        (
Shift + 9        )

AltGr + 8        [
AltGr + 9        ]
I don't like to use AltGr everytime I want to type the name of an array or list, Shift is better.

Re: Allow use of [] for lists and arrays

Posted: Wed Jan 14, 2009 11:45 am
by Kaeru Gaman
Rescator wrote:Allow use of [] for lists and arrays as an alias for ()
so, alternatively as Rescator suggested, it would be ok, tho I don't see much advantage, but it's just a matter of taste.
as long I can stick to %28 and %29, I don't mind any aliases...

Anyways, some more dynamic syntax coloring as gnozal suggested maybe the better idea,
but that is an IDE change no Compiler change...

Posted: Wed Jan 14, 2009 4:28 pm
by Psychophanta
DoubleDutch wrote:Unless Fred & Freak have something else planned for [], then it also gets my vote - but over time get rid of the old syntax?
Yes, i say just the same :!:

Re: Allow use of [] for lists and arrays

Posted: Wed Jan 14, 2009 4:47 pm
by gnozal
AND51 wrote:I don't like to use AltGr everytime I want to type the name of an array or list, Shift is better.
+1
Same on french keyboards, probably on most non english keyboards ?

Re: Allow use of [] for lists and arrays

Posted: Wed Jan 14, 2009 5:18 pm
by milan1612
gnozal wrote:
AND51 wrote:I don't like to use AltGr everytime I want to type the name of an array or list, Shift is better.
+1
Same on french keyboards, probably on most non english keyboards ?
That's why I bought a US layout keyboard, it's less hassle to enter
the German Umlauts by typing in a combination of keys once
in a while than to ruin your wrist over the time with AltGr + ... :lol:

+1 to the request btw...