guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unified name properties


From: Dirk Herrmann
Subject: Re: Unified name properties
Date: Fri, 22 Sep 2000 09:44:43 +0200 (MEST)

> - Procedure: binding-name OBJ ENV
>   Find the binding of OBJ in ENV and return its name (associated symbol).
> 
> - Procedure: binding-name-list OBJ ENV
>   Like `binding-name' but return a list of all names.
> 
> or
> 
> - Procedure: environment-find-name ENV OBJ
>   Find the binding of OBJ in ENV and return its name (associated symbol).
> 
> - Procedure: environment-find-name-list OBJ ENV
>   Like `environment-find-name' but return a list of all names.

Probably one function is sufficient, since you always have to expect more
than one binding for an object in an environment.  With the new
environments, this can easily be implemented (not sure, whether instead
of eq? the function should rather use eqv?):

(define (environment-bindings env obj)
  (environment-fold 
    env
    (lambda (sym val tail)
      (if (eq? val obj)
          (cons sym tail)
          tail))
    '()))

Example:

(define foo (make-leaf-environment))
(environment-define foo 'a 1)
(environment-define foo 'b 1)
(environment-define foo 'c 2)
(environment-bindings foo 1)
 --> (b a)
(environment-bindings foo 2)
 --> (c)

Best regards
Dirk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]