Menu

#35 PRINT command semicolon

v1.0_(example)
closed
None
5
2016-03-30
2016-03-20
No

Hello!

This is from BASIC ZX Spectrum dialect:

With a semicolon the next number or string is printed immediately after the preceding one.
50 PRINT F;
Now type in these extra lines:
100 REM this polite program remembers your name 110 INPUT n$ 120 PRINT "Hello ";n$;"!" 130 GO TO 110

In BASIC 256 is a good thing implementation of semicolon at the end of PRINT command to avoid starting a new line and keep things together. But look at line 120.
Command PRINT "Hello ";n$;"!" keep the sense of semicolon behaviour in PRINT command.

It is useful to add this behavior in BASIC 256 especially because it is not contrary to the actual command syntax and preserve the version with "+" sign for compatibility reasons. I find the original behavior is more easily understood by children. It also prevents kids from the confusion with the add operation.

PRINT "Hello ";n$;"!"
PRINT "Hello " + n$ + "!"

Respectfully,
Florin Oprea

Discussion

  • Jim Reneau

    Jim Reneau - 2016-03-22

    I like adding ";" as a concatenate operator that can be used to concatenate strings in all statements

    a = "hello "; 5 ; " of " ; 7 ; "."
    would be the same as
    a = "hello "+ 5 + " of " + 7 + "."

    As we clean up the language while we get ready for 2.0, do we need to add a setting to the preference screen to force + to always work arethmetically and to use ";" as our concatenate?

     
  • Florin Oprea

    Florin Oprea - 2016-03-23

    I'm glad you like the idea.
    Let's have both versions work at the same time (";" and "+" as a symbol for concatenation), without any special setting in preference screen.

     
  • Oprea Nicolae

    Oprea Nicolae - 2016-03-25

    Really? What about PRINT 5+7 ... it will print 12 (mathematical result) or 57 (5 and 7 as concatenated numbers)?
    Only the ";" concatenation operator sould be used like in all BASIC languages (print anything and keep position of print right after printed string or number instead of increase row and reset column).
    The + version is totally wrong and only confuses users.

     
    • Florin Oprea

      Florin Oprea - 2016-03-26

      I believe that both versions can exist simultaneously (as they simultaneously work in other old versions of BASIC). The user will choose which alternative wants to use ( ";" or "+").
      This is old style BASIC (works on many dialects):

      10 LET a$="Hello"
      20 LET b$=" World!"
      30 LET c$=a$+b$
      40 PRINT c$
      50 PRINT a$+b$
      60 PRINT a$;b$
      

      Results:

      "Hello World!"
      "Hello World!"
      "Hello World!"

      Plus sign "+" should act as a concatenation operator between two strings. So it must act as a concatenation operator between two strings also in the PRINT command.
      On the other hand, semicolon sign ";" is a PRINT specific operator. It is like a sign for enumeration that says for interpretor: "hold together" or "print this stuff together".

      Respectfully,
      Florin Oprea

       
  • Jim Reneau

    Jim Reneau - 2016-03-30
    • status: open --> closed
    • assigned_to: Jim Reneau
     
  • Jim Reneau

    Jim Reneau - 2016-03-30

    in 1.99.99.19 the ';' operator will ALWAYS concatenate a = 1;2;3 would be 123. The + operator will add numbers (int/float), strings conatining numbers (with no white spaces) will be converted to numbers and added as numbers. If either or both operators are strings that are not numbers then + will concatenate.

    a = "1" + "2" -- 3
    a = "1 " + 2 -- "1 2"
    a = "7e20" + 1e20 - 8e20
    a = "hi" + 7 - hi7

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.