unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Using guile's introspection facilities
@ 2007-02-28  0:31 Daniel Ridge
  2007-02-28 22:05 ` Kevin Ryde
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Ridge @ 2007-02-28  0:31 UTC (permalink / raw)
  To: guile-user

Guilers,

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.

Cheers,
	Dan Ridge


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Using guile's introspection facilities
  2007-02-28  0:31 Using guile's introspection facilities Daniel Ridge
@ 2007-02-28 22:05 ` Kevin Ryde
  2007-03-06 22:01   ` Neil Jerram
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Ryde @ 2007-02-28 22:05 UTC (permalink / raw)
  To: Daniel Ridge; +Cc: guile-user

Daniel Ridge <dskr@mac.com> writes:
>
> SCM_DEFINE(guile_srcprops_p, "srcprops?", 1, 0, 0,

I don't think that's meant to be visible, merely a compact form of
what's normally prsented as an alist.  If you want a test then one
possibility would be that it automagically shows up in goops as a
`<srcprops>' class

	(is-a? my-object <srcprop>)

I've used that on (documented) objects like for instance arbiters
which don't otherwise have a test func.

> (let* (
>           (propl (hash-fold (lambda (k v p) (cons (srcprops-to-plist
> v) p)) '() source-whash))

I'm not sure if source-whash is actually meant to be used.  But if you
do then I think `source-properties' can be called on each key in the
hash to get info in alist form.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

* Re: Using guile's introspection facilities
  2007-02-28 22:05 ` Kevin Ryde
@ 2007-03-06 22:01   ` Neil Jerram
  0 siblings, 0 replies; 3+ messages in thread
From: Neil Jerram @ 2007-03-06 22:01 UTC (permalink / raw)
  To: Daniel Ridge; +Cc: guile-user, Kevin Ryde

Kevin Ryde <user42@zip.com.au> writes:

> Daniel Ridge <dskr@mac.com> writes:
>>
>> SCM_DEFINE(guile_srcprops_p, "srcprops?", 1, 0, 0,
>
> I don't think that's meant to be visible, merely a compact form of
> what's normally prsented as an alist.

And in any case, your motivating code doesn't use this, does it?

>
>> (let* (
>>           (propl (hash-fold (lambda (k v p) (cons (srcprops-to-plist
>> v) p)) '() source-whash))
>
> I'm not sure if source-whash is actually meant to be used.  But if you
> do then I think `source-properties' can be called on each key in the
> hash to get info in alist form.

Agreed.  So I don't see a remaining argument for exposing these.

Regards,
     Neil



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


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

end of thread, other threads:[~2007-03-06 22:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-28  0:31 Using guile's introspection facilities Daniel Ridge
2007-02-28 22:05 ` Kevin Ryde
2007-03-06 22:01   ` Neil Jerram

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).