Page 1 of 2
A quick way to load arrays
Posted: Wed Jun 03, 2009 2:16 pm
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:
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.
Posted: Wed Jun 03, 2009 2:23 pm
by Wladek
Posted: Wed Jun 03, 2009 3:09 pm
by Mistrel
Wladek wrote:Or like this:
How do you intend on fitting all of those numbers into such a small array?
+2 for this!

Posted: Wed Jun 03, 2009 6:30 pm
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.
Posted: Wed Jun 03, 2009 11:42 pm
by Kale
Wladek wrote:Or like this:
I like that but it's starting to look like C. I don't mind tho' but others might.

Posted: Wed Jun 03, 2009 11:59 pm
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...
Posted: Thu Jun 04, 2009 2:32 pm
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.
4. ##
I not insist. :roll:
Posted: Thu Jun 04, 2009 2:37 pm
by Trond
# is already used for something else (in macros).
Posted: Thu Jun 04, 2009 2:40 pm
by Wladek
Oh

, you right
I forgot: #PB_2DDrawing_Default or #PB_Any..............
Posted: Thu Jun 04, 2009 2:42 pm
by Trond
Haha, I forgot about those as well.
Posted: Thu Jun 04, 2009 6:47 pm
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
Posted: Thu Jun 04, 2009 9:03 pm
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
Posted: Thu Jun 04, 2009 10:26 pm
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.
Posted: Fri Jun 05, 2009 3:45 pm
by Psychophanta
Use Read and Data.
It is a good invent

Posted: Sat Jun 13, 2009 6:45 pm
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).
Cheers
PS: I was referring to me.