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

@ -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-point-for-next #f)) ; return value for subsequent visits to line (return-k #f)) ; return value for subsequent visits to line
(pop-for-stack))) (format-datum "~a-incrementer" 'VAR)))) (pop-for-stack)))))
#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