[Top][All Lists]

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

Using guile's introspection facilities

From: Daniel Ridge
Subject: Using guile's introspection facilities
Date: Tue, 27 Feb 2007 19:31:54 -0500


Here's a snippet of a trivial C module that makes a couple of non- visible libguile functions available for your use:

SCM_DEFINE(guile_srcprops_p, "srcprops?", 1, 0, 0,
           (SCM obj),
           "is obj a srcprops?")
#define FUNC_NAME guile_srcprops_p
  if(SRCPROPSP(obj)) {
    return SCM_BOOL_T;
  } else {
    return SCM_BOOL_F;
#undef FUNC_NAME

SCM_DEFINE(guile_srcprops_to_plist, "srcprops-to-plist", 1, 0, 0,
           (SCM obj),
           "convert a guile srcprops object to a plist")
#define FUNC_NAME guile_srcprops_to_plist
  return scm_srcprops_to_plist(obj);
#undef FUNC_NAME

I use these in guile 1.8 to allow me to use source-whash as a navigation aid. With these bindings, I found
that I could evaluate expressions like:

(let* (
(propl (hash-fold (lambda (k v p) (cons (srcprops-to-plist v) p)) '() source-whash)) (all-filenames (map cdr (map (lambda (v) (assoc 'filename v)) propl))) (unique-filenames (unique (sort (delete #f (map (lambda (v) (and (string? v) v)) all-filenames)) string>?)))

    (apply with-xml-tag `("<div>"
      ,(make-raw (apply string-append `(
        "There are: " ,#~(length propl) " source terms on file\n"
        "Source files:<br/>"
        ,@(map (lambda (v)
          (string-append v "<br/>")
        ) unique-filenames)

that (if you excuse a couple of library functions of mine) generates HTML of the list of files associated by the reader with your runtime. This function, and functions like it are enormously helpful for me as I navigate my own guile environments.

Can anyone think of a way to accomplish this same result without exposing srcprops-to-plist? If not, can anyone think of a problem with the above solution?

If there are no problems, I propose adding these bindings to libguile.

        Dan Ridge

reply via email to

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