From b1a7b9e9cefbc27dec887065444badea57b489a4 Mon Sep 17 00:00:00 2001 From: Tobias Leichtfried Date: Fri, 2 Apr 2021 14:09:40 +0200 Subject: [PATCH 1/2] ntimes --- testdata/nTimes.scm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 testdata/nTimes.scm diff --git a/testdata/nTimes.scm b/testdata/nTimes.scm new file mode 100644 index 0000000..974fe27 --- /dev/null +++ b/testdata/nTimes.scm @@ -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)))) \ No newline at end of file From a30ef4f0801e45ab1a2f5d0cc285e52504576e03 Mon Sep 17 00:00:00 2001 From: Tobias Leichtfried Date: Fri, 2 Apr 2021 14:11:13 +0200 Subject: [PATCH 2/2] delete ntimes.scheme --- testdata/nTimes.scheme | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 testdata/nTimes.scheme diff --git a/testdata/nTimes.scheme b/testdata/nTimes.scheme deleted file mode 100644 index b794bcc..0000000 --- a/testdata/nTimes.scheme +++ /dev/null @@ -1,17 +0,0 @@ -(define continuation) -(define counter 0) - -(define (nTimes times func x) - (set! counter (+ counter 1)) - (if (> times 0) - (nTimes (- times 1) func (func x)) - x)) - -(define (pow2AndStore8 x) - (let - ( (maybeNum (call/cc (lambda (c) (if (= x 8) (set! continuation c))))) ) - (if (number? maybeNum) maybeNum (* 2 x)))) - -(write-string (number->string (nTimes 5 pow2AndStore8 1))) -(newline) -(if (= counter 6) (write-string (number->string (continuation 5)))) \ No newline at end of file