A quick way to load arrays

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

A quick way to load arrays

Post by DoubleDutch »

Instead of...

Code: Select all

SobelH(0)=-1:SobelH(1)=-2:SobelH(2)=-1
SobelH(3)=0:SobelH(4)=0,SobelH(5)=0
SobelH(6)=1:SobelH(7)=2:SobelH(8)=1
(I know it can also be coded with read ... data !)


I'd like something like:

Code: Select all

SobelH(0)=-1,-2,-1,0,0,0,1,2,1
Basically when loading an array, if the comma is used then the original index to the array is incremented by 1 and then next expression is loaded (and so on).

With multidimensional arrays it could go to the next row if the ending has been reached?

It would also be useful for loading string arrays.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Wladek
User
User
Posts: 98
Joined: Mon Feb 23, 2009 4:01 pm
Location: Poland
Contact:

Post by Wladek »

Or like this:

Code: Select all

SobelH(5)={-1,-2,-1,0,0,0,1,2,1}
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

Wladek wrote:Or like this:

Code: Select all

SobelH(5)={-1,-2,-1,0,0,0,1,2,1}
How do you intend on fitting all of those numbers into such a small array? :)

+2 for this! :D
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

The number (5 in that case) should be the starting point of the load, not the size of the array. I don't like the use of the {} brackets, looks too much like C.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Wladek wrote:Or like this:

Code: Select all

SobelH(5)={-1,-2,-1,0,0,0,1,2,1}
I like that but it's starting to look like C. I don't mind tho' but others might. :wink:
--Kale

Image
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

also such a row has to be placed within a DataSection...
if not manually, the compiler has to.

so, why not implementing some automation for filling arrays from DataSections?
but this would not be much change...
oh... and have a nice day.
Wladek
User
User
Posts: 98
Joined: Mon Feb 23, 2009 4:01 pm
Location: Poland
Contact:

Post by Wladek »

5 is not the size of the array.
5 is start to save the array.

We have 3 types of parenthesis:
1. ()
2. {}
3. []
I suggest add one more.:idea:
4. ##
I not insist. :roll:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

# is already used for something else (in macros).
Wladek
User
User
Posts: 98
Joined: Mon Feb 23, 2009 4:01 pm
Location: Poland
Contact:

Post by Wladek »

Oh :oops: , you right
I forgot: #PB_2DDrawing_Default or #PB_Any..............
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Haha, I forgot about those as well.
Nico
Enthusiast
Enthusiast
Posts: 274
Joined: Sun Jan 11, 2004 11:34 am
Location: France

Post by Nico »

With a macro:

Code: Select all

Macro liste(Tableau,chaine)
		count=CountString(chaine,",")
		For b=1 To count+1
			a=b-1
			Texte.s=StringField(chaine,b,",")
			Texte=ReplaceString(Texte,"'",Chr(34))
			tableau=Val(Texte)
		Next b
EndMacro


Global Dim SobelH(8)


liste(SobelH(a),"-1,-2,-1,0,0,0,1,2,1")

;/On teste le résultat
Debug "------------"
For a=0 To 8
	Debug SobelH(a)
Next a
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Code: Select all

Dim a.l(16)

CopyMemory( ?nums, @a(), SizeOf(LONG)*17 )

DataSection
  nums: Data.l 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
EndDataSection
BERESHEIT
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Post by DoubleDutch »

netmaestro: nice one. :)

Nico: Good idea, but not as good as netmaestro's! ;)

It would be good as part of the language though.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Use Read and Data.
It is a good invent :wink:
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Actually, should the pre-processor allow what you're asking for - it shouldn't need an initial array size, since it can tell how many elements you're initially inserting inside the statement. This is true in a number of languages.

I must admit, I did write a pre-processor that does just what you're asking for but I never cared to implement a proper tokenizer, so it was a hack more than anything and needless to say a little unsafe to use.

After writing that plugin I got one of my "what on earth am I doing" moments (ie. just write in c++ you dogcrack).
:lol:

Cheers

PS: I was referring to me.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Post Reply