File: test.scm

package info (click to toggle)
source-highlight 3.1.8-1.2~deb9u1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 10,224 kB
  • sloc: sh: 11,709; cpp: 10,226; ansic: 9,521; makefile: 1,902; lex: 1,200; yacc: 1,021; php: 213; perl: 211; awk: 98; erlang: 94; lisp: 90; java: 75; ruby: 69; python: 61; asm: 43; ada: 36; ml: 29; haskell: 27; xml: 23; cs: 11; sql: 8; tcl: 7; sed: 4
file content (95 lines) | stat: -rw-r--r-- 2,089 bytes parent folder | download | duplicates (7)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#|
multiline
comment
|#

"string with special \n \t chars"

; comment
(define (fn a)
  (let* ((b (+ a 1)))
    (if (= a 1)
        #t
        #f))) ;; another comment

(define c (lambda (x)
            (let loop ((i 0))
              (unless (= i 10)
                      ;; print some chars
                      (display #\' #\#)
                      (loop (+ i 1))))))

((if (= 0 0) * +) 5 2)

;; numbers
(define pi 3.14159)

(define circle-area
    (lambda (radius)
      (* pi radius radius)))

(define (circle-area radius)
    (* pi radius radius))

(define (blah)
  (define (foo) 55)
  (define (woo) 42)
  (+ (foo) (woo)))

(define (repeat-forever)
  (display "I will not play with Scheme in class.")
  (repeat-forever))

(define (all-atoms-are-numeric? tree)
  (call-with-current-continuation
   (lambda (return)                     ;bind RETURN to the current cont

     (define (walk tree)
       (cond ((null? tree))
             ((pair? tree)              ;pair? is like consp
              (walk (car tree))
              (walk (cdr tree)))
             ((number? tree))
             (else (return #f))))       ;found a non-number -- return false

     (walk tree)
     #t)))                              ;else return true


(cond ((number? x) "A number.")
      ((string? x) "A string.")
      (else "Beats me!"))

(cond ((assoc key a-list) => cdr)
      (else #f))


(letrec ((even? (lambda (n) (if (= n 0) #t (odd? (- n 1)))))
         (odd?  (lambda (n) (if (= n 0) #f (even? (- n 1))))))
  (even? 42))


(let counting ((n 10))
  (cond ((< 0 n)
         (write n)
         (counting (- n 1)))))


(define (list . arguments) arguments)

(define-syntax my-or
  (syntax-rules ()
    ((my-or) #f)
    ((my-or e) e)
    ((my-or e1 e2 ...)
     (let ((temp e1))
       (if temp temp (my-or e2 ...))))))

(define-syntax syntax-rules
  (lambda (x)
    (syntax-case x ()
      ((_ (i ...) ((keyword . pattern) template) ...)
       (syntax (lambda (x)
                 (syntax-case x (i ...)
                   ((dummy . pattern) (syntax template))
                   ...)))))))