Page 1 of 1

Prefill Array

Posted: Mon Nov 08, 2010 2:37 pm
by jamirokwai
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 :-)

Re: Prefill Array

Posted: Mon Nov 08, 2010 3:16 pm
by STARGÅTE
Dim Test.s(2) = ("AA","BB","CC")

No Basic Syntax!

Use:
Dim Test.s(2) : Test(0) = "AA" : Test(1) = "BB" : Test(2) = "CC"
:?

Re: Prefill Array

Posted: Mon Nov 08, 2010 3:20 pm
by jamirokwai
Hi STARGÅTE,

please reread my post...

Re: Prefill Array

Posted: Mon Nov 08, 2010 4:05 pm
by skywalk
I agree this is not Basic syntax.
But we do have Read - Data - Restore and/or Macros to simplify the function. :wink:

Re: Prefill Array

Posted: Mon Nov 08, 2010 4:17 pm
by jamirokwai
Hi,

so it's not basic syntax, agreed 8)
Stargate, I misinterpreted your comment.

Nontheless, having a prefilled Array without Read/DataSection would make some things easier.

Re: Prefill Array

Posted: Mon Nov 08, 2010 6:07 pm
by Little John
STARGÅTE wrote:Dim Test.s(2) = ("AA","BB","CC")

No Basic Syntax!
Omiting "Then" after "If" is no classic BASIC syntax, too.
And there is no official standard, that tells us what is BASIC syntax and what isn't.
STARGÅTE wrote:Use:
Dim Test.s(2) : Test(0) = "AA" : Test(1) = "BB" : Test(2) = "CC"
:?
The main difference is, that jamirokwai's proposal is much better readable.
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

Posted: Mon Nov 08, 2010 7:54 pm
by skywalk
Don't get me wrong, I welcome the "Basic" enhancements in PureBasic, but what do you do for multi-dimensional arrays?

Code: Select all

Dim Test.s(1,2) = ("AA","BB","CC":"DD","EE","FF")
This can get less readable in a hurry. :(

Re: Prefill Array

Posted: Mon Nov 08, 2010 8:49 pm
by Little John
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:

Code: Select all

Dim Test.s(1,2) = {{"AA","BB","CC"},{"DD","EE","FF"}}
or, if line continuation is possible,

Code: Select all

Dim Test.s(1,2) = { _
                   {"AA","BB","CC"}, _
                   {"DD","EE","FF"} _
                  }
Regards, Little John

Re: Prefill Array

Posted: Mon Nov 08, 2010 11:26 pm
by jamirokwai
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:

Code: Select all

Dim Test.s(1,2) = {{"AA","BB","CC"},{"DD","EE","FF"}}
or, if line continuation is possible,

Code: Select all

Dim Test.s(1,2) = { _
                   {"AA","BB","CC"}, _
                   {"DD","EE","FF"} _
                  }
Regards, Little John
Now, that is a great idea, I think!
Fits perfectly for hard-coded data!

Re: Prefill Array

Posted: Mon Nov 08, 2010 11:41 pm
by STARGÅTE
:|

And for LinkedLists:

Code: Select all

NewList Test.s() = {"AA","BB","CC"}
And for Maps:

Code: Select all

NewMap Test.s() = {"Key1":"AA","Key2":"BB","Key3":"CC"}
And for Structures:

Code: Select all

Structure Test
  Long.l
  String.s
  Array Field.b(3)
EndStructure
Test.Test = {123,"Text",{1,2,3,4}}
very useful :lol: , not really, is much harder to read later

Re: Prefill Array

Posted: Tue Nov 09, 2010 7:42 am
by KJ67
Personally I would much rather see a update in the DataSection.

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
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.

Re: Prefill Array

Posted: Tue Nov 09, 2010 9:01 am
by STARGÅTE
@KJ67:

+1

Re: Prefill Array

Posted: Tue Nov 09, 2010 12:25 pm
by TomS
STARGÅTE wrote::|

And for LinkedLists:

Code: Select all

NewList Test.s() = {"AA","BB","CC"}
And for Maps:

Code: Select all

NewMap Test.s() = {"Key1":"AA","Key2":"BB","Key3":"CC"}
And for Structures:

Code: Select all

Structure Test
  Long.l
  String.s
  Array Field.b(3)
EndStructure
Test.Test = {123,"Text",{1,2,3,4}}
PB does not support Multiline statements. That's why it's hard to read.

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