[Top][All Lists]

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

Re: Guile Introspection

From: Ludovic Courtès
Subject: Re: Guile Introspection
Date: Sun, 08 Jul 2007 17:18:46 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux)


Mike Gran <address@hidden> writes:

> For example, how can I write a function that prints its own name?

In Scheme, functions are first-class objects that are not necessarily
bound to a top-level name.  For instance, a `lambda' is nameless:

  (lambda args

Thus, there is no generic, portable way to find the symbol under which a
procedure is bound (_if_ it's bound).  But...

> Or, what is the scheme version of the following C code

In Guile, "primitive procedures" (i.e., procedures written in C) have
their "official" name recorded in them.  For instance:

  guile> 1+
  #<primitive-procedure 1+>
  guile> (procedure-name 1+)

Happily, it also works with regular procedures defined with `define':

  guile> (define (f x) x)  
  guile> (procedure-name f)

... but doesn't work with lambdas:

  guile> (procedure-name (lambda args args))

As for the file name and line number, you can in theory get them
(provided Guile runs in "debug" mode) using `procedure-source' and
`source-properties', although the details escape me now.


reply via email to

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