But does it work? Let’s start with the all-time BASIC favorite:
℘
10 print "HELLO WORLD!"
20 goto 10
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
HELLO WORLD!
···
Let’s also try our original sample program, which was designed to cause extra grief for the tokenizer and the parser:
#lang basic
30 rem print 'ignored'
35
50 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5 rem ignored
10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end
one
three
4
Let’s also see how our source locations worked out. Suppose we change line number 50 to be 30:
#lang basic
30 rem print 'ignored'
35
30 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5
10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end
DrRacket will raise the error we’d expect it to when it finds conflicting definitions, and the offending line is highlighted correctly:
Let’s switch it back, and see what happens if we introduce a bogus line number in the last goto:
#lang basic
30 rem print 'ignored'
35
50 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5
10 print "o" ; "n" ; "e"
20 print : goto 6000.0 : end
error in line 20: line 6000 not found
A side effect of making our lines into functions is that they’re available in the DrRacket REPL like any other function. For instance:
> (line-10)
one
> (line-60)
three
4
> (line-70)
uncaught exception: #<change-line-signal>
This last result makes sense: we’re trying to execute a goto outside the context of the program loop.