Allow use of [] for lists and arrays

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Allow use of [] for lists and arrays

Post 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
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Post by milan1612 »

That would really increase readability,
but the old syntax should stay valid, too (source compatibility)
Windows 7 & PureBasic 4.4
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post 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?
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post 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
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post by #NULL »

but then the static arrays in structures are messed.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

the macro does not work...
I tested it, surely that was my first idea... ;)
oh... and have a nice day.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Post 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 :)
Seymour Clufley
Addict
Addict
Posts: 1264
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

+1
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: Allow use of [] for lists and arrays

Post 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
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
AND51
Addict
Addict
Posts: 1040
Joined: Sun Oct 15, 2006 8:56 pm
Location: Germany
Contact:

Re: Allow use of [] for lists and arrays

Post 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.
PB 4.30

Code: Select all

onErrorGoto(?Fred)
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Re: Allow use of [] for lists and arrays

Post 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...
oh... and have a nice day.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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 :!:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Re: Allow use of [] for lists and arrays

Post 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 ?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
milan1612
Addict
Addict
Posts: 894
Joined: Thu Apr 05, 2007 12:15 am
Location: Nuremberg, Germany
Contact:

Re: Allow use of [] for lists and arrays

Post 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...
Windows 7 & PureBasic 4.4
Post Reply