unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Req for help on objects and environments
@ 2004-09-01  8:28 Alp Öztarhan
  2004-09-03 18:46 ` Andy Wingo
  0 siblings, 1 reply; 15+ messages in thread
From: Alp Öztarhan @ 2004-09-01  8:28 UTC (permalink / raw)


I have been digging the documentation to find answers to two questions,
but could not find any answers.

First, I want to play with the properties on objects.
I want to be able to serialize an object along with its properties.
I *can* make and retrieve properties of objects by use of
(make-object-property). But how do I get a list of the properties of a
given object?

Second, I want to manipulate the environment in eval.
I could not even do what the documentation tells.
I could not get a handle on (null-environment) etc. (undefined symbol
:-(
Besides, I want to manipulate it, giving extra symbols etc.
Could anybody give me any hint on these?

thanks.

- alp



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [Fwd: Req for help on objects and environments]
@ 2004-09-02 11:09 Alp Öztarhan
  2004-09-02 11:53 ` tomas
  2004-09-03 20:27 ` [Fwd: Req for help on objects and environments] Ludovic Courtès
  0 siblings, 2 replies; 15+ messages in thread
From: Alp Öztarhan @ 2004-09-02 11:09 UTC (permalink / raw)


Maybe I should give more information:

1) I work on gentoo linux guile 1.6.4

2) I try to program in Scheme. I DO NOT use C or C++ in my project.
   Just pure Scheme.

3) I try to control the environment I "eval" my expression, but
   manipulating the environment is not described in my documentation.
   (which comes with guile-1.6.4)

4) I also want to use the (make-object-property) scheme procedure.
   Unfortunately, I cannot list the properties of a given object.

Could anybody please help me on these? Or at least tell me where I can
ask these again?

- alp

-----Forwarded Message-----
From: Alp Öztarhan <alp@uludag.org.tr>
To: guile-user@gnu.org
Subject: Req for help on objects and environments
Date: Wed, 01 Sep 2004 11:28:49 +0300

I have been digging the documentation to find answers to two questions,
but could not find any answers.

First, I want to play with the properties on objects.
I want to be able to serialize an object along with its properties.
I *can* make and retrieve properties of objects by use of
(make-object-property). But how do I get a list of the properties of a
given object?

Second, I want to manipulate the environment in eval.
I could not even do what the documentation tells.
I could not get a handle on (null-environment) etc. (undefined symbol
:-(
Besides, I want to manipulate it, giving extra symbols etc.
Could anybody give me any hint on these?

thanks.

- alp



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
-- 



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Fwd: Req for help on objects and environments]
  2004-09-02 11:09 [Fwd: Req for help on objects and environments] Alp Öztarhan
@ 2004-09-02 11:53 ` tomas
  2004-09-02 12:47   ` Alp Öztarhan
  2004-09-03 19:10   ` Req for help on objects and environments Andy Wingo
  2004-09-03 20:27 ` [Fwd: Req for help on objects and environments] Ludovic Courtès
  1 sibling, 2 replies; 15+ messages in thread
From: tomas @ 2004-09-02 11:53 UTC (permalink / raw)
  Cc: guile-user


[-- Attachment #1.1: Type: text/plain, Size: 1552 bytes --]

On Thu, Sep 02, 2004 at 02:09:05PM +0300, Alp ?ztarhan wrote:
> Maybe I should give more information:
> 
> 1) I work on gentoo linux guile 1.6.4
> 
> 2) I try to program in Scheme. I DO NOT use C or C++ in my project.
>    Just pure Scheme.
> 
> 3) I try to control the environment I "eval" my expression, but
>    manipulating the environment is not described in my documentation.
>    (which comes with guile-1.6.4)

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?

> 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?

Regards
-- tomás

[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Fwd: Req for help on objects and environments]
  2004-09-02 11:53 ` tomas
@ 2004-09-02 12:47   ` Alp Öztarhan
  2004-09-02 19:19     ` Stephen Compall
  2004-09-03 19:10   ` Req for help on objects and environments Andy Wingo
  1 sibling, 1 reply; 15+ messages in thread
From: Alp Öztarhan @ 2004-09-02 12:47 UTC (permalink / raw)
  Cc: tomas

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, tomas@fabula.de 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 :-)



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Fwd: Req for help on objects and environments]
  2004-09-02 12:47   ` Alp Öztarhan
@ 2004-09-02 19:19     ` Stephen Compall
  0 siblings, 0 replies; 15+ messages in thread
From: Stephen Compall @ 2004-09-02 19:19 UTC (permalink / raw)
  Cc: guile-user

Alp Öztarhan <alp@uludag.org.tr> writes:

> 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" :-)

Object properties are kept in `scm_properties_whash'.  Properties are
not named; internally, they are just pairs, almost always (#f . ()).
They are identified by their uniqueness eq?-wise.  Only the returned
proc-with-setter has access to this pair, through its environment.

The only meaningful name is that which you assign to it.

If you want names, associate them with the proc-with-setters somehow.
Keep your own alist of names to values.  Whatever.

--
Stephen Compall or s11 or sirian

It is a human characteristic to love little animals, especially if
they're attractive in some way.
		-- McCoy, "The Trouble with Tribbles", stardate 4525.6

Dateline monarchist BLU-97 A/B passwd FTS2000 Delta Force MD4 Sears
Tower domestic disruption radar S Box ASLET JPL electronic
surveillance New World Order


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Req for help on objects and environments
  2004-09-01  8:28 Req for help on objects and environments Alp Öztarhan
@ 2004-09-03 18:46 ` Andy Wingo
  2004-09-06  6:17   ` tomas
  2004-09-21 20:47   ` Marius Vollmer
  0 siblings, 2 replies; 15+ messages in thread
From: Andy Wingo @ 2004-09-03 18:46 UTC (permalink / raw)


Hi Alp,

I know you've got a lot of answers already, but I think the environment
question is still not covered.

On Wed, 2004-09-01 at 11:28 +0300, Alp Öztarhan wrote:
> First, I want to play with the properties on objects.
> I want to be able to serialize an object along with its properties.
> I *can* make and retrieve properties of objects by use of
> (make-object-property). But how do I get a list of the properties of a
> given object?

In case you didn't figure it out, you can't, except from C with
scm_properties_whash.

> Second, I want to manipulate the environment in eval.
> I could not even do what the documentation tells.
> I could not get a handle on (null-environment) etc. (undefined symbol
> :-(
> Besides, I want to manipulate it, giving extra symbols etc.
> Could anybody give me any hint on these?

Sure. Scheme actually has two kinds of environments: toplevel and
lexical. The first is a simple association of names and values. The
concept is very similar to that of "modules", so in guile, toplevel
environments *are* modules[0]:

	(module? (null-environment 5)) => #t

By default, guile is not r5rs-compliant when it loads up. I think this
is because (ice-9 syncase) is very slow to load up. Anyway, using
(ice-9 r5rs) will give you everything in the report, including
null-environment.

Modules are what can be passed as the second argument to `eval'. They
should be accessed only with documented functions for maximum
portability between guile versions, and to other schemes. Unfortunately,
modules expose their guts too much because everyone sees boot-9.scm.

So, to opaquely add a:=5 to a module, you can say:

	(define env (null-environment 5))
	(eval '(define a 5) env)
	(eval 'a env) => 5

If you feel more dangerous, you can use module-define, module-defined?,
module-ref, module-variable, etc. See boot-9.scm for more. Dunno what
Marius thinks about this, but I like first-class modules :)

[0] This is complicated by the existence of environment SMOBs, from
environments.c / environment-*. I have no idea whether this code is on
the way in, or the way out. Marius, Dirk?

Lexical environments are a different beast. You cannot access them with
r5rs, I don't think. However, with guile you can, although it's
definitely not documented. I tried to be less hacky with the following
macro, but define-macro's memoizing behaviour caused guile 1.6 to
segfault, so I had to use low-level macros:

(define make-environment
  (procedure->syntax
   (lambda (exp env)
     (local-eval `(let* ,(let lp ((in (cdr exp)) (out '()))
                           (if (null? in)
                               (reverse out)
                               (lp (cddr in) (cons
                                              (list (car in) (cadr in)) 
                                              out))))
                    (the-environment))
                 env))))

;; e.g.
(make-environment a 5 b 6 c a)
=> <a lexical environment with a=5, b=6, c=5

This environment is created with let*, so later bindings can access the
values of previous ones. `the-environment' is a syntax that returns the
current lexical environment. local-eval is a form of eval that takes a
lexical environment instead of a toplevel. Indeed, the `env' argument to
a low-level macro is a lexical environment.

Then,

(define-macro (with-environment env . body)
  `(local-eval
    ,(list 'quote `(begin ,@body))
    ,env))

(with-environment (make-environment a 5)
   a) => 5

(define (bind sym val env)
  (if (defined? sym env)
      (begin (local-eval `(set! ,sym ',val) env)
             env)
      (local-eval `(let ((,sym ,val)) (the-environment)) env)))

There's more in (soundscrape environments), in my arch repository. I
wrote this when I just started with guile; the pattern of lexical
environments applied to a problem I had. Now I worry about the low-level
access. A problem for later, I guess...

Hope that helped,
-- 
Andy Wingo <wingo@pobox.com>
http://ambient.2y.net/wingo/


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Req for help on objects and environments
  2004-09-02 11:53 ` tomas
  2004-09-02 12:47   ` Alp Öztarhan
@ 2004-09-03 19:10   ` Andy Wingo
  2004-09-06 22:34     ` macro documentation? (was: Re: Req for help on objects and environments) Richard Todd
  1 sibling, 1 reply; 15+ messages in thread
From: Andy Wingo @ 2004-09-03 19:10 UTC (permalink / raw)


Hi Tomas,

On Thu, 2004-09-02 at 13:53 +0200, tomas@fabula.de wrote:
> (Note as well that the properties get attached to the *value*, not to the
> *variable*):
> 
>  | guile> (object-property 42 'friends)
>  | (alfred bert carol)

I didn't realize this! Thanks for the tip. I guess it has to be this
way.

It trips up some documentation thoughts I had, though... I was using the
'documentation object-property to attach docs to variables, whereas it
actually puts it on the value. I wonder if there's a better way.

> Does this help?

It helped me ;)

Cheers,
-- 
Andy Wingo <wingo@pobox.com>
http://ambient.2y.net/wingo/


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Fwd: Req for help on objects and environments]
  2004-09-02 11:09 [Fwd: Req for help on objects and environments] Alp Öztarhan
  2004-09-02 11:53 ` tomas
@ 2004-09-03 20:27 ` Ludovic Courtès
  2004-09-04 11:31   ` Marius Vollmer
  1 sibling, 1 reply; 15+ messages in thread
From: Ludovic Courtès @ 2004-09-03 20:27 UTC (permalink / raw)
  Cc: guile-user

Hi,

One day, 9 hours, 9 minutes, 46 seconds ago, 
Alp Öztarhan wrote:
> 3) I try to control the environment I "eval" my expression, but
>    manipulating the environment is not described in my documentation.
>    (which comes with guile-1.6.4)

The following document describes the Guile API for manipulating
environments: http://www.gnu.org/software/guile/docs/env.html .  It
should provide you with answers to your questions related to modifying
an environment.

BTW, the document preface reads:

  I hope this text will eventually become a chapter of the Guile manual

However, it dates back to 1999 and it looks like it never happened.  Is
there any reason for it?

Thanks,
Ludovic.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Fwd: Req for help on objects and environments]
  2004-09-03 20:27 ` [Fwd: Req for help on objects and environments] Ludovic Courtès
@ 2004-09-04 11:31   ` Marius Vollmer
  2004-09-04 13:07     ` Ludovic Courtès
  0 siblings, 1 reply; 15+ messages in thread
From: Marius Vollmer @ 2004-09-04 11:31 UTC (permalink / raw)
  Cc: guile-user

Ludovic Courtès <ludo@chbouib.org> writes:

> However, it dates back to 1999 and it looks like it never happened.
> Is there any reason for it?

Guile does not (yet?) use the 'environment' data type described in
this draft proposal.

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Fwd: Req for help on objects and environments]
  2004-09-04 11:31   ` Marius Vollmer
@ 2004-09-04 13:07     ` Ludovic Courtès
  0 siblings, 0 replies; 15+ messages in thread
From: Ludovic Courtès @ 2004-09-04 13:07 UTC (permalink / raw)
  Cc: guile-user

Hi,

Today, one hour, 13 minutes, 41 seconds ago, Marius Vollmer wrote:
> Guile does not (yet?) use the 'environment' data type described in
> this draft proposal.

Good reason.  ;-)

What fooled me is that Guile (1.6.4) seems to already implement most of
the operations described in the proposal:

  environment-bound?        environment-module        environment-set!
  environment-cell          environment-observe       environment-undefine
  environment-define        environment-observe-weak
  environment-unobserve
  environment-fold          environment-ref           environment?

Looking closer at what these functions do, it looks like they are
currently unusable:

  guile> (environment-ref (scheme-report-environment 5) 'append)
  <unnamed port>:33:1: In procedure environment-ref in expression (environment-ref (scheme-report-environment 5) (quote append)):
  <unnamed port>:33:1: Wrong type argument in position 1: #<interface (ice-9 r5rs) 8086720>

Whatever is returned by `scheme-report-environement',
`interaction-environment', `current-module' and the likes is suitable as
the `env' argument of `eval' but not as the `env' argument of the
aforementioned procedures.  Is it that the proposal _was_ implemented
but never got integrated into the rest of Guile?

Thanks,
Ludovic.



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Req for help on objects and environments
  2004-09-03 18:46 ` Andy Wingo
@ 2004-09-06  6:17   ` tomas
  2004-09-21 20:47   ` Marius Vollmer
  1 sibling, 0 replies; 15+ messages in thread
From: tomas @ 2004-09-06  6:17 UTC (permalink / raw)
  Cc: Guile Users

On Fri, Sep 03, 2004 at 07:46:49PM +0100, Andy Wingo wrote:
> Hi Alp,
> 

[...]

> Lexical environments are a different beast. You cannot access them with
> r5rs, I don't think. However, with guile you can, although it's
> definitely not documented. I tried to be less hacky with the following
> macro, but define-macro's memoizing behaviour caused guile 1.6 to
> segfault, so I had to use low-level macros:
> 
> (define make-environment
>   (procedure->syntax
>    (lambda (exp env)
>      (local-eval `(let* ,(let lp ((in (cdr exp)) (out '()))
>                            (if (null? in)
>                                (reverse out)
>                                (lp (cddr in) (cons
>                                               (list (car in) (cadr in)) 
>                                               out))))
>                     (the-environment))
>                  env))))

Thanks for your insightful post. As a (mostly) lurker and (currently) non-
schemer (shame!) I appreciate this.

Suggestion: Maybe call your macro make-local-environment -- that might help
newbies to keep apart those two beasts better.

Regards
-- tomás


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* macro documentation? (was: Re: Req for help on objects and environments)
  2004-09-03 19:10   ` Req for help on objects and environments Andy Wingo
@ 2004-09-06 22:34     ` Richard Todd
  2004-09-07 18:40       ` Andy Wingo
  0 siblings, 1 reply; 15+ messages in thread
From: Richard Todd @ 2004-09-06 22:34 UTC (permalink / raw)
  Cc: Richard Todd, Guile Users

On Sep 3, 2004, at 2:10 PM, Andy Wingo wrote:
>
> On Thu, 2004-09-02 at 13:53 +0200, tomas@fabula.de wrote:
>> (Note as well that the properties get attached to the *value*, not to 
>> the
>> *variable*):
>>
>>  | guile> (object-property 42 'friends)
>>  | (alfred bert carol)
>
> I didn't realize this! Thanks for the tip. I guess it has to be this
> way.

A similar problem appears when trying to document syncase macros... 
they all (display) as:

#<macro! sc-macro>

When I apply the 'documentation property to one of these macros, all 
the sudden ALL my syncase macros have this documentation.  I don't 
suppose anyone knows of a way to add docstrings to individual macros?  
How does this sc-macro entity know which transformation to make?   I 
don't know anything about how syncase works internally...

Richard



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: macro documentation? (was: Re: Req for help on objects and environments)
  2004-09-06 22:34     ` macro documentation? (was: Re: Req for help on objects and environments) Richard Todd
@ 2004-09-07 18:40       ` Andy Wingo
  0 siblings, 0 replies; 15+ messages in thread
From: Andy Wingo @ 2004-09-07 18:40 UTC (permalink / raw)
  Cc: Guile Users

Hey Richard,

On Mon, 2004-09-06 at 17:34 -0500, Richard Todd wrote:
> On Sep 3, 2004, at 2:10 PM, Andy Wingo wrote:
> >
> > On Thu, 2004-09-02 at 13:53 +0200, tomas@fabula.de wrote:
> >> (Note as well that the properties get attached to the *value*, not to 
> >> the
> >> *variable*):
> 
> A similar problem appears when trying to document syncase macros... 
> they all (display) as:
> 
> #<macro! sc-macro>
> 
> When I apply the 'documentation property to one of these macros, all 
> the sudden ALL my syncase macros have this documentation.

That's what you get for using syncase ;-)

Seriously though, this is a problem. Perhaps we can make define-with-
docs set the object-property on the _variable_ rather than (in addition
to?) the value:

(define-macro-with-docs (define-with-docs sym docs val)
  "Define a variable with documentation."
  `(begin
     (define ,sym ,val)
     (set-object-property! (module-variable ,sym) 'documentation ,docs)
     *unspecified*))

Of course with the proper checks, etc. Then when we implement Marius's
Grand New Help Scheme (GNHS), we can make `help' look for documentation
on the variable first. In any case, we implement it in (texinfo
reflection).

> How does this sc-macro entity know which transformation to make?

Presumably because it is passed the whole expression, including the name
of the macro, which would then be looked up in the lexical environment
or in the global macro-table.

Regards,
-- 
Andy Wingo <wingo@pobox.com>
http://ambient.2y.net/wingo/


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Req for help on objects and environments
  2004-09-03 18:46 ` Andy Wingo
  2004-09-06  6:17   ` tomas
@ 2004-09-21 20:47   ` Marius Vollmer
  2004-09-22 17:07     ` Andy Wingo
  1 sibling, 1 reply; 15+ messages in thread
From: Marius Vollmer @ 2004-09-21 20:47 UTC (permalink / raw)
  Cc: Guile Users

Andy Wingo <wingo@pobox.com> writes:

> [0] This is complicated by the existence of environment SMOBs, from
> environments.c / environment-*. I have no idea whether this code is
> on the way in, or the way out. Marius, Dirk?

They are not used by Guile at the moment, but maybe they will be in
the future.  Or maybe not.  Their existence has caused a few
confusions, so maybe it is best to remove them...

> Lexical environments are a different beast. You cannot access them with
> r5rs, I don't think. However, with guile you can, although it's
> definitely not documented.

It is best not to fiddle with the implementation of lexical
environments (expect when you are writing a debugger, say).  Something
like the following might be sufficient and is cleaner.

    (define (make-environment . bindings)
      (let loop ((b bindings)
                 (env '()))
        (cond ((null? b)
               env)
              (else
               (loop (cddr b) (cons (list (car b) (cadr b)) env))))))

    (define-macro (with-env env . body)
      (let ((module (current-module)))
        `(let ((code (cons* 'let ,env ',body)))
           (eval code ',module))))

    (define env (make-environment 'a 12 'b 13))

    (pk (with-env env (+ a b)))

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Req for help on objects and environments
  2004-09-21 20:47   ` Marius Vollmer
@ 2004-09-22 17:07     ` Andy Wingo
  0 siblings, 0 replies; 15+ messages in thread
From: Andy Wingo @ 2004-09-22 17:07 UTC (permalink / raw)
  Cc: Guile Users

Hey Marius,

On Tue, 2004-09-21 at 22:47 +0200, Marius Vollmer wrote:
> It is best not to fiddle with the implementation of lexical
> environments (expect when you are writing a debugger, say).  Something
> like the following might be sufficient and is cleaner.
[...]
>     (define-macro (with-env env . body)
>       (let ((module (current-module)))
>         `(let ((code (cons* 'let ,env ',body)))
>            (eval code ',module))))
> 
>     (define env (make-environment 'a 12 'b 13))
> 
>     (pk (with-env env (+ a b)))

Yeah, I think I would have done this if I hadn't needed to keep state in
the environment. I agree it's ugly though -- it would be impossible to
compile this code, for instance, because it violates the
implementation's prerogative to implement environments as they like. I
should probably implement my stuff with anonymous modules.

Regards,
-- 
Andy Wingo <wingo@pobox.com>
http://ambient.2y.net/wingo/


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2004-09-22 17:07 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-09-02 11:09 [Fwd: Req for help on objects and environments] Alp Öztarhan
2004-09-02 11:53 ` tomas
2004-09-02 12:47   ` Alp Öztarhan
2004-09-02 19:19     ` Stephen Compall
2004-09-03 19:10   ` Req for help on objects and environments Andy Wingo
2004-09-06 22:34     ` macro documentation? (was: Re: Req for help on objects and environments) Richard Todd
2004-09-07 18:40       ` Andy Wingo
2004-09-03 20:27 ` [Fwd: Req for help on objects and environments] Ludovic Courtès
2004-09-04 11:31   ` Marius Vollmer
2004-09-04 13:07     ` Ludovic Courtès
  -- strict thread matches above, loose matches on Subject: below --
2004-09-01  8:28 Req for help on objects and environments Alp Öztarhan
2004-09-03 18:46 ` Andy Wingo
2004-09-06  6:17   ` tomas
2004-09-21 20:47   ` Marius Vollmer
2004-09-22 17:07     ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).