Prefill Array
-
- Enthusiast
- Posts: 772
- Joined: Tue May 20, 2008 2:12 am
- Location: Cologne, Germany
- Contact:
Prefill Array
Hiya,
my suggestion is to add a prefill-mechanism for arrays, like this:
Dim Test.s(2) = ("AA","BB","CC)
Instead of having to use:
Dim Test.s(2)
Test(0) = "AA"
Test(1) = "BB"
Test(1) = "CC"
(EDIT: added "having to use" to clarify
my suggestion is to add a prefill-mechanism for arrays, like this:
Dim Test.s(2) = ("AA","BB","CC)
Instead of having to use:
Dim Test.s(2)
Test(0) = "AA"
Test(1) = "BB"
Test(1) = "CC"
(EDIT: added "having to use" to clarify
Last edited by jamirokwai on Mon Nov 08, 2010 3:22 pm, edited 1 time in total.
Regards,
JamiroKwai
JamiroKwai
Re: Prefill Array
Dim Test.s(2) = ("AA","BB","CC")
No Basic Syntax!
Use:
Dim Test.s(2) : Test(0) = "AA" : Test(1) = "BB" : Test(2) = "CC"
No Basic Syntax!
Use:
Dim Test.s(2) : Test(0) = "AA" : Test(1) = "BB" : Test(2) = "CC"
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
-
- Enthusiast
- Posts: 772
- Joined: Tue May 20, 2008 2:12 am
- Location: Cologne, Germany
- Contact:
Re: Prefill Array
I agree this is not Basic syntax.
But we do have Read - Data - Restore and/or Macros to simplify the function.
But we do have Read - Data - Restore and/or Macros to simplify the function.
-
- Enthusiast
- Posts: 772
- Joined: Tue May 20, 2008 2:12 am
- Location: Cologne, Germany
- Contact:
Re: Prefill Array
Hi,
so it's not basic syntax, agreed
Stargate, I misinterpreted your comment.
Nontheless, having a prefilled Array without Read/DataSection would make some things easier.
so it's not basic syntax, agreed
Stargate, I misinterpreted your comment.
Nontheless, having a prefilled Array without Read/DataSection would make some things easier.
Regards,
JamiroKwai
JamiroKwai
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Prefill Array
Omiting "Then" after "If" is no classic BASIC syntax, too.STARGÅTE wrote:Dim Test.s(2) = ("AA","BB","CC")
No Basic Syntax!
And there is no official standard, that tells us what is BASIC syntax and what isn't.
The main difference is, that jamirokwai's proposal is much better readable.STARGÅTE wrote:Use:
Dim Test.s(2) : Test(0) = "AA" : Test(1) = "BB" : Test(2) = "CC"
It also requires less typing.
Regards, Little John
PS: One of the next versions of my pre-processor LPP will allow to use this syntax.
I have planned this some time ago, but am just busy with other projects ATM.
Re: Prefill Array
Don't get me wrong, I welcome the "Basic" enhancements in PureBasic, but what do you do for multi-dimensional arrays?
This can get less readable in a hurry.
Code: Select all
Dim Test.s(1,2) = ("AA","BB","CC":"DD","EE","FF")
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Prefill Array
My pre-processor probably will only support one-dimensional arrays.
Generally speaking, the programming language Euphoria (now free and open source) shows how this can be handled (IMHO) elegantly with arbitrary dimensions. Your example could look e.g. like this:
or, if line continuation is possible,
Regards, Little John
Generally speaking, the programming language Euphoria (now free and open source) shows how this can be handled (IMHO) elegantly with arbitrary dimensions. Your example could look e.g. like this:
Code: Select all
Dim Test.s(1,2) = {{"AA","BB","CC"},{"DD","EE","FF"}}
Code: Select all
Dim Test.s(1,2) = { _
{"AA","BB","CC"}, _
{"DD","EE","FF"} _
}
-
- Enthusiast
- Posts: 772
- Joined: Tue May 20, 2008 2:12 am
- Location: Cologne, Germany
- Contact:
Re: Prefill Array
Now, that is a great idea, I think!Little John wrote:My pre-processor probably will only support one-dimensional arrays.
Generally speaking, the programming language Euphoria (now free and open source) shows how this can be handled (IMHO) elegantly with arbitrary dimensions. Your example could look e.g. like this:
or, if line continuation is possible,Code: Select all
Dim Test.s(1,2) = {{"AA","BB","CC"},{"DD","EE","FF"}}
Regards, Little JohnCode: Select all
Dim Test.s(1,2) = { _ {"AA","BB","CC"}, _ {"DD","EE","FF"} _ }
Fits perfectly for hard-coded data!
Regards,
JamiroKwai
JamiroKwai
Re: Prefill Array
And for LinkedLists:
Code: Select all
NewList Test.s() = {"AA","BB","CC"}
Code: Select all
NewMap Test.s() = {"Key1":"AA","Key2":"BB","Key3":"CC"}
Code: Select all
Structure Test
Long.l
String.s
Array Field.b(3)
EndStructure
Test.Test = {123,"Text",{1,2,3,4}}
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Prefill Array
Personally I would much rather see a update in the DataSection.
This would better fit my needs, still keep a similar structure and at the same time give a fast and simple way to fill complicated structures.
Code: Select all
Structure XYZ
A.i
B.f
C.s
EndStructure
CopyMemory(?MyData, @SomeWhere, MySize)
DataSection
MyData:
Data.XYZ 10, 3.1415, "The Brown fox...."
Data.XYZ 12, 0.0010, ""
EndDataSection
The best preparation for tomorrow is doing your best today.
Re: Prefill Array
@KJ67:
+1
+1
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Prefill Array
PB does not support Multiline statements. That's why it's hard to read.STARGÅTE wrote:
And for LinkedLists:And for Maps:Code: Select all
NewList Test.s() = {"AA","BB","CC"}
And for Structures:Code: Select all
NewMap Test.s() = {"Key1":"AA","Key2":"BB","Key3":"CC"}
Code: Select all
Structure Test Long.l String.s Array Field.b(3) EndStructure Test.Test = {123,"Text",{1,2,3,4}}
But With could be enhanced to work like enumeration with LLs and Maps:
Code: Select all
NewList Test.s()
With Test()
"AA"
"BB"
EndWith
NewMap Test.s()
With Test()
(Key1, "A")
(Key2, "B")
EndWith
NewList Test.POINT()
With Test()
(10, 4)
(35, 95)
(45, 74)
EndWith