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?
      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

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.
  • Soruk wrote: »
    if memory serves your BASICs have a program line length of 256 bytes (if not a few less).
    It's not specifically my BASICs which have a line-length limit, all versions of BBC BASIC which support a tokenised representation of the program (in memory or file) have that limitation, because the line-length is stored as a single-byte value in the tokenised formats.

    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
    Interesting, but it's not something I could safely use if I want to be sure that everyone using Brandy can run it, at least not until they have nearly all updated to this new version.

    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'.
  • 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".
  • Soruk wrote: »
    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".
    That's basically what I came up with, but it's messier than just handling the final four elements of the array separately (it's fortunate that it happens to be the last four elements, rather than scattered).

    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!