Initialising a string array
I'm trying to make this code work in Brandy but it objects because of the backslashes (I suppose I shouldn't have been surprised). I tried recasting it as DATA statements, but then the CHR$xxx get read as literal strings rather than being evaluated (again not surprising)!
What's the neatest Brandy-compatible workaround which will still run in other versions of BBC BASIC?
What's the neatest Brandy-compatible workaround which will still run in other versions of BBC BASIC?
DIM Legend$(4,13) Legend$() = "`","1","2","3","4","5","6","7","8","9","0","-","=","Backspace", \ \ "Tab","Q","W","E","R","T","Y","U","I","O","P","[","]","Enter", \ \ "Caps","A","S","D","F","G","H","J","K","L",";","'","#","", \ \ "Shift","\","Z","X","C","V","B","N","M",",",".","/","Shift","", \ \ "Ctrl","Alt"," Space","AltGr","Ctrl",CHR$128,CHR$129,CHR$130,CHR$131
0
Comments
-
Up until a few moments ago, there wasn't a way, other than using DATA, then "manually" putting the last 4 in, or entering it as a single long line - but if memory serves your BASICs have a program line length of 256 bytes (if not a few less).
That said, I've just pushed a change, and rebuilt the nightlies, that attempts to handle your line continuation syntax, but due to the way the parser reads directly from the memory this is ONLY enabled for expression handling (like this). With that, your example above is imported correctly.0 -
if memory serves your BASICs have a program line length of 256 bytes (if not a few less).
So that's all Acorn versions, all my versions and the few third-party versions of BBC BASIC that I've come across (e.g. for the Mac). I don't know about Brandy, but given the likelihood that one will want to exchange programs with other versions, in practice the same limit would apply.
It would make a nonsense of 'single line program' challenges (such as RHEOLISM) if the line could be any length!I've just pushed a change, and rebuilt the nightlies, that attempts to handle your line continuation syntax
I tried to work out a way of using READ with EVAL so that the CHR$ constants would be correctly evaluated, but I didn't come up with anything 'elegant'.0 -
I suppose you could use DATA, READ into a temporary variable, then if the value starts CHR$ then put it into the array via EVAL else just store it in the array "as is".0
-
I suppose you could use DATA, READ into a temporary variable, then if the value starts CHR$ then put it into the array via EVAL else just store it in the array "as is".
Looked at from a historical perspective, I think it's rather surprising that when Sophie introduced the 'array initialisation' syntax in ARM BASIC she didn't at the same time devise a way it could be split between multiple lines.
As it is, the maximum size of array that can be initialised this way is very limited; indeed if it's a string array there might not even be room for a single constant element to fit in a line!
0