[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] extending an environment; object systems
From: |
Shawn Rutledge |
Subject: |
[Chicken-users] extending an environment; object systems |
Date: |
Sun, 16 Apr 2006 10:28:34 -0700 |
(Sorry this is more of a basic Scheme question than a Chicken one)
I think I'm concluding that there is no way to destructively add to an
environment (other than top-level) that already exists. For example I
try this:
(define (make-obj name)
(lambda (sym . rest)
(case sym
['name name]
['def (define (car rest) (cadr rest))]
['foo foo]
[else (eval sym)]
)
)
)
(define f (make-obj 'o))
#;2> (f 'name)
o
#;3> (f 'def 'foo "the foo")
#;4> (f 'foo)
Error: unbound variable: foo
http://sicp.ai.mit.edu/Fall-2003/manuals/scheme-7.5.5/doc/scheme_2.html
also says that you can create a new environment which inherits values
from an old one and adds more, but you cannot add new bindings to an
old env.
Is there a way to do it with macros? I'm suspecting probably not. So
this is a difficulty when building object systems. I see that some of
the simple ones (like prometheus and protobj) tend to use assq lists
for variables. I'd like to find a way to leverage the fast
symbol-lookup mechanism Scheme already has to look up variable
bindings within objects, and also, be able to add new bindings to
existing objects. (If it's impossible, then it might be best to
accept that you cannot add bindings to an object without cloning the
whole object at the same time. This is more in the functional style.)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Chicken-users] extending an environment; object systems,
Shawn Rutledge <=