TIP: Click on subject to list as thread! ANSI
echo: cbm
to: Thomas Lake
from: Johann Klasek - swap last two domai
date: 2018-06-04 09:57:58
subject: Re: Something strange going on.

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. 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  GOTO ... to
use a calculated form of GOTO, or using a patched GOTO, or using the
display containing a prepared GOTO 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 | FidoUsenet Gateway (3:770/3)
SEEN-BY: 57/0 116/102 153/150 250 226/20 317/2 3 393/68 633/267 280 640/384
SEEN-BY: 712/620 848 770/0 1 3 100 340 772/0 1 210 500
@PATH: 770/3 1 712/848 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.