home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / acorn / 8357 < prev    next >
Encoding:
Internet Message Format  |  1992-08-25  |  6.2 KB

  1. Path: sparky!uunet!mcsun!uknet!acorn!armltd!dseal
  2. From: dseal@armltd.co.uk (David Seal)
  3. Newsgroups: comp.sys.acorn
  4. Subject: Case of Basic keywords (was Re: OS differences and improvements...)
  5. Message-ID: <5751@armltd.uucp>
  6. Date: 26 Aug 92 08:52:29 GMT
  7. References: <5695@mccuts.uts.mcc.ac.uk>
  8. Sender: dseal@armltd.uucp
  9. Distribution: comp
  10. Organization: A.R.M. Ltd, Swaffham Bulbeck, Cambs, UK
  11. Lines: 116
  12.  
  13. In article <5695@mccuts.uts.mcc.ac.uk> zzassgl@uts.mcc.ac.uk (Geoff Lane)
  14. writes:
  15.  
  16. >In article <1992Aug25.075656.17526@rdg.dec.com> goodwin@edieng.enet.dec.com (Pete Goodwin) writes:
  17. >>Still, I'm biased, I like the VMS command line: DIR, SET DEFAULT, TYPE, ED (I'm
  18. >>a fan of EVE EDT), SEARCH, PRINT etc.
  19. >>Pete Goodwin
  20. >
  21. >Never could trust a computer you had to shout at to get work done :-)
  22. >
  23. >Which brings me to RiscOs Basic. Why, Oh why, Oh why, Oh why do we still
  24. >have to write the Basic commands and keywords in uppercase?
  25.  
  26. Probably because changing this would (a) be highly inconvenient; (b) make
  27. old programs difficult to maintain, etc.
  28.  
  29. To explain: there is a rule in the Acorn Basics that a variable name may not
  30. start with a keyword. This rule is there to make certain that the
  31. interpreter can understand your programs. A simple example of this is a
  32. statement like:
  33.  
  34.   unable%=NOTable%
  35.  
  36. Without the rule about variable names not starting with keywords, the
  37. interpreter wouldn't be able to tell whether you were telling it to set
  38. unable% to the variable NOTable%, or to the logical negation of the variable
  39. able%. With the rule, it can easily determine that the latter is the only
  40. legitimate interpretation.
  41.  
  42. This isn't too inconvenient, because the keywords are only recognised in
  43. upper case. For instance, the variable name "TOTAL" is disallowed because
  44. "TO" is a keyword, but you can quite easily use "Total" or "total" instead.
  45. If you start recognising keywords regardless of case, however, it becomes a
  46. lot more inconvenient: quite a few desirable variable names become
  47. completely unusable.
  48.  
  49. On top of this, at present there are several useful rule of thumbs about
  50. avoiding variable names which start with a keyword - e.g. "If your variable
  51. names never start with more than one upper case letter, you'll never run
  52. into the problem". No such easy rule of thumb exists if keywords are
  53. recognised regardless of case.
  54.  
  55. Secondly, old programs would become very difficult to maintain, because they
  56. would be likely to contain some of the now-forbidden variable names. This
  57. wouldn't be a problem for the tokenised form in which Basic programs are
  58. stored, because the tokenised form makes a clear distinction between e.g.
  59. the variable "notable%" and the token for the keyword "not" followed by the
  60. variable "able%". So the old program would still run. But the moment you
  61. convert it to text, then convert it back, you're going to run into problems.
  62. E.g. if you decide you need to change the line:
  63.  
  64.   dignitary% = notable%(I%): I%+=1
  65.  
  66. to:
  67.  
  68.   dignitary% = notable%(I%): I%+=increment%
  69.  
  70. you are likely to find that the old tokenised form contains the variable
  71. "notable%", but after conversion to text, editing and conversion back, the
  72. new tokenised form contains the token for the keyword "NOT" followed by the
  73. variable "able%". This is likely to cause chaos...
  74.  
  75. Similar problems would arise e.g. if you wanted to email an old program to
  76. someone: because of email only really handling the normal printable
  77. characters, you would probably send the program in textual form. When the
  78. recipient reconstructs the program, they don't get what you started with...
  79.  
  80. There are of course other possible ways to ensure the interpreter can sort
  81. out variables from keywords. One such would be to insist the keywords are
  82. always preceded and followed by non-alphabetic characters - inserting spaces
  83. if necessary, and probably not allowing the non-alphabetic character after
  84. the keyword to be "$" or "%". (This is already necessary before keywords -
  85. e.g. the statement "FORi=jTOk" doesn't work, since the interpreter looks for
  86. a variable called "jTOk". To make it work, you need to insert a space to get
  87. "FORi=j TOk" and make the keyword "TO" recognisable.) With this alternative
  88. rule, the interpreter would know that "NOTable%" had to be a variable and
  89. not the same as "NOT able%". You would then be able to have keywords in any
  90. case without too much inconvenience.
  91.  
  92. However, this change would suffer from at least two disadvantages:
  93.  
  94.   * It would still cause problems with old programs that had been stored in
  95.     textual form rather than tokenised form (e.g. magazine listings, some
  96.     programs in archives, etc.). (Old programs in tokenised form would
  97.     presumably be converted to text correctly and so could be edited without
  98.     trouble. E.g. the new interpreter would detokenise what had been
  99.     "dignitary% = notable%(I%)" as "dignitary% = notable%(I%)", and what had
  100.     been "dignitary% = NOTable%(I%)" as "dignitary% = not able%(I%)". But it
  101.     wouldn't be able to work with a detokenised program created by an old
  102.     interpreter.
  103.  
  104.   * For every programmer who had been swearing at the insistence on upper
  105.     case keywords, there would probably be at least one who was now swearing
  106.     at the insistence on spaces where they hadn't been necessary before!
  107.  
  108. Finally, if you do like the idea of this alternative rule, it would probably
  109. not be too difficult a programming project to write an application that took
  110. a program written in the changed style and converted it to the standard
  111. style. Basically, it would need to recognise keywords in either case and
  112. change them to upper case. Optional extras would be to warn you about
  113. variable names that start with an upper case keyword (which will cause you
  114. problems when the program is subsequently tokenised) and to remove spaces
  115. around keywords that had become unnecessary in the standard style.
  116.  
  117. One particular keyword you would have to look out for is "TOP". This isn't
  118. in the standard keyword/token tables, since the interpreter actually
  119. tokenises it as the keyword "TO" followed by the letter "P", then has a
  120. special case when interpreting the program to detect this combination.
  121. Keywords that start with other keywords could cause the same sort of parsing
  122. problems as variables that start with keywords: it's fortunate there aren't
  123. many of them!
  124.  
  125. David Seal
  126. dseal@armltd.co.uk
  127.  
  128. All opinions are mine only...
  129.