File: cpstak.sc

package info (click to toggle)
stalin 0.11-6
  • links: PTS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 110,396 kB
  • ctags: 163,122
  • sloc: ansic: 1,757,574; lisp: 88,332; sh: 1,514; makefile: 229; sed: 100; csh: 30
file content (35 lines) | stat: -rw-r--r-- 954 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; File:         cpstak.sc
;;; Description:  continuation-passing version of TAK
;;; Author:       Will Clinger
;;; Created:      20-Aug-87
;;; Modified:     21-Mar-94 (Qobi)
;;;               31-Mar-98 (Qobi)
;;; Language:     Scheme
;;; Status:       Public Domain
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; CPSTAK -- A continuation-passing version of the TAK benchmark.
;;; A good test of first class procedures and tail recursion.

(define (cpstak x y z)
 (define (tak x y z k)
  (if (not (< y x))			;Qobi: avoid temptation to optimize
      (k z)
      (tak (- x 1)
	   y
	   z
	   (lambda (v1)
	    (tak (- y 1)
		 z
		 x
		 (lambda (v2)
		  (tak (- z 1)
		       x
		       y
		       (lambda (v3) (tak v1 v2 v3 k)))))))))
 (tak x y z (lambda (a) a)))

(do ((i 0 (+ i 1))) ((= i 1000))
 (write (cpstak 18 12 6))
 (newline))