Getting info on exported identifiers

Asked by leppie on 2008-08-25

Hi

I was wondering what would be involved to get some information about exported identifiers. Currently I can easily get a list of exported id's by calling 'env-names' on an environment object. But what I would additionally like is to categorize those identifiers into 3 separate classes, namely variable, syntax and record-type-descriptor.

I know I can probably take the 'bad' road, and eval/guard each id and categorize it according to an expected exception/condition. I have also noticed I should probably look at label->binding, but unfortunately I do not know where to get the 'r' parameter from, neither do I really know what it is :o|

Also, is there a way to determine whether an exported identifier is simply a re-exported identifier from another library?

Cheers

leppie

Question information

Language:
English Edit question
Status:
Solved
For:
Ikarus Scheme Edit question
Assignee:
No assignee Edit question
Solved by:
leppie
Solved:
2008-08-25
Last query:
2008-08-25
Last reply:
2008-08-25
Abdulaziz Ghuloum (aghuloum) said : #1

On Aug 25, 2008, at 4:37 AM, leppie wrote:

> I was wondering what would be involved to get some information
> about exported identifiers. Currently I can easily get a list of
> exported id's by calling 'env-names' on an environment object. But
> what I would additionally like is to categorize those identifiers
> into 3 separate classes, namely variable, syntax and record-type-
> descriptor.

There might be more categories like modules, primitives, and core
syntax forms.

> I know I can probably take the 'bad' road, and eval/guard each id
> and categorize it according to an expected exception/condition.

That's bad, I agree.

> I have also noticed I should probably look at label->binding,

Or imported-label->binding from library manager since all identifiers
that you find in an environment are imported from some library. The
library manager knows about them.

> but unfortunately I do not know where to get the 'r' parameter
> from, neither do I really know what it is :o|

This "r" is a local environment used while expanding an expression,
so it holds lexical variables, macros, etc., that are bound in an
expression and not imported from somewhere else. You shouldn't need it.

> Also, is there a way to determine whether an exported identifier is
> simply a re-exported identifier from another library?

The simple answer is that imported-label->binding should give you the
library in which the binding originated, so, you can compare that to
the library in question.

The long answer is that you can take the library-subst (contains a
mapping from names->labels for all identifiers that are explicitly
exported by a library) and look at the library-env (containing a
mapping from label->binding for all binding that are defined in the
library). A re-exported identifier is one that has a name->label
mapping in the subst but has no label->binding in the env (it's label-
 >binding is in another library).

Does this make sense?

leppie (leppie) said : #2

> Does this make sense?

Hopefully, thanks, will let you know the mileage I get :-)

Cheers

leppie

leppie (leppie) said : #3

I got what I need :)

  (define (environment-bindings e)
    (let ((enl (vector->list (vector-map cons (env-names e) (env-labels e)))))
      (let f ((l enl)(a '()))
        (if (null? l)
          a
          (let ((nl (car l)))
            (f (cdr l) (cons (cons (car nl) (imported-label->binding (cdr nl))) a)))))))

Thanks again

leppie

Sample of output:
> (for-each (lambda (x) (printf "~a\n" x)) (environment-bindings (environment '(ironscheme linq))))
(group global-macro #<library (ironscheme linq)> . g$664$1l0u0O)
(key global #<library (ironscheme linq)> . g$key$510$1l0u0O)
(descending global-macro #<library (ironscheme linq)> . g$659$1l0u0O)
(from global-macro #<library (ironscheme linq)> . g$654$1l0u0O)
(single/default global #<library (ironscheme linq)> . g$single/default$506$1l0u0O)
(ascending global-macro #<library (ironscheme linq)> . g$660$1l0u0O)
(single global #<library (ironscheme linq)> . g$single$505$1l0u0O)
(where global-macro #<library (ironscheme linq)> . g$666$1l0u0O)
(get-list global #<library (ironscheme linq)> . g$get-list$509$1l0u0O)
(first/default global #<library (ironscheme linq)> . g$first/default$508$1l0u0O)
(= core-prim . =)
(on global-macro #<library (ironscheme linq)> . g$661$1l0u0O)
(foreach global-macro #<library (ironscheme linq)> . g$657$1l0u0O)
(join global-macro #<library (ironscheme linq)> . g$665$1l0u0O)
(select global-macro #<library (ironscheme linq)> . g$669$1l0u0O)
(skip global #<library (ironscheme linq)> . g$skip$504$1l0u0O)
(let macro . let)
(equals global-macro #<library (ironscheme linq)> . g$662$1l0u0O)
(take global #<library (ironscheme linq)> . g$take$503$1l0u0O)
(in global-macro #<library (ironscheme linq)> . g$668$1l0u0O)
(first global #<library (ironscheme linq)> . g$first$507$1l0u0O)
(then global-macro #<library (ironscheme linq)> . g$658$1l0u0O)
(by global-macro #<library (ironscheme linq)> . g$663$1l0u0O)
(grouping? global #<library (ironscheme linq)> . g$grouping?$499$1l0u0O)
(orderby global-macro #<library (ironscheme linq)> . g$667$1l0u0O)

And I can see let and = is re-exported (will figure that out still).

Abdulaziz Ghuloum (aghuloum) said : #4

Urgh!!

(define (environment-bindings e)
  (vector->list
    (vector-map
      (lambda (name label)
        (cons name (imported-label->binding label)))
      (env-names e)
      (env-labels e))))

leppie (leppie) said : #5

LOL, yeah :o)

Thanks