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 CHANGED
@@ -2,60 +2,118 @@
2
2
  ;; -----------------
3
3
  (enable-idebug)
4
4
  (disable-idebug)
5
- (define debug-print-length 2000)
6
-
7
-
8
-
9
-
10
- (define case
11
- (macro (cond-exp . body)
12
- (define (case-block val . elem)
13
- (let1 block (car elem)
14
- (let ((cond-vals (car block))
15
- (body (cdr block)))
16
- (let1 v
17
- (if (eq? 'else cond-vals)
18
- cond-vals
19
- (cons 'or
20
- (map
21
- (lambda (x)
22
- `(eqv? (quote ,x) ,val))
23
- cond-vals)))
24
- `((,v
25
- ,@body))))))
26
-
27
- (define (case-iter val lst)
28
- (cond
29
- ((null? lst)
30
- '())
31
- ((eq? 1 (length lst))
32
- (case-block val (car lst)))
33
- (else
34
- (append (case-block val (car lst))
35
- (case-iter val (cdr lst))))))
36
-
37
- (let1 sym (gensym)
38
- `(let1 ,sym ,cond-exp
39
- (cond
40
- ,@(case-iter sym body))))))
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
- (macroexpand-1
44
- '(case (car '(a b c d))
45
- ((a) 'a)
46
- ((b) 'b)
47
- ((1) 1)
48
- (else 'else))))
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