Prefill Array

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
jamirokwai
Enthusiast
Enthusiast
Posts: 772
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Prefill Array

Post 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 :-)
Last edited by jamirokwai on Mon Nov 08, 2010 3:22 pm, edited 1 time in total.
Regards,
JamiroKwai
User avatar
STARGÅTE
Addict
Addict
Posts: 2090
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Prefill Array

Post 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"
:?
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 moreTypeface - Sprite-based font include/module
jamirokwai
Enthusiast
Enthusiast
Posts: 772
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Prefill Array

Post by jamirokwai »

Hi STARGÅTE,

please reread my post...
Regards,
JamiroKwai
User avatar
skywalk
Addict
Addict
Posts: 4003
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Prefill Array

Post by skywalk »

I agree this is not Basic syntax.
But we do have Read - Data - Restore and/or Macros to simplify the function. :wink:
jamirokwai
Enthusiast
Enthusiast
Posts: 772
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Prefill Array

Post 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.
Regards,
JamiroKwai
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Prefill Array

Post 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.
User avatar
skywalk
Addict
Addict
Posts: 4003
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Prefill Array

Post 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. :(
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Prefill Array

Post 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
jamirokwai
Enthusiast
Enthusiast
Posts: 772
Joined: Tue May 20, 2008 2:12 am
Location: Cologne, Germany
Contact:

Re: Prefill Array

Post 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!
Regards,
JamiroKwai
User avatar
STARGÅTE
Addict
Addict
Posts: 2090
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Prefill Array

Post 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
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 moreTypeface - Sprite-based font include/module
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: Prefill Array

Post 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.
The best preparation for tomorrow is doing your best today.
User avatar
STARGÅTE
Addict
Addict
Posts: 2090
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Prefill Array

Post by STARGÅTE »

@KJ67:

+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 moreTypeface - Sprite-based font include/module
User avatar
TomS
Enthusiast
Enthusiast
Posts: 342
Joined: Sun Mar 18, 2007 2:26 pm
Location: Munich, Germany

Re: Prefill Array

Post 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
Post Reply