nendo 0.3.4 → 0.3.5

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.
@@ -0,0 +1,57 @@
1
+ #!/bin/sh
2
+ :; #-*- mode: nendo; syntax: scheme -*-;;
3
+ :; exec /usr/local/bin/nendo $0 $*
4
+
5
+ (require "benchmark")
6
+ (.load "./benchmark/ruby_benchmark_code.rb")
7
+ ( load "./benchmark/nendo_benchmark_code.nnd")
8
+
9
+ (require "ruby-prof")
10
+
11
+ ;; ------------------ macro --------------------
12
+ (define bench-task
13
+ (macro (profile-flag title proc)
14
+ `(begin
15
+ (.puts ,title)
16
+ (.puts Benchmark::CAPTION)
17
+ ,(if profile-flag
18
+ `(let* ((result (RubyProf.profile
19
+ (&block ()
20
+ ,proc)))
21
+ (printer (RubyProf::GraphPrinter.new result)))
22
+ (printer.print STDOUT))
23
+ `(.puts (Benchmark.measure
24
+ (&block ()
25
+ ,proc))))
26
+ (.puts ""))))
27
+
28
+
29
+ ;; -------------------- fact --------------------
30
+ (bench-task #f
31
+ "fact (ruby version)"
32
+ (printf " => %d\n" (RubyBenchmarkCode.new.fact 1000)))
33
+
34
+ (bench-task #f
35
+ "fact (nendo version)"
36
+ (printf " => %d\n" (fact 1000)))
37
+
38
+
39
+ ;; -------------------- tak --------------------
40
+ (bench-task #f
41
+ "tak (ruby version)"
42
+ (printf " => %d\n" (RubyBenchmarkCode.new.tak 10 5 0)))
43
+
44
+ (bench-task #f
45
+ "tak2 (ruby version)"
46
+ (printf " => %d\n" (RubyBenchmarkCode.new.tak2 10 5 0)))
47
+
48
+ (bench-task #f
49
+ "tak3 (ruby version)"
50
+ (printf " => %d\n" (RubyBenchmarkCode.new.tak3 10 5 0)))
51
+
52
+ (bench-task #f
53
+ "tak (nendo version)"
54
+ (printf " => %d\n" (tak 10 5 0)))
55
+
56
+
57
+ ;;[EOF]
@@ -10,5 +10,9 @@
10
10
  (tak (- y 1) z x)
11
11
  (tak (- z 1) x y))))
12
12
 
13
- (define (main argv)
14
- (print (tak 10 5 0)))
13
+ ;; factorial
14
+ (define (fact n)
15
+ (if (zero? n)
16
+ 1
17
+ (* n (fact (- n 1)))))
18
+
@@ -0,0 +1,58 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ # takeuchi function ( tarai mawashi bench )
4
+ class RubyBenchmarkCode
5
+
6
+ def tak( x, y, z )
7
+ if y >= x
8
+ y
9
+ else
10
+ tak( tak( x-1, y, z ),
11
+ tak( y-1, z, x ),
12
+ tak( z-1, x, y ))
13
+ end
14
+ end
15
+
16
+ def tak2( x, y, z )
17
+ @inner_tak = Proc.new { |_x,_y,_z|
18
+ if ( _y >= _x )
19
+ _y
20
+ else
21
+ @inner_tak.call(
22
+ @inner_tak.call( _x-1, _y, _z ),
23
+ @inner_tak.call( _y-1, _z, _x ),
24
+ @inner_tak.call( _z-1, _x, _y ))
25
+ end
26
+ }
27
+ @inner_tak.call( x, y, z )
28
+ end
29
+
30
+ def tak3( x, y, z )
31
+ @inner_minus = Proc.new { |_a,_b|
32
+ _a - _b
33
+ }
34
+ @inner_le = Proc.new { |_a,_b|
35
+ _a >= _b
36
+ }
37
+ @inner_tak = Proc.new { |_x,_y,_z|
38
+ if ( @inner_le.call( _y, _x ))
39
+ _y
40
+ else
41
+ @inner_tak.call(
42
+ @inner_tak.call( @inner_minus.call(_x,1), _y, _z ),
43
+ @inner_tak.call( @inner_minus.call(_y,1), _z, _x ),
44
+ @inner_tak.call( @inner_minus.call(_z,1), _x, _y ))
45
+ end
46
+ }
47
+ @inner_tak.call( x, y, z )
48
+ end
49
+
50
+ def fact( n )
51
+ if 0 == n
52
+ 1
53
+ else
54
+ n * fact( n - 1 )
55
+ end
56
+ end
57
+
58
+ end
data/example/scratch.nnd CHANGED
@@ -4,12 +4,58 @@
4
4
  (disable-idebug)
5
5
  (define debug-print-length 2000)
6
6
 
7
- (%internal-define-to-letrec
8
- '(macro (x)
9
- (define (foo v) (+ v 1))
10
- (define result 10)
11
- (define (bar v) (+ v 2))
12
- '(1 2 3)))
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))))))
13
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))))))
41
+
42
+ (pretty-print
43
+ (macroexpand-1
44
+ '(case (car '(a b c d))
45
+ ((a) 'a)
46
+ ((b) 'b)
47
+ ((1) 1)
48
+ (else 'else))))
49
+
50
+ (case (caddr '(a b 1 2))
51
+ ((a) 'a)
52
+ ((b) 'b)
53
+ ((1) 1)
54
+ (else 'else))
55
+
56
+
57
+
58
+
59
+
14
60
  (exit)
15
61
 
@@ -4,16 +4,17 @@
4
4
  #
5
5
 
6
6
  trampCall(
7
- delayCall( 'require',
7
+ delayCall( '_require', 'require',
8
8
  begin
9
9
  if @global_lisp_binding.has_key?('_require') then
10
10
  trampCall(@_require)
11
11
  else raise NameError.new( "Error: undefined variable _require", "_require" ) end
12
12
  rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:37"] + __e.backtrace ) ; raise __e
13
13
  end ,
14
- Cell.new(
14
+ [
15
15
  "syslog"
16
- ))
16
+ ]
17
+ )
17
18
  )
18
19
  #--------------------
19
20
 
@@ -43,13 +44,14 @@ trampCall(
43
44
  else raise NameError.new( "Error: undefined variable __PLMARK", "__PLMARK" ) end
44
45
  rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:41"] + __e.backtrace ) ; raise __e
45
46
  end ,
46
- Cell.new(
47
- "Nendo: " ,Cell.new(
47
+ [
48
+ "Nendo: " ,
48
49
  begin
49
50
  trampCall(_str)
50
51
  rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:41"] + __e.backtrace ) ; raise __e
51
52
  end
52
- ))))
53
+ ]
54
+ ))
53
55
  )
54
56
  rescue => __e ; __e.set_backtrace( ["./lib/debug/syslog.nnd:41"] + __e.backtrace ) ; raise __e
55
57
  end
data/lib/init.nnd CHANGED
@@ -652,20 +652,20 @@
652
652
  (cons 'or
653
653
  (map
654
654
  (lambda (x)
655
- `(eqv? ,x ,val))
655
+ `(eqv? (quote ,x) ,val))
656
656
  cond-vals)))
657
657
  `((,v
658
658
  ,@body))))))
659
659
 
660
660
  (define (case-iter val lst)
661
661
  (cond
662
- ((eq? 0 (length lst))
662
+ ((null? lst)
663
663
  '())
664
664
  ((eq? 1 (length lst))
665
665
  (case-block val (car lst)))
666
- (else
667
- (append (case-block val (car lst))
668
- (case-iter val (cdr lst))))))
666
+ (else
667
+ (append (case-block val (car lst))
668
+ (case-iter val (cdr lst))))))
669
669
 
670
670
  (let1 sym (gensym)
671
671
  `(let1 ,sym ,cond-exp
@@ -1268,18 +1268,18 @@
1268
1268
  '())
1269
1269
  ((list? sexp)
1270
1270
  (case (car sexp)
1271
- (('quote)
1271
+ ((quote)
1272
1272
  sexp)
1273
- (('macro)
1273
+ ((macro)
1274
1274
  sexp)
1275
- (('begin)
1275
+ ((begin)
1276
1276
  `(begin
1277
1277
  ,@(setup-proc-body (cdr sexp))))
1278
- (('lambda)
1278
+ ((lambda)
1279
1279
  `(lambda
1280
1280
  ,(second sexp)
1281
1281
  ,@(setup-proc-body (cddr sexp))))
1282
- (('if)
1282
+ ((if)
1283
1283
  (case (length sexp)
1284
1284
  ((3)
1285
1285
  `(if
@@ -1290,15 +1290,15 @@
1290
1290
  ,(second sexp)
1291
1291
  ,(setup-proc (third sexp))
1292
1292
  ,(setup-proc (fourth sexp))))))
1293
- (('let)
1293
+ ((let)
1294
1294
  `(let
1295
1295
  ,(setup-let-args (second sexp))
1296
1296
  ,@(setup-proc-body (cddr sexp))))
1297
- (('letrec)
1297
+ ((letrec)
1298
1298
  `(letrec
1299
1299
  ,(setup-let-args (second sexp))
1300
1300
  ,@(setup-proc-body (cddr sexp))))
1301
- (('define)
1301
+ ((define)
1302
1302
  (let1 val (third sexp)
1303
1303
  `(define
1304
1304
  ,(second sexp)
@@ -1325,5 +1325,5 @@
1325
1325
  ;; global variables
1326
1326
  ;; ----------------------------------------
1327
1327
  (define *nendo-version*
1328
- "0.3.4" ;;NENDO-VERSION
1328
+ "0.3.5" ;;NENDO-VERSION
1329
1329
  )