Having problem getting bytes from DAT with passed in address
fish
Posts: 55
Hi,
I am trying to do somthing·really simple, but I'm stuck.
Method testMe() looks up an address at index·0 and·passes that address to showNumber()·who·then·displays the data.
But it's not working out·the way I expected.·
Can somebody please clue me in on what·am I doing·wrong?
thx
fish
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Did I make a unit test for it? No... Did·I run the test·suite·before checking it in? No... But it shouldn't break anything.· ~intern·(just before we let him go).
I am trying to do somthing·really simple, but I'm stuck.
Method testMe() looks up an address at index·0 and·passes that address to showNumber()·who·then·displays the data.
But it's not working out·the way I expected.·
Can somebody please clue me in on what·am I doing·wrong?
DAT _A byte 0,9,4,0,4,0,7,9,2,5,6,5,-1 pub testMe | index,addr index := 0 addr:= lookup(index : _A) showNumbers(addr) pub showNumbers(addr) | val, i i:=0 repeat until val==-1 val := byte[noparse][[/noparse]@addr][noparse][[/noparse]i++] 'I get, well.. not what I want. ' val := byte[noparse][[/noparse]@_A][noparse][[/noparse]i++] 'uncomment to see the expected results term.dec(val) term.out(13)
thx
fish
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Did I make a unit test for it? No... Did·I run the test·suite·before checking it in? No... But it shouldn't break anything.· ~intern·(just before we let him go).
Comments
Instead of addr:= lookup(index : _A), use addr:= _A[noparse][[/noparse]index]
index is the location of the data you want.
_A is just an array(index).
Richard
Not quite what I am getting at though.
And upon closer inspection and what CardboardGuru is getting at is LOOKUP/Z does not give me what I want.
So it is not not a reference passing problem at all (as this thread title suggests), but rather a problem of obtaining the address to the array.
So a more complete picture of what I am trying to do is:
DAT
_A 1,2,4,5,6,-1
_B 6,3,6,7,-1
_C 1,3,-1
_D 3,2,1,5,0,-1
_E 5,2,7,5,1,5,3,5,2,-1
...
So a given index would point to an array in memory.
index 0 would give me array _A
index 1 would give me array _B
index 2 would give me array _C
and so on.
I believe I can iterate thru the array just fine ( val := byte[noparse][[/noparse]@correctAddress][noparse][[/noparse]i++] )
It's getting the correct address to that array based upon a given index that I am having trouble with.
thx
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
". . . the fog is rising"~ Emily Dickinson
val := byte[noparse][[/noparse]lookupz( array_number: @_A, @_B, @_C, @_D, @_E)][noparse][[/noparse]i++]
Sorry, I missunderstood. I like what Cardboard just said but I don't know ....
Let us know if it works. It would be another good tool.
Richard
was the @ in the wrong places.
This works:
-btw, I am wondering why have·zero-based·AND·one-based lookup methods?
Moreover, why does Spin have·one-based indexing at all?·If it's because·beginning programmers·have trouble·wrapping their minds around·the zeroeth element concept, I will be disappointed. Seems like it would introduce more confusion and 'off by one' errors than it would mitigate... But there must·be·a good reason.
Anyway, thanks for the help guys!
fish
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
". . . the fog is rising"~ Emily Dickinson
Post Edited (fish) : 6/21/2007 8:37:02 PM GMT