guile-user
[Top][All Lists]
Advanced

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

interrogation about introspecting function bindings


From: rixed
Subject: interrogation about introspecting function bindings
Date: Wed, 21 Dec 2011 13:26:33 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

I'm trying to get a list of parameter names from a function, using this:

(use-modules (system vm program))
(define (val->string v)
  (if (string? v) v (object->string v)))
(define (fun-params fun)
  (let ((bindings (program-bindings fun)))
    (map (lambda (binding) (val->string (binding:name binding))) bindings)))

All seams well:

(define (f foo) 'bar)
(fun-params f)
-> ("foo")

But sometime I've got internal binding as well as parameter in the
bindings list. So I use (program-arities) to find out how many
parameters I actually have, and take only the firsts bindings :

(define (pop l n)
  (cond
    ((= 0 n)   '())
    ((null? l) '())
    (else      (cons (car l)
                     (pop (cdr l) (- n 1))))))
(define (fun-params fun)
  (let ((bindings (program-bindings fun))
        (arity    (arity:nreq (car (program-arities fun)))))
    (map (lambda (binding)
           (val->string (binding:name binding)))
         (pop bindings arity))))

This seams to work, but is it guaranteed that the first b bindings will
be the parameters ?




reply via email to

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