It is currently Mon Dec 17, 2018 11:14 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Extended array definition
PostPosted: Wed May 11, 2016 10:54 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Oct 26, 2015 2:55 am
Posts: 895
Location: UA
Suspect this already was proposed sometime by someone, but at least my thread will be another vote ^^
Would be cool to have some short form of predefining arrays (like variables).

I think something like this is nice:
Code:
; predefined array in short form
Dim Dat.l (8) = 2,5,1,2,3,4,7,7,6


Should be expanded as
Code:
Dim Dat.l (8)
Dat(0) = 2
Dat(1) = 5
Dat(2) = 1
Dat(3) = 2
Dat(n) ...
Dat(8) = 6



Close to how "Data" keyword works, working with strings too; for multidimensional/structured arrays should not be applicable.

_________________
Dreamness

Like a copyleft notify: all the source code created by me and posted on Purebasic official forums is free to use and modification in all possible (and several impossible) ways for anyone, without asking my permission


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended array definition
PostPosted: Wed May 11, 2016 11:37 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1603
Location: Uttoxeter, UK
@Lunasole,

Have a look at this post by Little John, it achieves such a definition with a macro using JSON.

http://www.purebasic.fr/english/viewtopic.php?p=453449#p453449

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended array definition
PostPosted: Wed May 11, 2016 11:43 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Feb 04, 2013 5:28 pm
Posts: 332
It was asked so many times... but unfortunately it's still missing.

You can look at all the limited and convoluted contraptions we have to go through instead here

viewtopic.php?f=13&t=60372


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended array definition
PostPosted: Fri May 13, 2016 3:36 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3346
Location: New Zealand
simple work around for arrays of a single type

Code:
Structure Ar   ;generic 1D array itterator
  StructureUnion
    a.a[0]
    b.b[0]
    c.c[0]
    u.u[0]
    w.w[0]
    l.l[0]
    f.f[0]
    i.i[0]
    q.q[0]
    d.d[0]
  EndStructureUnion
  s.s[0]
EndStructure   

Structure MyPoint
  x.i
  y.i
EndStructure   

Structure MyPointAR ;a structured itterator
  e.myPoint[0]
EndStructure   


DataSection   ;datasection can be declared anywhere
QuadArray: 
Data.q 1,2,3,4,5,6
ByteArray:
Data.b 9,8,7,6,5,4
FloatArray:
Data.f 1.1,1.2,1.3,1.4,1.5,1.6
MyPointArray:  ;x,y
Data.i 1,6,2,5,3,4,4,3,5,2,6,1
StringArray:
Data.i @"One",@"Two",@"Three",@"Four",@"Five",@"Six"
EndDataSection

*myarray.AR = ?QuadArray ;set address of typed itterator pointer

For a = 0 To 5
  Debug *myarray\q[a]
Next   
Debug "-----"

*myarray.AR = ?ByteArray

For a = 0 To 5
  Debug *myarray\b[a]
Next   
Debug "-----"

*myarray.AR = ?FloatArray

For a = 0 To 5
  Debug *myarray\f[a]
Next   
Debug "-----"

*mypoint.MyPointAR = ?MyPointArray

For a = 0 To 5
  Debug Str(*mypoint\e[a]\x) + "," + Str(*mypoint\e[a]\y)
Next   
Debug "-----"

*myarray.AR = ?QuadArray

For a = 0 To 5
  *myarray\q[a] = 6-a  ;overwrite it 
Next   

For a = 0 To 5
  Debug *myarray\q[a]
Next   
Debug "-----"

*myarray.AR = ?StringArray

For a = 0 To 5
  Debug *myarray\s[a]
Next   


_________________
Got winter blues?
Enjoy a Caravan Trip into, "The Land of Grey and Pink", wine and punk weed optional!
https://www.youtube.com/watch?v=9hmFzGTxod4


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended array definition
PostPosted: Fri May 13, 2016 12:09 pm 
Offline
Enthusiast
Enthusiast

Joined: Mon Feb 04, 2013 5:28 pm
Posts: 332
Emphasis on simple !

Not to discredit the workarounds, they are all nice ideas in their own way, it's just they are so convoluted, depressing to type and to read later compared to what you should be able to do in the first place.

Just think when you have to initialize simple vectors for points or colors in game or graphic programming.

Would be so nice to be able to do

Code:
Dim vec.f() = (1.0, 2.0, 3.0)

or
Code:
Dim vec.f(2) = (1.0, 2.0, 3.0)


if the precedent is "too difficult" for the compiler

resulting in

debug vec(0) = 1.0
...
debug vec(2) = 3.0


Lunasole wrote:
for multidimensional/structured arrays should not be applicable.


why not ? at least for multidimensional arrays

Code:
Dim mat.f() = (1.0, 2.0, 3.0) (4.0, 5.0, 6.0) (7.0, 8.0, 9.0)  or Dim mat.f() = (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)

or
Code:
Dim mat.f(2,2) = (1.0, 2.0, 3.0) (4.0, 5.0, 6.0) (7.0, 8.0, 9.0) or Dim mat.f(2,2) = (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)


if the precedent is "too difficult" for the compiler

resulting in (row major order)

debug mat(0,0) = 1.0
debug mat(0,1) = 2.0
debug mat(0,2) = 3.0
debug mat(1,0) = 4.0
debug mat(1,1) = 5.0
debug mat(1,2) = 6.0
debug mat(2,0) = 7.0
debug mat(2,1) = 8.0
debug mat(2,2) = 9.0

All the above while keeping the support for the Static keyword to initialize an array only once inside a procedure if possible.

Simple but useful enhancements to the language are much more needed IMO than another library and this one in particular should be extremely easy to add for the predefined data types.


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended array definition
PostPosted: Fri May 13, 2016 8:31 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 1482
Location: Germany
Perhaps with Macro
Code:
EnableExplicit

Macro MyDim(name, size, v0=0, v1=0, v2=0, v3=0, v4=0, v5=0, v6=0, v7=0, v8=0, v9=0, v10=0, v11=0, v12=0, v13=0, v14=0, v15=0, v16=0, v17=0, v18=0, v19=0)
  Dim name(size)
  CompilerIf v0 : name(0) = v0 : CompilerEndIf
  CompilerIf v1 : name(1) = v1 : CompilerEndIf
  CompilerIf v2 : name(2) = v2 : CompilerEndIf
  CompilerIf v3 : name(3) = v3 : CompilerEndIf
  CompilerIf v4 : name(4) = v4 : CompilerEndIf
  CompilerIf v5 : name(5) = v5 : CompilerEndIf
  CompilerIf v6 : name(6) = v6 : CompilerEndIf
  CompilerIf v7 : name(7) = v7 : CompilerEndIf
  CompilerIf v8 : name(8) = v8 : CompilerEndIf
  CompilerIf v9 : name(9) = v9 : CompilerEndIf
  CompilerIf v10 : name(10) = v10 : CompilerEndIf
  CompilerIf v11 : name(11) = v11 : CompilerEndIf
  CompilerIf v12 : name(12) = v12 : CompilerEndIf
  CompilerIf v13 : name(13) = v13 : CompilerEndIf
  CompilerIf v14 : name(14) = v14 : CompilerEndIf
  CompilerIf v15 : name(15) = v15 : CompilerEndIf
  CompilerIf v16 : name(16) = v16 : CompilerEndIf
  CompilerIf v17 : name(17) = v17 : CompilerEndIf
  CompilerIf v18 : name(18) = v18 : CompilerEndIf
  CompilerIf v19 : name(19) = v19 : CompilerEndIf
EndMacro

Global MyDim(daten.f, 3, 200.6, 300.3, 99.1)

Define index
For index = 0 To ArraySize(Daten())
  Debug daten(index)
Next

CallDebugger

No Strings :(

_________________
My Projects OOP-BaseClass / OOP-BaseClassDispatch / Event-Designer /
PB v3.30 / v5.60 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended array definition
PostPosted: Fri May 13, 2016 8:54 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3307
Location: Berlin, Germany
mk-soft wrote:
No Strings :(

This works also with strings: :D
viewtopic.php?p=487965#p487965

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended array definition
PostPosted: Sat May 14, 2016 3:25 am 
Offline
Addict
Addict
User avatar

Joined: Mon Oct 26, 2015 2:55 am
Posts: 895
Location: UA
DontTalkToMe wrote:
why not ? at least for multidimensional arrays

I think it will look dirty for multidimensional arrays. Also they are used much less often than simple arrays.
But generally I'm not against that, just this is secondary and let Fred first do something for plain arrays at least



Btw you said nicely about workarounds. They are OK, but not usable in any case you want or need. There is a big difference between just opening IDE and using one keyword to do something or messing before this with extra code to do the same trivial thing at last.
Surely can also write custom precompiler for more automation, but that brings additional limits and for example makes problems with further code sharing.


> Simple but useful enhancements to the language are much more needed IMO than another library and this one in particular should be extremely easy to add for the predefined data types.

And this is right too, usability (or maybe there is some better word which I can't pick right now^^) is probably main PB advantage (it simply almost has no others against modern languages) and syntax is key part of it. Well, attached libraries are another key part :) But libraries keep growing greatly for last years, syntax evolution -- not, few small changes like string escaping are nice and marking some progress, but still missing lot of trivial stuff implemented in most languages and IDEs years ago.

_________________
Dreamness

Like a copyleft notify: all the source code created by me and posted on Purebasic official forums is free to use and modification in all possible (and several impossible) ways for anyone, without asking my permission


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended array definition
PostPosted: Sat May 14, 2016 11:09 am 
Offline
Enthusiast
Enthusiast

Joined: Mon Feb 04, 2013 5:28 pm
Posts: 332
Lunasole wrote:
Surely can also write custom precompiler for more automation, but that brings additional limits and for example makes problems with further code sharing.


Also PB does not offer anything to help writing a precompiler, see for example the LINE directive in C languages used to get the error on the right line on the pre-processed source file (and so meaningful) instead of the line in the post-processed source file saw by the compiler.

https://gcc.gnu.org/onlinedocs/cpp/Line-Control.html

This also would be trivial to add (should be added tomorrow really), and would help a lot.

A preprocessor has other problems. Just think about debugging. And most of all as you mentioned, your code becomes something else and not PB anymore, so no sharing.

Lunasole wrote:
But libraries keep growing greatly for last years, syntax evolution -- not, few small changes like string escaping are nice and marking some progress, but still missing lot of trivial stuff implemented in most languages and IDEs years ago.


Same here.

Most trivial things could be implemented without fears of breaking something else and would result in a language a lot more comfortable to use. No idea why Fred is not considering these.

Array initialization is just one of them.


Top
 Profile  
Reply with quote  
 Post subject: Re: Extended array definition
PostPosted: Mon Mar 27, 2017 12:13 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Sep 12, 2015 6:55 pm
Posts: 105
Is this going to be finally added ?

I'm too tired to struggle with these things every day. I did it on the side because I was hopeful the language was going to be enhanced just a little but in almost 2 years nothing really happened.

Working with math related stuff in this language is becoming unbearable for me. Too archaic, too limited. This is just the tip of the iceberg but at least this should be added today :|

I understand the error was mine, adoption in the hope of things to come. Bad idea.
There were no milestones announced and no promises about any evolution.
I think it's better if I forget about the experiment and move on.
Cheers.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Exabot [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye