First off thank you to Richard Russell for creating and maintaining BBC Basic for Windows and SDL. I went from ZX80 Basic to BBC Micro Basic to university FORTRAN and then into a plethora of languages across my career, and it is with great joy that I return to BBC Basic for pure fun now.
I have been playing with structures and found some unexpected behaviour. The following code should only change one array structure per dump, but it modifies others where indicated. It is entirely possible that I am being stupid - if so apologies again - but any explanation would be very welcome
Code: Select all
MODE 14
DIM a{t,s$}
DIM array{(4)}=a{}
FORi=0TO4
array{(i)}.t=-1
array{(i)}.s$="null"
NEXT
PROCdump
PROCset(a{},0,"Zero?")
array{(0)}=a{}
PROCdump
PROCset(a{},1,"11")
array{(1)}=a{}
PROCdump
PROCset(a{},2,"222")
array{(2)}=a{} : REM unexpected, array{(1)}.s$="22"
PROCdump
PROCset(a{},3,"3333")
array{(3)}=a{} : REM unexpected, array{(0)}.s$="3333?"
PROCdump
array{(4)}.t=4.4
array{(4)}.s$="Four.four"
PROCdump
a{}.t=4
a{}.s$="44444"
array{(4)}=a{} : REM unexpected, array{(3)}.s$="4444"
PROCdump
END
DEFPROCdump:LOCALi
FORi=0TO4
PRINT"dataitem ";i;", t=";array{(i)}.t;" s$=""";array{(i)}.s$;""""
NEXT
PRINT
ENDPROC
DEFPROCset(RETURN struc{},p,q$)
struc{}.t=p
struc{}.s$=q$
ENDPROC