nendo 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Rakefile +20 -18
- data/VERSION.yml +1 -1
- data/lib/nendo/init.nndc +269 -269
- data/lib/nendo/nendo/experimental.nnd +69 -1
- data/lib/nendo/nendo/experimental.nndc +1814 -933
- data/lib/nendo/nendo/test.nndc +16 -16
- data/lib/nendo/rfc/json.nndc +6 -6
- data/lib/nendo/ruby/builtin_functions.rb +2 -0
- data/lib/nendo/ruby/core.rb +1 -1
- data/lib/nendo/ruby/printer.rb +2 -0
- data/lib/nendo/srfi-1.nnd +20 -5
- data/lib/nendo/srfi-1.nndc +1814 -1706
- data/lib/nendo/srfi-2.nndc +154 -154
- data/lib/nendo/srfi-26.nndc +433 -433
- data/lib/nendo/text/html-lite.nndc +46 -46
- data/lib/nendo/util/combinations.nndc +213 -213
- data/lib/nendo/util/list.nndc +294 -294
- data/lib/nendo/util/match.nnd +1 -1
- data/lib/nendo/util/match.nndc +5724 -5724
- data/test/nendo-util-test.nnd +121 -0
- data/test/nendo_spec.rb +5 -0
- data/test/rspec_formatter_for_emacs.rb +1 -0
- metadata +66 -17
@@ -32,6 +32,37 @@
|
|
32
32
|
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
33
33
|
;;;
|
34
34
|
|
35
|
+
;; for nendo.lazy
|
36
|
+
(define *ruby-lazy-enabled-platform*
|
37
|
+
(let ((arr (. Array new)))
|
38
|
+
(arr.respond_to? (. "lazy" to_sym)))) ;; Check the Emumerable#lazy method
|
39
|
+
(define (ruby-lazy-enabled-platform?) *ruby-lazy-enabled-platform*)
|
40
|
+
|
41
|
+
|
42
|
+
(define (ruby-lazy enumerable)
|
43
|
+
(if (and (ruby-lazy-enabled-platform?)
|
44
|
+
(enumerable.is_a? Enumerable))
|
45
|
+
(. enumerable lazy)
|
46
|
+
enumerable))
|
47
|
+
|
48
|
+
(define (ruby-lazy? v)
|
49
|
+
(if (ruby-lazy-enabled-platform?)
|
50
|
+
(v.is_a? Enumerator::Lazy)
|
51
|
+
#f))
|
52
|
+
|
53
|
+
(define (vector? v)
|
54
|
+
(or (v.is_a? Array)
|
55
|
+
(ruby-lazy? v)))
|
56
|
+
|
57
|
+
(define (vector->list v)
|
58
|
+
(let1 v (if (ruby-lazy? v)
|
59
|
+
(v.to_a)
|
60
|
+
v)
|
61
|
+
v.to_list))
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
35
66
|
|
36
67
|
;; Checking (Ruby's Enumerable?) and (not Nendo's list?)
|
37
68
|
(define (%%enumerable? x)
|
@@ -88,10 +119,33 @@
|
|
88
119
|
(%filter-original proc lst)))
|
89
120
|
|
90
121
|
|
122
|
+
(define (%%fold-able? proc knil lst)
|
123
|
+
(%%enumerable? lst))
|
124
|
+
|
125
|
+
(define (%%fold proc knil vec)
|
126
|
+
(vec.inject knil
|
127
|
+
(&block (result item)
|
128
|
+
(proc item result))))
|
129
|
+
|
130
|
+
(define (%fold-original proc knil lis1)
|
131
|
+
(define (null-list? l)
|
132
|
+
(cond ((pair? l) #f)
|
133
|
+
((null? l) #t)
|
134
|
+
(else (error "null-list?: argument out of domain" l))))
|
135
|
+
(check-arg procedure? proc %fold-original)
|
136
|
+
(let lp ((lis lis1) (ans knil))
|
137
|
+
(if (null-list? lis) ans
|
138
|
+
(lp (cdr lis) (proc (car lis) ans)))))
|
139
|
+
|
140
|
+
(define (%fold proc knil lst)
|
141
|
+
(if (%%fold-able? proc knil lst)
|
142
|
+
(%%fold proc knil lst)
|
143
|
+
(%fold-original proc knil lst)))
|
144
|
+
|
91
145
|
(define map %map)
|
92
146
|
(define for-each %for-each)
|
93
147
|
(define filter %filter)
|
94
|
-
|
148
|
+
(define fold %fold)
|
95
149
|
|
96
150
|
|
97
151
|
;; dis-assembler
|
@@ -197,3 +251,17 @@
|
|
197
251
|
(raise nendo-syntax-error "let1 requires (let1 var expr body ...) form."))
|
198
252
|
((let1 var expr body ...)
|
199
253
|
(%let ((var expr)) body ...))))
|
254
|
+
|
255
|
+
|
256
|
+
(define (readlines io)
|
257
|
+
(if (not (io.is_a? IO))
|
258
|
+
(raise ArgumentError "readlines expects IO object.")
|
259
|
+
(map
|
260
|
+
(lambda (x) (x.chomp))
|
261
|
+
(ruby-lazy (io.each_line)))))
|
262
|
+
|
263
|
+
|
264
|
+
(define (readchars io)
|
265
|
+
(if (not (io.is_a? IO))
|
266
|
+
(raise ArgumentError "readlines expects IO object.")
|
267
|
+
(ruby-lazy (io.each_char))))
|