2

With the exception of DEF FN and the handful of direct-mode commands (CONT, LIST, etc), my interpreter is running most programs, but layout remains an issue.

Here are three lines from the BASIC Computer Games' "23 Matches"...

270 PRINT "THE NUMBER OF MATCHES IS NOW" N
...
350 PRINT "THERE ARE NOW ";N;"MATCHES REMAINING."
...
390 PRINT "MY TURN ! I REMOVE" Z "MATCHES"

First, look at line 350. There is a space inside the string before the first semi, so that the value isn't run up against the text. However, the second string doesn't have a space. Is there a trailing space on numbers, or is this going to cause it to run up against the number?

Now consider the other two lines. They print a list of items without any separators, something I didn't think was legal but I'm now trying to support. In both cases, the first string has no trailing space. In these cases, is the space between the string constant and the variable significant? I believe MS drops all whitespace, and my code assumes that, so my suspicion is that these are not significant. However,

  • 2
    did your question get cut off? For those who need to see the source, it's here: vintage-basic.net/bcg/23matches.bas – scruss Nov 28 '19 at 1:54
  • 1
    I ran this program in RT-11 BASIC (only changes needed were to add 10 RANDOMIZE and change 40 to PRINT \ PRINT \ PRINT) and none of the text ran up against any of the numbers (impying that numbers always get a leading and trailing blank). But the "MATCHES REMAINING" message didn't have an extra space before the number, as if this dialect detected this situation and handled it specially. – Ken Gober Nov 28 '19 at 5:02
  • I tried it on RSTS V7 (which is actually BASIC-PLUS so might be nothing to do with the language that interests you, and certainly is not the implementation you're asking about), and my conclusion is that numbers get a leading space-or-minus and a trailing space. Also for RSTS, semi-colon and no delimiter cases both insert no extra separation, unlike the multiple-of-three column cited for the semicolon case in 1964 DTSS, – another-dave Nov 29 '19 at 22:08
2

When I did my MS basic clone I found I needed the trailing space on numbers and a leading space if the number wasn't negative.

Looking at the tests I wrote STR$ always puts a leading space in.

I think I ended up testing with a UK101,Pet,Apple and CP/M version of MS basic in the end.

| improve this answer | |
  • 1
    Most excellent, thanks! – Maury Markowitz Nov 28 '19 at 14:40
  • I don't want to plug my own work, but the whole thing is up on GitHub. I aimed for getting 101 Basic games to work based on the CP/M source. – PeterI Nov 28 '19 at 14:43
  • Link, link! Is it lex/bison? – Maury Markowitz Nov 28 '19 at 14:44
  • Nah hand coded. github.com/peteri/ClassicBasic I'd guess the tests are probably the most useful bit. – PeterI Nov 28 '19 at 15:18
  • The question is about MS BASIC, but the original Dartmouth BASIC from 1964 may shed some useful light - page 31 onwards. My summary: comma moves to next 15-column "zone", semicolon moves to next multiple-of-3 column, and the absence of either of those effectively concatenates stringified representation. I did not see explicit description of how the number is rendered in this last case, but an example seems to show it is space, space-or-sign, the digits of the integer. Or maybe the lead space is a separator. Try PRINT "FOO" A$ ? – another-dave Nov 28 '19 at 16:09
2

Not all MS BASICs include spaces. AppleSoft — which is derived from MS BASIC — would output

A5B

if it saw

PRINT "A";5;"B"
| improve this answer | |
  • Thanks scruss. It looks like I'll have to add a command-line option for this. – Maury Markowitz Nov 28 '19 at 15:04
2

MS-BASIC is for many parts modelled after DEC's PDP-11 BASIC. And PDP-11 BASIC is as well quite related to ECMA-55 Minimal BASIC, so as usual when talking about old BASIC details a look at the fine crafted ECMA-55 specification is helpful.

For PRINTing of number is notes:

   Numeric-expressions shall be evaluated to produce a string of
   characters consisting of a leading space if the number is po-
   sitive or a leading minus-sign if the number is negative fol-
   lowed by the decimal representation of the absolute value of
   the number and a trailing space. The possible formats for the
   decimal representation of a number are the same as those des-
   cribed for numeric-constants in 6 and are used as follows.

So line 350 looks like with exactly this formating in mind. A space in front of the number element to make sure that an optional negative sign will not be glued to the text, while no space after, as the number will already produce one.

The standard continues about number output formation:

   Each implementation shall define two quantities, a significance-
   width d to control the number of significant decimal digits
   printed in numeric representations, and an exrad-width e to con-
   trol the number of digits printed in the exrad component of a
   numeric representation. The value of d shall be at least six
   and the value of e shall be at least two.

   Each number that can be represented exactly as an integer with
   d or fewer decimal digits is output using the implicit point
   unscaled representation.

   All other numbers shall be output using either explicit point
   unscaled notation or explicit point scaled notation. Numbers
   which can be represented with d or fewer digits in the unscaled
   format no less accurately than they can be represented in the
   scaled format shall be output using the unscaled format. For
   example, if d = 6, then 10^(-6) is output as .000001
   and 10^(-7) is output as 1.E-7.

   Numbers represented in the explicit point unscaled notation shall
   be output with up to d significant decimal digits and a full-
   stop; trailing zeroes in the fractional part may be omitted.
   A number with magnitude less than 1 shall be represented with
   no digits to the left of the full-stop. This form requires up
   to d+3 characters counting the sign, the full-stop and the
   trailing space.

Well, there is mich more to PRINT here - including the TAB() cell argument wich is for example present with DEC and Applesoft BASIC, positioning any following output to a given TAB cell. Which BTW doesn't mean 8 like in terminal speak, but 14 or more, depending on the number printing format used, as a tab cell is supposed to hold a full numeric output. A feature quite handy to print nice lists.

Similar requires to check if there's enough space on the remaining line to output the whole print item or otherwise start a new line first.

   If the evaluation of any print-item in a print-list would cause
   the length of a nonempty line to exceed the margin, then an
   end-of-line is generated prior to the characters generated by
   that print-item. Subsequently, if the evaluation of a print-
   item generates a string whose length is greater than the mar-
   gin, then end-of-lines are inserted after every m characters
   in the string, where m is the margin value.

A remarkable point many microcomputer BASICs never implemented - but minis did. Lime many other side effects, programmers may have made use of this, rendering output in a different BASIC different.

In general it is important to keep in mind, that most of the games in 101 BASIC Games weren't first (or at all) developed on a some micro computer, but came from minis with their own BASICs


| improve this answer | |
  • Once annoyance about that last quoted item is that the only easy way to know how wide the output will be in C is to int w = printf(...). I guess I'll print to a string first to check the size and then print the string. – Maury Markowitz Nov 28 '19 at 19:26
  • 1
    ... and forget micros, some of the famous ones weren't even basic. If I ever get this working well enough I'll try a FOCAL conversion. – Maury Markowitz Nov 28 '19 at 19:26
  • @MauryMarkowitz I wouldn't put too much emphasis on the length issue. Sure, for doing a clean Minimal BASIC it would be mandatory, but today's canon is formed by MS-BASIC who didn't check, but just outputted. – Raffzahn Nov 28 '19 at 19:41
  • 1
    Outside MS compatibility, for Minimal BASIC it's worth knowing about NBS minimal BASIC test programs - Version 2, user's manual and NBS Minimal BASIC Test Programs— Source Listings and Sample Output along with the NBS Test Programs. These give useful background on what BASIC should do and why – scruss Nov 29 '19 at 2:30
  • 1
    The newline insertion was perhaps necessary to cater for some teletypes, which as far as I recall (possibly inaccurately) would just bang up against the margin if you printed a line wider than the physical carriage-width. No automatic line-wrap in the hardware, so software had to do it. – another-dave Nov 29 '19 at 2:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.