-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcj-env-1--include.scm
98 lines (79 loc) · 2.11 KB
/
cj-env-1--include.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
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
96
97
98
;;; Copyright 2010-2018 by Christian Jaeger <ch@christianjaeger.ch>
;;; This file is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License (GPL) as published
;;; by the Free Software Foundation, either version 2 of the License, or
;;; (at your option) any later version.
;; no require form, included in cj-source.scm
(define (inc-function n)
(declare (fixnum))
(+ n 1))
(define (dec-function n)
(declare (fixnum))
(- n 1))
(define (parameter-inc! p)
(let ((x (inc-function (p))))
(p x)
x))
(define (parameter-dec! p)
(let ((x (dec-function (p))))
(p x)
x))
(define (parameter-add! p x)
(let ((x (+ (p) x)))
(p x)
x))
(define (parameter-update! p fn)
(let ((x (fn (p))))
(p x)
x))
(define (parameter-push! p v)
(let ((x (cons v (p))))
(p x)
x))
;; this one deviates from the above in that its return value is used
;; for the "primary purpose":
(define (parameter-pop! p)
(let ((l (p)))
(p (cdr l))
(car l)))
(define (list-join lis val #!optional (tail '()))
;; copy to avoid circular dependency
(define (null-list? l)
(cond ((pair? l) #f)
((null? l) #t)
(else (error "null-list?: argument out of domain" l))))
(define (fold-right kons knil lis1)
(let recur ((lis lis1)) ; Fast path
(if (null-list? lis) knil
(let ((head (car lis)))
(kons head (recur (cdr lis)))))))
;;/copy
(if (null? lis)
tail
(cons (car lis)
(fold-right (lambda (v l)
(cons val (cons v l)))
tail
(cdr lis)))))
(define (scm:object->string v)
(parameterize ((current-readtable
(readtable-max-write-level-set
(readtable-max-write-length-set
(current-readtable)
12)
6)))
(object->string v)))
(define (scm:objects->string objs
#!key
(prepend #f) ;; maybe type, *or* boolean
(separator " "))
(apply string-append
(let ((m (list-join
(map scm:object->string
objs)
separator)))
(if (and prepend (pair? objs))
(cons (if (string? prepend) prepend separator) m)
m))))
(define (identity x)
x)