unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* interrogation about introspecting function bindings
@ 2011-12-21 12:26 rixed
  2012-01-10 21:15 ` Andy Wingo
  0 siblings, 1 reply; 4+ messages in thread
From: rixed @ 2011-12-21 12:26 UTC (permalink / raw)
  To: guile-user

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 ?




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

end of thread, other threads:[~2013-01-07 21:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-21 12:26 interrogation about introspecting function bindings rixed
2012-01-10 21:15 ` Andy Wingo
2012-01-11 16:13   ` rixed
2013-01-07 21:04     ` 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).