nendo 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/example/scratch.nnd +107 -49
- data/lib/init.nnd +429 -78
- data/lib/init.nndc +16939 -9197
- data/lib/nendo.rb +163 -53
- data/lib/rfc/json.nnd +1 -1
- data/lib/rfc/json.nndc +21 -6
- data/lib/srfi-1.nnd +9 -5
- data/lib/srfi-1.nndc +684 -626
- data/lib/srfi-2.nnd +42 -0
- data/lib/srfi-2.nndc +1350 -0
- data/lib/srfi-26.nnd +50 -0
- data/lib/srfi-26.nndc +4124 -0
- data/lib/text/html-lite.nndc +7 -1
- data/lib/util/list.nnd +184 -0
- data/lib/util/list.nndc +5453 -0
- data/test/{util-test.nnd → nendo-util-test.nnd} +4 -4
- data/test/nendo_spec.rb +136 -81
- data/test/srfi-1-test.nnd +8 -4
- data/test/srfi-2-test.nnd +63 -0
- data/test/srfi-26-test.nnd +89 -0
- data/test/syntax_spec.rb +200 -0
- data/test/util-list-test.nnd +178 -0
- metadata +16 -5
data/example/scratch.nnd
CHANGED
@@ -2,60 +2,118 @@
|
|
2
2
|
;; -----------------
|
3
3
|
(enable-idebug)
|
4
4
|
(disable-idebug)
|
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
|
-
|
5
|
+
(exit)
|
6
|
+
|
7
|
+
(debug-print-length)
|
8
|
+
(debug-print-length 2000)
|
9
|
+
|
10
|
+
(error "Error: (error) func test 1")
|
11
|
+
(error "Error: (error) func test 1" '(r a i s e))
|
12
|
+
|
13
|
+
|
14
|
+
(define (generic-member cmp obj lst)
|
15
|
+
(cond
|
16
|
+
((null? lst) #f)
|
17
|
+
((not (pair? lst)) #f)
|
18
|
+
((cmp obj (car lst)) lst)
|
19
|
+
(else (generic-member cmp obj (cdr lst)))))
|
20
|
+
|
21
|
+
|
22
|
+
(memq 'b '(a b c d))
|
23
|
+
(memq 'a '(a b c d . e))
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
;; :optional feature from Gauche-0.9.1 .
|
28
|
+
|
29
|
+
(define %expand-define-form-lambda
|
30
|
+
(lambda (arg body-list)
|
31
|
+
;; (define (func arg...) body)
|
32
|
+
(if (pair? (cdr arg))
|
33
|
+
(if (pair? (car (cdr arg)))
|
34
|
+
(error "Error: define syntax error.")))
|
35
|
+
(cons 'define
|
36
|
+
(list (car arg)
|
37
|
+
(%transform-optional-arguments (cdr arg) body-list)))))
|
38
|
+
|
39
|
+
|
40
|
+
(define (%transform-optional-arguments arg body-list)
|
41
|
+
(if-let1 rest-of-opts (memq :optional arg)
|
42
|
+
(let([opts '()]
|
43
|
+
[rest-of-opts (cdr rest-of-opts)]
|
44
|
+
[_rest (gensym)])
|
45
|
+
;; arguemnt form check
|
46
|
+
(for-each
|
47
|
+
(lambda (x)
|
48
|
+
(let1 syntax-is-ok (if (pair? x)
|
49
|
+
(= 2 (length x))
|
50
|
+
#f)
|
51
|
+
(unless syntax-is-ok
|
52
|
+
(error "Error: :optional format is illegal ... " arg))))
|
53
|
+
rest-of-opts)
|
54
|
+
(let loop ((arg arg))
|
55
|
+
(if (eq? :optional (car arg))
|
56
|
+
arg
|
57
|
+
(begin
|
58
|
+
(set! opts (cons (car arg) opts))
|
59
|
+
(loop (cdr arg)))))
|
60
|
+
(let1 new-arg (apply list* (append (reverse opts) (list _rest)))
|
61
|
+
(list 'lambda
|
62
|
+
new-arg
|
63
|
+
`(let
|
64
|
+
,rest-of-opts
|
65
|
+
,@(map
|
66
|
+
(lambda (k n)
|
67
|
+
`(when (< ,n (length ,_rest))
|
68
|
+
(set! ,(car k) (nth ,n ,_rest))))
|
69
|
+
rest-of-opts
|
70
|
+
(range (length rest-of-opts)))
|
71
|
+
,@body-list))))
|
72
|
+
`(lambda ,arg ,@body-list)))
|
41
73
|
|
74
|
+
|
75
|
+
(%transform-optional-arguments '(arg1 arg2)
|
76
|
+
'((begin 1 2)))
|
77
|
+
(pretty-print
|
78
|
+
(%transform-optional-arguments '(arg1 arg2 :optional (arg3 #f))
|
79
|
+
'((begin 1 2))))
|
80
|
+
|
81
|
+
(pretty-print
|
82
|
+
(%transform-optional-arguments '(arg1 arg2 :optional (arg3 #f) (arg4 #t))
|
83
|
+
'((begin 1 2))))
|
84
|
+
|
85
|
+
(pretty-print
|
86
|
+
(%transform-optional-arguments '(arg1 arg2 :optional illegal-arg (arg3 #f) (arg4 #t))
|
87
|
+
'((begin 1 2))))
|
42
88
|
(pretty-print
|
43
|
-
(
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
89
|
+
(%transform-optional-arguments '(arg1 arg2 :optional (arg3 #f) (arg4 #t) illegal-arg)
|
90
|
+
'((begin 1 2))))
|
91
|
+
(pretty-print
|
92
|
+
(%transform-optional-arguments '(arg1 arg2 :optional (arg3 #f) illegal-arg (arg4 #t))
|
93
|
+
'((begin 1 2))))
|
94
|
+
|
95
|
+
(pretty-print
|
96
|
+
(%transform-optional-arguments '(arg1 arg2 :optional (arg3 #f #f))
|
97
|
+
'((begin 1 2))))
|
49
98
|
|
50
|
-
(case (caddr '(a b 1 2))
|
51
|
-
((a) 'a)
|
52
|
-
((b) 'b)
|
53
|
-
((1) 1)
|
54
|
-
(else 'else))
|
55
99
|
|
56
|
-
|
100
|
+
(macroexpand
|
101
|
+
'(define (func arg1 arg2)
|
102
|
+
(begin
|
103
|
+
1
|
104
|
+
2)))
|
57
105
|
|
106
|
+
(pretty-print
|
107
|
+
(macroexpand
|
108
|
+
'(define (func arg1 arg2 :optional (arg3 #t))
|
109
|
+
(print "1")
|
110
|
+
(print "2"))))
|
58
111
|
|
112
|
+
(define (func arg1 arg2 :optional (arg3 #t))
|
113
|
+
(printf "[%d]" arg1)(newline)
|
114
|
+
(printf "[%d]" arg2)(newline)
|
115
|
+
(printf "[%s]" arg3)(newline))
|
116
|
+
|
117
|
+
(func 1 2 'a)
|
59
118
|
|
60
|
-
(exit)
|
61
119
|
|