[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fwd: Req for help on objects and environments]
From: |
Alp Öztarhan |
Subject: |
Re: [Fwd: Req for help on objects and environments] |
Date: |
Thu, 02 Sep 2004 15:47:46 +0300 |
Thank you very much for caring to write. But I still do not have the
answers yet.
On Thu, 2004-09-02 at 14:53, address@hidden wrote:
> AFAIK eval takes an expression and a module (which is an environment)
> to eval the expression in. I don't quite understand your problem.
> Could you give some examples?
The question about environments is this: I have an alist that contains
my "variables". Say '((a . 3) (b . 5)). T want to be able to "eval" an
expression, say '(+ a b), in an environment where a has value 3, b has
value 5. For that, I have to manipulate an environment (null-environment
maybe?) and put a and b as variables, with values 3 and 5 respectively.
How can I manipulate the environment?
Second, how do I get a null-environment? (Or any environment I can
manipulate) It is in R5RS, but guile initially does not have it. I
suspect it may be in an ice-9 module, but how can I find out which one?
(Or maybe in SLIB?)
How do I find out which variables an environment contains. Maybe I
should ask: what is an "environment"? It is _not_ an alist. How can I
play with it?
> > 4) I also want to use the (make-object-property) scheme procedure.
> > Unfortunately, I cannot list the properties of a given object.
>
> Like this?
>
> | guile> (define x 42)
> | guile> (set-object-property! x 'colour 'green)
> | green
> | guile> (set-object-property! x 'size 42)
> | 42
> | guile> (set-object-property! x 'friends '(alfred bert carol))
> | (alfred bert carol)
> | guile> (object-properties x)
> | ((friends alfred bert carol) (size . 42) (colour . green))
> | guile> (object-property x 'friends)
> | (alfred bert carol)
>
> (note that the object properties is an alist, the key being the car of the
> sublists, the value the cdr. But you can (and usually should) ignore that
> and use object-property, object-properties and so on).
>
> (Note as well that the properties get attached to the *value*, not to the
> *variable*):
>
> | guile> (object-property 42 'friends)
> | (alfred bert carol)
>
> Does this help?
Well, in a way it does. But the documentation says that this way of
giving properties is "the old way". They say "the new way" is using
(make-object-property). It seems nicer at least:
|guile> (define var 'value)
|guile> (define color (make-object-property))
|guile> (set! (color var) 'green)
|guile> (color var)
=> green
Now this is a different way of giving properties. After these,
object-properties gives an empty alist. So given the documentation, I
thought I should use "the new way". If I cannot find out how, then
maybe I should use "the old way" :-)
Thank you again for answering. I will be very happy if you can answer
the environment questions.
PS: I thought I should CC this to the guile-user list just in case
someone else may need the answer to these questions more than some spam :-)