pull/2/head
Matthew Butterick 9 years ago
parent 83a1090754
commit 6ad59477cd

@ -11,7 +11,7 @@
80 PRINT"IF YOU DO NOT WANT TO BET, INPUT A 0" 80 PRINT"IF YOU DO NOT WANT TO BET, INPUT A 0"
100 N=100 100 N=100
110 Q=100 110 Q=100
120 PRINT "YOU NOW HAVE";Q;"DOLLARS." 120 PRINT "YOU NOW HAVE ";Q;" DOLLARS."
130 PRINT 130 PRINT
140 GOTO 260 140 GOTO 260
210 Q=Q+M 210 Q=Q+M

@ -66,7 +66,7 @@
(set! return-stack (cons return-k return-stack)) (set! return-stack (cons return-k return-stack))
(basic:goto where))) (basic:goto where)))
(struct $line (number thunk) #:transparent) (struct $line (number thunk))
(define-macro (line NUMBER . STATEMENTS) (define-macro (line NUMBER . STATEMENTS)
#'($line NUMBER (λ () (with-handlers ([end-line-signal? (λ _ #f)]) #'($line NUMBER (λ () (with-handlers ([end-line-signal? (λ _ #f)])
. STATEMENTS)))) . STATEMENTS))))
@ -168,19 +168,16 @@
#'(basic:for VAR START-VALUE END-VALUE 1)] #'(basic:for VAR START-VALUE END-VALUE 1)]
[(_ VAR START-VALUE END-VALUE STEP-VALUE) [(_ VAR START-VALUE END-VALUE STEP-VALUE)
#'(begin #'(begin
;; initialize the loop counter (statement VAR "=" START-VALUE) ; initialize the loop counter
(statement VAR "=" START-VALUE) (let/cc return-k ; create a return point
;; create a point for the `next` statement to return to, using a continuation
(let/cc return-point-for-next
(push-for-stack (cons 'VAR (push-for-stack (cons 'VAR
(procedure-rename (λ () ; thunk that increments counter & teleports back to beginning of loop
(λ () ; thunk that increments counter & teleports back to beginning of loop (define next-val (+ VAR STEP-VALUE))
(define next-val (+ VAR STEP-VALUE)) (if (<= next-val END-VALUE)
(if (<= next-val END-VALUE) (begin
(begin (set! VAR next-val)
(set! VAR next-val) (return-k #f)) ; return value for subsequent visits to line
(return-point-for-next #f)) ; return value for subsequent visits to line (pop-for-stack)))))
(pop-for-stack))) (format-datum "~a-incrementer" 'VAR))))
#f))]) ; return value for first visit to line #f))]) ; return value for first visit to line
(define (handle-next [which #f]) (define (handle-next [which #f])

Loading…
Cancel
Save