[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
iScheme based on the Metaobject protocol
From: |
Keisuke Nishida |
Subject: |
iScheme based on the Metaobject protocol |
Date: |
07 Nov 2000 04:08:56 -0500 |
User-agent: |
T-gnus/6.14.4 (based on Gnus v5.8.6) (revision 02) SEMI/1.13.7 (Awazu) Chao/1.14.0 (Momoyama) Emacs/20.7 (i686-pc-linux-gnu) MULE/4.1 (AOI) |
Hello,
Because of the fun of it, I'm still thinking about iScheme.
I guess I'll make it completely based on the Metaobject protocol
(though I haven't understood it quite well yet).
Primitive @lambda creates a method:
(@define add-integer
(@lambda ((<integer> x) (<integer> y))
(+ x y)))
(add-integer 1 2) => 3
Several methods can be combined into a generic function:
(@define add-string
(@lambda ((<string> x) (<string> y))
(string-append x y)))
(@define add (@make-generic add-integer add-string))
(add 1 2) => 3
(add "a" "b") => "ab"
A new method can be added easily:
(@define (add (<list> x) (<list> y))
(append x y))
(add '(1) '(2)) => (1 2)
So, the following two expressions are different in iScheme:
(@define (foo) 1) ;; `foo' is a generic function
(@define foo (@lambda () 1)) ;; `foo' is a method
The latter is more efficient when (foo) is evaluated.
Special notation <const> allows to define a method for a particular
object instead of class:
(@define (add (<const> 'double) y)
(add y y))
(add 'double "ab") => "abab"
(add 'single "ab") ;; ERROR
<const> can be omitted:
(@define (add 'single y) y)
(add 'single "ab") => "ab"
Is this a good thing? I guess this is feasible, though I'm not sure
how efficiently it could be implemented.
By using the notation above, the following Haskell-like code
fact 0 = 1
fact n = n * fact (n - 1)
might be translated into the following iScheme code:
(@define (fact 0) 1)
(@define (fact n) (* n (fact (- n 1))))
(I know this is not sufficient as a translation of Haskell yet.)
Thinking about this kind of stuff is really fun, after all :)
I guess I'll continue working on iScheme until I realize it is
a stupid thing...
This is the current draft:
http://home.cwru.edu/~kxn30/ischeme.ps.gz
Any comment is appreciated.
Thanks,
Keisuke Nishida
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- iScheme based on the Metaobject protocol,
Keisuke Nishida <=