Skip to content

Commit

Permalink
Merge pull request #22 from metamorph-scheme/TL/ntimes.scm
Browse files Browse the repository at this point in the history
ntimes
  • Loading branch information
rapgru authored Apr 2, 2021
2 parents 9efcd83 + a30ef4f commit 6da13dc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
17 changes: 0 additions & 17 deletions testdata/nTimes.scheme

This file was deleted.

17 changes: 17 additions & 0 deletions testdata/nTimes.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(define continuation)
(define counter 0)

(define (n-times times func x)
(set! counter (+ counter 1))
(if (> times 0)
(n-times (- times 1) func (func x))
x))

(define (mul2-store8 x)
(let ((maybe-num
(call/cc (lambda (c) (if (= x 8) (set! continuation c))))))
(* 2 (if (number? maybe-num) maybe-num x))))

(write-string (number->string (n-times 4 mul2-store8 1)))
(newline)
(if (= counter 5) (write-string (number->string (continuation 5))))

0 comments on commit 6da13dc

Please sign in to comment.