-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.scm
54 lines (40 loc) · 1.34 KB
/
helpers.scm
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
(define (call f x) (f x))
(define (two-crossproduct a b)
(flatten-one-layer
(map
(lambda (a-el)
(map
(lambda (b-el) (cons a-el b-el))
b))
a)))
(define (crossproduct lists)
(fold-right two-crossproduct (list (list)) lists))
(define (identity x) x)
(define (flatten-one-layer list-of-lists) (apply append list-of-lists))
(define (get-name f)
(if (equal? (get-name-proc f) '|#[unnamed-procedure]|)
(get-name-search f)
(get-name-proc f)))
(define (get-name-proc f)
(if (list? f)
(string->symbol (apply string-append (map (compose symbol->string get-name) f)))
(car (lambda-components* (procedure-lambda f) list))))
(define (get-name-search f)
(if (list? f)
(map get-name f)
(let ((matches (filter
(lambda (el) (and (> (length el) 1) (eq? (car (cdr el)) f)))
(environment-bindings user-initial-environment))))
(if (>= (length matches) 1)
(car (car matches))
'missing-name-in-get-name-lookup))))
(define write
(lambda args
(write-line
(apply string-append
(map (lambda (x) (string-append (string x) " ")) args)))))
(define (reverse items)
(fold-right (lambda (x r) (append r (list x))) '() items))
(define (boolean->string val) (if val "#t" "#f"))
(define (alist:keys alist) (map car alist))
(define (always-true x) #t)