Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Commodore » Commodore 8-bit » Something strange going on.
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Something strange going on. [message #366235] Wed, 11 April 2018 06:33 Go to next message
Anonymous
Karma:
Originally posted by: Shaun Bebbington

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.
Re: Something strange going on. [message #366236 is a reply to message #366235] Wed, 11 April 2018 07:05 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Shaun Bebbington

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.
Re: Something strange going on. [message #366237 is a reply to message #366235] Wed, 11 April 2018 08:34 Go to previous messageGo to next message
wwww.leser is currently offline  wwww.leser
Messages: 21
Registered: March 2013
Karma: 0
Junior Member
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
Re: Something strange going on. [message #366245 is a reply to message #366235] Wed, 11 April 2018 14:55 Go to previous messageGo to next message
wwww.leser is currently offline  wwww.leser
Messages: 21
Registered: March 2013
Karma: 0
Junior Member
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.
Something strange going o [message #366258 is a reply to message #366235] Wed, 11 April 2018 06:37 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: nospam.Ed.Vance

04-11-18 03:33 Shaun Bebbington wrote to All about Something strange going o
Howdy! Shaun,

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

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

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

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

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

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

SB> Thanks in advance.

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



.... Have you checked your smoke detector batteries & Fire Ext, LATELY?!
Re: Something strange going on. [message #366273 is a reply to message #366235] Thu, 12 April 2018 21:41 Go to previous messageGo to next message
Tom Lake is currently offline  Tom Lake
Messages: 450
Registered: May 2012
Karma: 0
Senior Member
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?
Something strange going on. [message #366279 is a reply to message #366235] Thu, 12 April 2018 17:53 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: nospam.Janne.Johansson

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.
Re: Something strange going on. [message #367185 is a reply to message #366235] Tue, 01 May 2018 16:11 Go to previous messageGo to next message
Whammo is currently offline  Whammo
Messages: 31
Registered: August 2012
Karma: 0
Member
Try:

on X goto
Re: Something strange going on. [message #367208 is a reply to message #367185] Wed, 02 May 2018 08:11 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Shaun Bebbington

On Tuesday, 1 May 2018 21:11:06 UTC+1, Whammo wrote:
> Try:
>
> on X goto

Yes I know.

Thanks,

Shaun.
Re: Something strange going on. [message #368573 is a reply to message #366273] Mon, 04 June 2018 05:57 Go to previous messageGo to next message
Anonymous
Karma:
Originally posted by: Johann Klasek - swap last two domainparts

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
Re: Something strange going on. [message #368574 is a reply to message #366235] Mon, 04 June 2018 06:12 Go to previous message
Anonymous
Karma:
Originally posted by: Johann Klasek - swap last two domainparts

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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Printing on Commodore printer without Commodore 64
Next Topic: Commodore 64 BASIC upgrades?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Apr 19 20:17:27 EDT 2024

Total time taken to generate the page: 0.06952 seconds