• Something strange going on.

    From Shaun Bebbington@3:770/3 to All on Wed Apr 11 03:33:15 2018
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X where X is
    a valid line number (i.e., LET X = 100). But I know that's not possible with Microsoft BASIC. Of course there is the ON X GO TO 100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use this as a look up table". The following, I expected to go to the value in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    Thanks in advance.

    Shaun.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Shaun Bebbington@3:770/3 to Shaun Bebbington on Wed Apr 11 04:05:16 2018
    On Wednesday, 11 April 2018 11:33:17 UTC+1, Shaun Bebbington wrote:
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X where X
    is a valid line number (i.e., LET X = 100). But I know that's not possible with
    Microsoft BASIC. Of course there is the ON X GO TO 100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use this
    as a look up table". The following, I expected to go to the value in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    Thanks in advance.

    Shaun.

    The same weird thing is happening with 1D arrays, i.e.,

    0 PRINT "LINE ZERO"
    1 LET A(0) = 10
    2 LET A(1) = 20
    3 LET A(2) = 30
    5 GO TO A(1)
    10 STOP
    20 STOP
    30 STOP

    Expected result: Unconditional jump to line 20
    Actual: infinite loop

    But one cannot GOTO A for instance.

    Regards,

    Shaun.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From wwww.leser@gmail.com@3:770/3 to Shaun Bebbington on Wed Apr 11 05:34:15 2018
    On Wednesday, April 11, 2018 at 12:33:17 PM UTC+2, Shaun Bebbington wrote:
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X where X
    is a valid line number (i.e., LET X = 100). But I know that's not possible with
    Microsoft BASIC. Of course there is the ON X GO TO 100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use this
    as a look up table". The following, I expected to go to the value in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    Thanks in advance.

    Shaun.

    I went the "hard" way and traced what happens using VICE's monitor's 'z' command. I recommend that you do the same, consulting a commented BASIC ROM listing if necessary.
    But there's a much easier way to get the idea: Let your programs start at line 1 instead of 0.

    Chris

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From ArcadeAge@3:770/3 to Shaun Bebbington on Wed Apr 11 11:55:06 2018
    On Wednesday, April 11, 2018 at 12:33:17 PM UTC+2, Shaun Bebbington wrote:
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X where X
    is a valid line number (i.e., LET X = 100). But I know that's not possible with
    Microsoft BASIC. Of course there is the ON X GO TO 100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use this
    as a look up table". The following, I expected to go to the value in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    Thanks in advance.

    Shaun.

    I went the "hard" way and traced what happens using VICE's monitor's 'z' command. I recommend that you do the same, consulting a commented BASIC ROM listing if necessary.
    But there's a much easier way to get the idea: Let your programs start at line 1 instead of 0.

    Chris

    Edit: The above should read "Let your programs start _with_ line number 1". Here's a short version of the "hard" way:
    - Start x64 from a console window (otherwise breakpoints might not work)
    - Enter a one-liner "0 goto 0"
    - RUN the one-liner
    - Enter VICE's monitor (Ctrl-h)
    - Enter 'bk a971' in VICE's monitor
    - Enter 'x' in VICE's monitor
    - Not(ic)e that the C-flag is set but every other time the breakpoint is reached

    Now repeat the above procedure, but let your one-liner be "0 goto a" instead this time. Note that the C-flag is set _all_ the time.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Ed Vance@1:2320/105 to Shaun Bebbington on Wed Apr 11 22:37:00 2018
    04-11-18 03:33 Shaun Bebbington wrote to All about Something strange going o Howdy! Shaun,

    @MSGID: <5ACE2329.2490.cbm@capitolcityonline.net>
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X
    where X is a valid line number (i.e., LET X = 100). But I know that's
    not possible with Microsoft BASIC. Of course there is the ON X GO TO 100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use this as a look up table". The following, I expected to go to the value
    in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    Thanks in advance.

    X isn't given a VALUE yet. I "think" (TM).



    ... Have you checked your smoke detector batteries & Fire Ext, LATELY?!
    --- MultiMail/MS-DOS v0.49
    * Origin: CCO BBS - capitolcityonline.net:26 (1:2320/105)
  • From Thomas Lake@3:770/3 to Shaun Bebbington on Thu Apr 12 18:41:56 2018
    On Wednesday, April 11, 2018 at 6:33:17 AM UTC-4, Shaun Bebbington wrote:
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X where X
    is a valid line number (i.e., LET X = 100). But I know that's not possible with
    Microsoft BASIC. Of course there is the ON X GO TO 100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use this
    as a look up table". The following, I expected to go to the value in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    Thanks in advance.

    Shaun.

    You SHOULD get a syntax error. Commodore (Microsoft) BASIC is supposed to only allow numeric constants, not variables after GOTO and GOSUB. What do you actually see happening?

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Janne Johansson@2:221/6 to Shaun Bebbington on Fri Apr 13 09:53:58 2018
    On 2018-04-11 02:33, Shaun Bebbington : All wrote:
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X
    where X is a valid line number (i.e., LET X = 100). But I know that's
    not possible with Microsoft BASIC. Of course there is the ON X GO TO
    100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use
    this as a look up table". The following, I expected to go to the value
    in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    BTW, I got reminded of someone devising a way to make selfmodifying
    BASIC on C64, by printing out the line you wanted to have, then moving
    the cursor to that line on the screen, adding "RETURN" and R, U, N and
    "RETURN" into the keyboard input buffer and telling the system the
    buffer has 5 CHARS in it, then ending the program, whereupon the system
    will enter that line you generated and then re-ran your program.

    Of course you have to write it so it can restart nicely on the second
    and upcoming runs, but with such a scheme, you could make a
    10 GOTO <runtimegenerated line here>
    thing actually work, at the cost of losing more or less all variables
    and state of course.

    But it was a nice trick.

    ---
    * Origin: nntp://news.fidonet.fi - Lake Ylo - Finland (2:221/6)
  • From Andreas Kohlbach@3:770/3 to Thomas Lake on Fri Apr 13 15:20:29 2018
    On Thu, 12 Apr 2018 18:41:56 -0700 (PDT), Thomas Lake wrote:

    On Wednesday, April 11, 2018 at 6:33:17 AM UTC-4, Shaun Bebbington wrote:
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X
    where X is a valid line number (i.e., LET X = 100). But I know
    that's not possible with Microsoft BASIC. Of course there is the ON
    X GO TO 100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC
    use this as a look up table". The following, I expected to go to the
    value in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    Thanks in advance.

    Shaun.

    You SHOULD get a syntax error. Commodore (Microsoft) BASIC is supposed
    to only allow numeric constants, not variables after GOTO and
    GOSUB.

    Yes. He might solve this with some IF statements.

    What do you actually see happening?

    I'd wonder if anything else than an error message.
    --
    Andreas

    My random toughts and comments
    https://news-commentaries.blogspot.com/

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Whammo@3:770/3 to All on Tue May 1 13:11:04 2018
    Try:

    on X goto

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Shaun Bebbington@3:770/3 to Whammo on Wed May 2 05:11:10 2018
    On Tuesday, 1 May 2018 21:11:06 UTC+1, Whammo wrote:
    Try:

    on X goto

    Yes I know.

    Thanks,

    Shaun.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Johann Klasek - swap last two domai@3:770/3 to Thomas Lake on Mon Jun 4 09:57:58 2018
    Thomas Lake <tlake@twcny.rr.com> wrote:
    On Wednesday, April 11, 2018 at 6:33:17 AM UTC-4, Shaun Bebbington wrote:
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X where X
    is a valid line number (i.e., LET X = 100). But I know that's not possible with
    Microsoft BASIC. Of course there is the ON X GO TO 100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use this as a look up table". The following, I expected to go to the value in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    Thanks in advance.

    Shaun.

    You SHOULD get a syntax error. Commodore (Microsoft) BASIC is supposed to
    only allow numeric constants, not variables after GOTO and GOSUB. What do you actually see happening?

    Not exactly how BASIC V2 parses it. GOTO parses all digits (ignoring
    blanks everywhere in between) and stops a the first non-digit character.
    In this case GOTO stops right before the FN token. So, the parsed line
    number is empty. The fallback (evaluation) for an empty line number
    argument is 0. Therefore GOTO jumps to line 0 and starts over.

    As others suggested already, one should use ON <expression> GOTO ... to
    use a calculated form of GOTO, or using a patched GOTO, or using the
    display containing a prepared GOTO<number> statement with keyboard
    buffer ... could go like this

    100 PRINT "{CLRSCR}{DOWN}{DOWN}GOTO "500+500"{HOME}";
    110 POKE631,13: REM RETURN INTO KEYBOARD BUFFER
    120 POKE198.1: REM KEYBOARD BUFFER LENGTH
    130 END: REM HERE
    1000 PRINT "WE REACHED LINE 1000"


    Johann

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Johann Klasek - swap last two domai@3:770/3 to Andreas Kohlbach on Mon Jun 4 10:12:59 2018
    Andreas Kohlbach <ank@spamfence.net> wrote:
    On Thu, 12 Apr 2018 18:41:56 -0700 (PDT), Thomas Lake wrote:
    [..]
    You SHOULD get a syntax error. Commodore (Microsoft) BASIC is supposed
    to only allow numeric constants, not variables after GOTO and
    GOSUB.

    Funny things can be done with GOTO/GOSUB parsing in MS-based BASIC
    variants. You may insert comment snippets to these commands to be more
    verbose on the destination etc. without fiddling around with REM, which
    turns the whole remaining line to comment.

    100 GOSUB 9500 OPEN FILE: GOSUB 8000 CHECK STATUS: PRINT "DONE"


    Johann

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Ed Vance@255:255/999 to All on Wed Apr 11 22:37:00 2018
    04-11-18 03:33 Shaun Bebbington wrote to All about Something strange going o Howdy! Shaun,

    @MSGID: <5ACE2329.2490.cbm@capitolcityonline.net>
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X
    where X is a valid line number (i.e., LET X = 100). But I know that's
    not possible with Microsoft BASIC. Of course there is the ON X GO TO 100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use this as a look up table". The following, I expected to go to the value
    in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    Thanks in advance.

    X isn't given a VALUE yet. I "think" (TM).



    ... Have you checked your smoke detector batteries & Fire Ext, LATELY?!

    --- SoupGate-Win32 v1.05
    * Origin: SpaceSST BBS Usenet <mccarragher.org> Fidonet Gateway (255:255/999)
  • From Janne Johansson@255:255/999 to All on Fri Apr 13 09:53:58 2018
    On 2018-04-11 02:33, Shaun Bebbington : All wrote:
    Hi,

    I found something odd today in the powerful CBM BASIC v2.0.

    Having worked with Sinclair BASIC quite a lot recently, I use GOTO X
    where X is a valid line number (i.e., LET X = 100). But I know that's
    not possible with Microsoft BASIC. Of course there is the ON X GO TO
    100,200 ...

    So I thought "I know, I'll try and use a function, could CBM BASIC use
    this as a look up table". The following, I expected to go to the value
    in the function A() which returns 10, but...

    0 DEF FN A(X) = 10
    1 PRINT FN A(0)
    2 GO TO FN A(0)
    3 PRINT "END GRACEFULLY"
    4 END
    10 PRINT "STOP"
    11 STOP

    Try it for yourself. What's going on here?

    BTW, I got reminded of someone devising a way to make selfmodifying
    BASIC on C64, by printing out the line you wanted to have, then moving
    the cursor to that line on the screen, adding "RETURN" and R, U, N and
    "RETURN" into the keyboard input buffer and telling the system the
    buffer has 5 CHARS in it, then ending the program, whereupon the system
    will enter that line you generated and then re-ran your program.

    Of course you have to write it so it can restart nicely on the second
    and upcoming runs, but with such a scheme, you could make a
    10 GOTO <runtimegenerated line here>
    thing actually work, at the cost of losing more or less all variables
    and state of course.

    But it was a nice trick.

    --- SoupGate-Win32 v1.05
    * Origin: SpaceSST BBS Usenet <mccarragher.org> Fidonet Gateway (255:255/999)