File: case.pal

package info (click to toggle)
auto-editor 26.3.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 884 kB
  • sloc: python: 8,445; xml: 68; javascript: 27; makefile: 26
file content (34 lines) | stat: -rw-r--r-- 979 bytes parent folder | download
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
#!/usr/bin/env auto-editor palet

#lang palet

(assert (equal? (case (+ 7 5) [(1 2 3) 'small] [(10 11 12) 'big]) 'big))
(assert (equal? (case (- 7 5) [(1 2 3) 'small] [(10 11 12) 'big]) 'small))
(assert (case (mod 3 2) [(0) #f] [else #t]))
(assert (case 'y [(y) #t]))


(define/c (read-tb-ntsc [tb int?] [ntsc bool?] -> frac?)
    (if ntsc
        (cond
            ((= tb 24) 24000/1001)
            ((= tb 30) 30000/1001)
            ((= tb 60) 60000/1001)
            (else (* tb 999/1000))
        )
        (* tb 1/1)
    )
)

(assert (equal? (read-tb-ntsc 3 #f) 3/1))
(assert (equal? (read-tb-ntsc 3 #t) 2997/1000))
(assert (equal? (read-tb-ntsc 30 #f) 30/1))
(assert (equal? (read-tb-ntsc 30 #t) 30000/1001))

(assert (not (keyword? 3)))
(assert (not (keyword? #(3 4))))
(assert (not (keyword? 'define)))
(assert (keyword? '#:hello))
(assert (equal? (keyword->string '#:hello) "hello"))
(assert (equal? (string->keyword "hello") '#:hello))
(assert (equal? '(3 4) '(3 4)))