Page 1 of 1 1
Topic Options
#77733 - 2001-05-03 08:16 PM BUG - Array bug or just Shawn being a dough-head ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Ruud (etal)

Speaking of arrays ...

Hope you can make sense out of the following scrap of code. I'm trying to enumerate nested arrays using the FOR-EACH-IN-NEXT construct... What I bumped into was the following bit of esoterica and wanted to know if this was desirable behavior (on KiXtart's part, not mine)...

The following script enumerates an array of numbers (twice) then attempts to enumerate an array of arrays (twice). Run this script with beta2a and you get the following syntax error...

Script error : expected '[' !
for each $array in $array4

Uncomment the commented line and everything works fine...

I'm bringing this to your attention because my gut tells me that this is not something you want happening and that there may be a problem in the way KiXtart is initializing (or in this case, not initializing) these transient in-variables.

Afterthink:

Does this have to do with the fact that you can't use arrays in some expressions - therefore once it gets casts to an array in the first loop - you can't use it again in the second loop - unless you recast it to anything but an array ?


After-Afterthink:

no,no,no - it's because in the second array enumeration, $array is already cast as an array and FOR-NEXT is looking for brackets !

code:

break on


; Enumerate an array of numbers (twice)


$array1 = 1,2,3,4


?"once..."


for each $number in $array1
?$number
next


?"twice..."


for each $number in $array1
?$number
next


; Enumerate an array of arrays (twice)


$array2 = 1,2,3,4
$array3 = 1,2,3,4
$array4 = $array2,$array3


?"once..."


for each $array in $array4
? $array[0]
? $array[1]
? $array[2]
? $array[3]
next


; $array = 0 ; <--- uncomment this line


?"twice..."


for each $array in $array4
? $array[0]
? $array[1]
? $array[2]
? $array[3]
next


exit


Shawn.

[This message has been edited by Shawn (edited 04 May 2001).]

Top
#77734 - 2001-05-03 08:26 PM Re: BUG - Array bug or just Shawn being a dough-head ?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Shawn,

I added this

vartypename($array) ?

before and after the $array=0 and uncommented it.

KiX said:

Before = Variant[]
After = Long

I also tried this

redim $array

instead of $array=0 and KiX said:

Before = Variant[]
After = Empty

Then I popped a few

"number = " vartypename($number) ?

lines in and saw that $number goes from Empty to Long and stays as Long.

Putting a vartype($array) ? at the top, after $array was filled and before it was used in the FOR EACH loop and it was EMPTY.

It looks to me that you can't put a VARIANT[] in the xxxx of FOR EACH xxxx IN array command. But a LONG or EMPTY is ok.

cj

Top
#77735 - 2001-05-03 08:47 PM Re: BUG - Array bug or just Shawn being a dough-head ?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Ok, this won't work.

It looks to me that you are trying to make a two dimensional array, or add to arrays together.

The statement:

$array4=$array2,$array3

does not work. You cannot return all the elements of $array2 byt just putting $array2 in the statement. If you want to simulate

$array4=$array2,$array3
or in pseudo code,

$array4=contents of $array2 and contents of $array3 (alright, so it's not real pseudocode)

try this:

code:

break on cls


$array2=1,2,3,4
"$$array2: "
for each $thing in $array2
$thing ; ", " ; this is replaced by the if...
if $thing<>$array2[ubound($array2)] ", " endif ; stops comma on the end
next
? ?


$array3=5,6,7,8
"$$array3: "
for each $thing in $array3
$thing
if $thing<>$array3[ubound($array3)] ", " endif
next
? ?


$=execute('$$array4='+join($array2, ",")+','+join($array3, ","))


"$$array4: "
for each $thing in $array4
$thing
if $thing<>$array4[ubound($array4)] ", " endif
next
? ?


function join($array, $separator)
; crude implementation of VBJoin, I'll make a better one later.
; p.s. Ruud, can you put a function like this in Beta 3
; but make it the same as the VBS one...
$join="" ; reset output
for each $thing in $array
$join=$join+$thing+$separator ; add items together
next
$join=substr($join, 1, len($join)-1) ; strip last comma
endfunction



cj

p.s. You can't use

if $thing<>$array2[ubound($array2)] ", " endif

if there is more than one occurance of the last element of the array. eg:
if array='1,2,3,4,1,2,3,4" you will get 1, 2, 3, 41, 2, 3, 4 because the ", " is not printed for the 4 because the last element is a 4.

In this case, just use the Join function.


[This message has been edited by cj (edited 03 May 2001).]

Top
#77736 - 2001-05-03 08:50 PM Re: BUG - Array bug or just Shawn being a dough-head ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ceej:

See my After-Afterthink (lookie above). I think that there's another specific error message when using variant[]'s inproperly (should say "in a currently unsupported fashion") ... I remember Ruud saying that he's working on expanding the usage of variant[]'s to other contructs. hmmm...

Shawn.

quit
quit

[I read your code! ]


p.s. you can do this - i did (do) it all the time in my kixpoker script. just never did it twice.

Shawn..

[This message has been edited by Shawn (edited 03 May 2001).]

Top
#77737 - 2001-05-05 04:02 AM Re: BUG - Array bug or just Shawn being a dough-head ?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Which code?

I often use quit quit because quit just doesn't quit I think that it just quits the current loop (if, select, while, do etc)

Although, I would like EXIT to do this...


cj

Top
#77738 - 2001-05-05 04:27 AM Re: BUG - Array bug or just Shawn being a dough-head ?
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I studied your tictactoe game quite throughly and was referring to this line...

:bibi
? "Thanks for playing!" ?
quit quit

So what you're saying is that kixtart's quit command is like the energizer bunny - it just keeps going, and going, and going ... zzz ...

Shawn.

Top
#77739 - 2001-05-05 11:55 PM Re: BUG - Array bug or just Shawn being a dough-head ?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia

The quit problem might have been fixed, but I can't remember exactly what happened or how to reproduce it.

I found a bug with my post above, the line

$=execute('$$array4='+join($array2, ",")+','+join($array3, ","))

does not actually add the contents of $array2 and $array3 to $array4, what it does is put the contents of $array2 into $array4[0] and $array3 into $array4[1].

I have tried to make this work for a script I am working on, but gave up and will write some UDFs instead.

Speaking of UDFs, I have written a few that I will post with the next script. I will be including these UDFs IN the actual script that they are used in, but they can be saved to external .UDF files and CALLed from the top of the .K2k file like the #include that we were discussing on Suggestions.


I started a thread on Beta about a proposal to create a spec for UDFs.

cj

Top
#77740 - 2001-05-06 02:28 PM Re: BUG - Array bug or just Shawn being a dough-head ?
Anonymous
Unregistered


Trying for nested arrays, eh ? ;-)

This is not really supported. I was actually amazed to see the extent to which it works. However, there are certain things that don't work, so for now, it is unsupported syntax.

However, the fact that the 2nd FOR NEXT stumbled on this was a plain and simple bug. It's been fixed since.

Thanks for your support, and keep stretching the limits!

Ruud

Top
#77741 - 2001-05-08 02:16 AM Re: BUG - Array bug or just Shawn being a dough-head ?
cj Offline
MM club member
*****

Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
Is there any chance we'll see 2D arrays?

maybe:

DIM $array[5,5]

and references are:

$array[1, 1]="first"
$array[1, 2]="second"

and FOR EACH...

FOR EACH $thing in $array

returns

1,1
1,2
1,3
1,4
1,5
2,1
2,2
.
.
.
etc

cj

Top
#77742 - 2001-05-09 12:13 AM Re: BUG - Array bug or just Shawn being a dough-head ?
Anonymous
Unregistered


Absolutely: multi-dimension arrays are on the todo-list for 2001+.

Kind regards,

Ruud

Top
Page 1 of 1 1


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 509 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.029 seconds in which 0.011 seconds were spent on a total of 12 queries. Zlib compression enabled.