BASIC V/VI private (or static) vars & arrays
David Williams (2619) 103 posts |
When converting an old game of mine from Russell-branch BBC BASIC to ARM BASIC V, I had to replace private (static) variables with globals, which felt very unsatisfactory. Could private variables and arrays be (natively) introduced to ARM BASIC V/VI? Here’s a link to the section in the ‘BBC BASIC for Windows’ docs regarding the PRIVATE statement: http://www.rtrussell.co.uk/bbcwin/manual/bbcwin7.html#private I use private variables quite a lot in my BB4W projects. Among BASIC V/VI programmers/dabblers reading this, is there agreement that such an update would be a good and worthwhile thing? Are there particular technical barriers to implementing private vars & arrays within the interpreter’s architecture? (I now have the feeling that I’ve made the same or similar request here before. I should’ve checked first, so forgive me if I have!) |
David Williams (2619) 103 posts |
Can allocate memory, use a pointer to block that is LOCAL. Same for variables. No, thanks. I wasn’t looking for a hack. |
Steve Drain (222) 1620 posts |
Quite likely.
I cannot see any problem doing it just as BB4W does. It would be a moderately deep change. B****t does its own thing, because it operates outside the interpreter. It does not have a You can achieve something similar in plain BASIC using the ‘magic’ pointers to the grave (`) list of variables or the underscore (_) list, even if it is a bit clumsy: DEFPROCmyProc IF FN_PRIVATE(myProc) THEN `a%+=1:`b%(1)=9:REM main calls ELSE `a%=0:DIM `b%(9):REM first call ENDIF PRINT `a%,`b%(1) PROC_PRIVATE(myProc) ENDPROC DEFFN_PRIVATE(RETURN list%) SWAP list%,!&8580:REM grave list =!&8580 DEFPROC_PRIVATE(RETURN list%) SWAP list%,!&8580 ENDPROC |
David Williams (2619) 103 posts |
I hope the guys at ROOL will seriously considerate it. Maybe a new bounty could be proposed? :-)
Thank you, and not wishing to sound unappreciative of your stopgap solution (which I’ll play with later), I think I’ll hold out for a ‘proper’ native implementation of the PRIVATE statement – should one ever arrive! |