nendo 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/emacs/nendo-mode.el +2 -0
- data/lib/init.nnd +51 -35
- data/lib/init.nndc +3371 -2920
- data/lib/nendo.rb +463 -194
- data/lib/srfi-2.nndc +48 -165
- data/lib/srfi-26.nndc +142 -511
- data/lib/text/html-lite.nndc +23 -1
- data/lib/util/combinations.nnd +290 -0
- data/lib/util/combinations.nndc +7218 -0
- data/lib/util/list.nndc +138 -387
- data/lib/util/match.nnd +672 -0
- data/lib/util/match.nndc +81024 -0
- data/test/match-test.nnd +186 -0
- data/test/nendo-util-test.nnd +5 -7
- data/test/nendo_spec.rb +697 -235
- data/test/syntax_spec.rb +561 -52
- data/test/util-combinations-test.nnd +383 -0
- metadata +9 -4
- data/example/scratch.nnd +0 -119
data/emacs/nendo-mode.el
CHANGED
data/lib/init.nnd
CHANGED
@@ -61,8 +61,8 @@
|
|
61
61
|
|
62
62
|
(define %expand-define-form
|
63
63
|
(lambda (arg-and-body)
|
64
|
-
(let ((arg (car arg-and-body))
|
65
|
-
|
64
|
+
(%let ((arg (car arg-and-body))
|
65
|
+
(body (cdr arg-and-body)))
|
66
66
|
;; (define (func arg...) body)
|
67
67
|
(if (not (pair? arg))
|
68
68
|
;; (define var body)
|
@@ -168,15 +168,20 @@
|
|
168
168
|
(lambda str-lst
|
169
169
|
(string-join str-lst "")))
|
170
170
|
|
171
|
+
(define (string=? a b)
|
172
|
+
(eq? a b))
|
171
173
|
|
172
174
|
;; ----------------------------------------
|
173
175
|
;; basic forms
|
174
176
|
;; ----------------------------------------
|
175
177
|
(define (macroexpand sexp)
|
176
|
-
(let ((newsexp (macroexpand-1 sexp)))
|
177
|
-
|
178
|
-
|
179
|
-
|
178
|
+
(%let ((newsexp (macroexpand-1 sexp)))
|
179
|
+
(if (not (equal? sexp newsexp))
|
180
|
+
(macroexpand newsexp)
|
181
|
+
(strip-let-syntax-keyword
|
182
|
+
(strip-syntax-quote
|
183
|
+
newsexp)))))
|
184
|
+
|
180
185
|
|
181
186
|
(define (feedto)
|
182
187
|
(error "=> (feedto) appeared outside cond or case."))
|
@@ -185,9 +190,9 @@
|
|
185
190
|
(macro lst
|
186
191
|
(letrec ((case-block
|
187
192
|
(lambda (elem . elseblock)
|
188
|
-
(let ((condition (if (eq? 'else (car elem))
|
189
|
-
|
190
|
-
|
193
|
+
(%let ((condition (if (eq? 'else (car elem))
|
194
|
+
true
|
195
|
+
(car elem)))
|
191
196
|
(body (if (null? (cdr elem))
|
192
197
|
'(#t)
|
193
198
|
(cdr elem)))
|
@@ -221,7 +226,7 @@
|
|
221
226
|
(define let1
|
222
227
|
(macro (var expr . body)
|
223
228
|
(append
|
224
|
-
(list 'let (list (list var expr)))
|
229
|
+
(list '%let (list (list var expr)))
|
225
230
|
body)))
|
226
231
|
|
227
232
|
(define or
|
@@ -375,8 +380,8 @@
|
|
375
380
|
(second x))
|
376
381
|
(second lst))))
|
377
382
|
|
378
|
-
;;
|
379
|
-
`(let ,@lst))))
|
383
|
+
;; trasform to internal let syntax (%let)
|
384
|
+
`(%let ,@lst))))
|
380
385
|
|
381
386
|
(define if-let1
|
382
387
|
(macro (var _expr _then . _else)
|
@@ -384,6 +389,10 @@
|
|
384
389
|
(if ,var ,_then ,@_else))))
|
385
390
|
|
386
391
|
|
392
|
+
(define push!
|
393
|
+
(macro (_lst _val)
|
394
|
+
`(set! ,_lst (append (list ,_val) ,_lst))))
|
395
|
+
|
387
396
|
;; ----------------------------------------
|
388
397
|
;; errorf
|
389
398
|
;; ----------------------------------------
|
@@ -541,9 +550,9 @@
|
|
541
550
|
(define (%internal-define-to-letrec _sym _src)
|
542
551
|
(if (not (list? (cadr _src)))
|
543
552
|
`(,_sym ,@_src)
|
544
|
-
(let ((body (cdr _src))
|
545
|
-
|
546
|
-
|
553
|
+
(%let ((body (cdr _src))
|
554
|
+
(defs '())
|
555
|
+
(rest '()))
|
547
556
|
(if (not (list? (car body)))
|
548
557
|
`(,_sym ,@_src)
|
549
558
|
(begin
|
@@ -554,8 +563,8 @@
|
|
554
563
|
(set! defs (cons (%expand-define-form (cdr x)) defs))
|
555
564
|
(set! rest (cons x rest))))
|
556
565
|
body)
|
557
|
-
(let ((defs (reverse defs))
|
558
|
-
|
566
|
+
(%let ((defs (reverse defs))
|
567
|
+
(rest (reverse rest)))
|
559
568
|
(if (< 0 (length defs))
|
560
569
|
`(,_sym
|
561
570
|
,(car _src)
|
@@ -872,7 +881,7 @@
|
|
872
881
|
(define (cons* arg . args)
|
873
882
|
(if (null? args)
|
874
883
|
arg
|
875
|
-
(cons arg (apply
|
884
|
+
(cons arg (apply cons* args))))
|
876
885
|
(define list* cons*)
|
877
886
|
|
878
887
|
|
@@ -1304,11 +1313,11 @@
|
|
1304
1313
|
|
1305
1314
|
|
1306
1315
|
;; ----------------------------------------
|
1307
|
-
;; tail
|
1316
|
+
;; tail call optimization
|
1308
1317
|
;; ----------------------------------------
|
1309
|
-
(define (setup
|
1318
|
+
(define (%setup-%tailcall-mark sexp)
|
1310
1319
|
(define (reserved? sym)
|
1311
|
-
(let* ([reserved-orig '(quote syntax-quote macro %syntax begin lambda if let letrec define define-syntax)]
|
1320
|
+
(let* ([reserved-orig '(quote syntax-quote macro %syntax begin lambda if %let letrec define define-syntax)]
|
1312
1321
|
[reserved (append reserved-orig
|
1313
1322
|
(map
|
1314
1323
|
(lambda (orig)
|
@@ -1324,7 +1333,7 @@
|
|
1324
1333
|
(list name
|
1325
1334
|
(if (list? body)
|
1326
1335
|
(if (reserved? (car body))
|
1327
|
-
(setup
|
1336
|
+
(%setup-%tailcall-mark body)
|
1328
1337
|
body)
|
1329
1338
|
body))))
|
1330
1339
|
args))
|
@@ -1336,7 +1345,7 @@
|
|
1336
1345
|
((and (list? sexp)
|
1337
1346
|
(< 0 (length sexp)))
|
1338
1347
|
(if (reserved? (car sexp))
|
1339
|
-
(setup
|
1348
|
+
(%setup-%tailcall-mark sexp)
|
1340
1349
|
(if (pair? (car sexp))
|
1341
1350
|
sexp ;; e.g. ((lambda (x) ...)
|
1342
1351
|
`(%tailcall ,sexp))))
|
@@ -1356,7 +1365,7 @@
|
|
1356
1365
|
(cons
|
1357
1366
|
(if (reserved? (car last))
|
1358
1367
|
;; recursive
|
1359
|
-
(setup
|
1368
|
+
(%setup-%tailcall-mark last)
|
1360
1369
|
;; this is the tailcall!
|
1361
1370
|
`(%tailcall ,last))
|
1362
1371
|
other))))))
|
@@ -1395,7 +1404,7 @@
|
|
1395
1404
|
,(second sexp)
|
1396
1405
|
,(setup-proc (third sexp))
|
1397
1406
|
,(setup-proc (fourth sexp))))))
|
1398
|
-
((let /nendo/core
|
1407
|
+
((%let /nendo/core/%let)
|
1399
1408
|
`(,_car
|
1400
1409
|
,(setup-let-args (second sexp))
|
1401
1410
|
,@(setup-proc-body (cddr sexp))))
|
@@ -1410,7 +1419,7 @@
|
|
1410
1419
|
,(if (and (list? val)
|
1411
1420
|
(not (null? val))
|
1412
1421
|
(reserved? (car val)))
|
1413
|
-
(setup
|
1422
|
+
(%setup-%tailcall-mark val)
|
1414
1423
|
val))))
|
1415
1424
|
((set! /nendo/core/set!)
|
1416
1425
|
(let1 val (third sexp)
|
@@ -1419,7 +1428,7 @@
|
|
1419
1428
|
,(if (and (list? val)
|
1420
1429
|
(not (null? val))
|
1421
1430
|
(reserved? (car val)))
|
1422
|
-
(setup
|
1431
|
+
(%setup-%tailcall-mark val)
|
1423
1432
|
val))))
|
1424
1433
|
(else
|
1425
1434
|
(if (symbol? (car sexp))
|
@@ -1429,29 +1438,29 @@
|
|
1429
1438
|
sexp)))
|
1430
1439
|
|
1431
1440
|
|
1441
|
+
|
1432
1442
|
;; definition of 'compile-phase'
|
1433
1443
|
(set! %compile-phase-functions
|
1434
1444
|
(list
|
1435
|
-
setup
|
1445
|
+
%setup-%tailcall-mark
|
1436
1446
|
))
|
1437
1447
|
|
1438
1448
|
|
1439
|
-
|
1440
1449
|
;; explicit renameing macro transformer
|
1441
1450
|
;; ported from chibi-scheme-0.3 by Kiyoka Nishiyama
|
1442
1451
|
;;
|
1443
1452
|
;; URL: http://community.schemewiki.org/?syntactic-closures
|
1444
1453
|
;;
|
1445
|
-
(define (strip-syntactic-closures expr)
|
1446
|
-
expr)
|
1447
|
-
|
1448
|
-
|
1449
1454
|
(define (identifier? x)
|
1450
1455
|
(symbol? x))
|
1451
1456
|
|
1452
1457
|
(define (identifier=? use-env-x x use-env-y y)
|
1453
1458
|
(eq? x y))
|
1454
1459
|
|
1460
|
+
(define (identifier->symbol id)
|
1461
|
+
(when (not (symbol? id))
|
1462
|
+
(error "Error: identifier->symbol requires only symbol"))
|
1463
|
+
id)
|
1455
1464
|
|
1456
1465
|
;; readable code for nendo. (original code is chibi-scheme-0.3)
|
1457
1466
|
(define er-macro-transformer
|
@@ -1469,7 +1478,6 @@
|
|
1469
1478
|
name)
|
1470
1479
|
(make-syntactic-closure mac-env '() identifier))))))
|
1471
1480
|
(define (_compare x y)
|
1472
|
-
(sprintf "compare( %s %s )" x y)
|
1473
1481
|
(identifier=? use-env x use-env y))
|
1474
1482
|
|
1475
1483
|
(expander-main
|
@@ -1483,6 +1491,12 @@
|
|
1483
1491
|
(define-syntax syntax-rules
|
1484
1492
|
(er-macro-transformer
|
1485
1493
|
(lambda (expr rename compare)
|
1494
|
+
(when (not (pair? (cdr expr)))
|
1495
|
+
(error "syntax-rules requires: (syntax-rules (ellipses...) ..patterns..) form (1). but got: " expr))
|
1496
|
+
(when (not (or (null? (cadr expr)) (list? (cadr expr))))
|
1497
|
+
(error "syntax-rules requires: (syntax-rules (ellipses...) ..patterns..) form (2). but got: " expr))
|
1498
|
+
(when (> 3 (length expr))
|
1499
|
+
(error "syntax-rules requires: (syntax-rules (ellipses...) ..patterns..) form (3). but got: " expr))
|
1486
1500
|
(let ((ellipse-specified? (identifier? (cadr expr)))
|
1487
1501
|
(count 0)
|
1488
1502
|
(_er-macro-transformer (rename 'er-macro-transformer))
|
@@ -1502,7 +1516,8 @@
|
|
1502
1516
|
(_- (rename '-)) (_>= (rename '>=)) (_error (rename 'error))
|
1503
1517
|
(_ls (rename 'ls)) (_res (rename 'res)) (_i (rename 'i))
|
1504
1518
|
(_vector->list (rename 'vector->list))
|
1505
|
-
(_list->vector (rename 'list->vector))
|
1519
|
+
(_list->vector (rename 'list->vector))
|
1520
|
+
(_list (rename 'list)))
|
1506
1521
|
(define ellipse (rename (if ellipse-specified? (cadr expr) '...)))
|
1507
1522
|
(define lits (if ellipse-specified? (caddr expr) (cadr expr)))
|
1508
1523
|
(define forms (if ellipse-specified? (cdddr expr) (cddr expr)))
|
@@ -1689,5 +1704,6 @@
|
|
1689
1704
|
(list (list _error "no expansion for"
|
1690
1705
|
(list (rename 'strip-syntactic-closures) _expr)))))))))))
|
1691
1706
|
|
1707
|
+
(define-syntax %syntax-rules syntax-rules)
|
1692
1708
|
|
1693
1709
|
;;[EOS]
|