File: loop.scm

package info (click to toggle)
scheme48 1.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 14,980 kB
  • ctags: 14,127
  • sloc: lisp: 76,272; ansic: 71,514; sh: 3,026; makefile: 637
file content (54 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download | duplicates (4)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
; Copyright (c) 1993-2008 by Richard Kelsey.  See file COPYING.



(xodd? 10)
(xodd? 5)

(define-local-syntax (define-primitive id nargs)
  (let ((args (reverse (list-tail '(z y x) (- '3 nargs)))))
    `(define (,id . ,args)
       (call-primitively ,id . ,args))))

(define-primitive + 2)
(define-primitive - 2)
(define-primitive * 2)
(define-primitive < 2)
(define-primitive = 2)

(define (xodd? x)
  (cond ((= 0 x)
	 #f)
	((< 100 x)                  ; efficiency hack
	 (goto odd? (- x 100)))
	((< 1000 x)                  ; efficiency hack
	 (goto xodd? (- x 100)))
	(else
	 (goto xeven? (- x 1)))))

(define (xeven? x)
  (cond ((= 0 x)
	 #t)
	((< 100 x)                  ; efficiency hack
	 (goto xeven? (- x 100)))
	(else
	 (goto xodd? (- x 1)))))


(define (odd? x)
  (cond ((= 0 x)
	 #f)
	((< 100 x)                  ; efficiency hack
	 (goto odd? (- x 100)))
	(else
	 (goto even? (- x 1)))))

(define (even? x)
  (cond ((= 0 x)
	 #t)
	((< 100 x)                  ; efficiency hack
	 (goto even? (- x 100)))
	(else
	 (goto odd? (- x 1)))))