unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Creating a list of procedures in a file.
@ 2009-11-18 20:46 Richard Shann
  2009-11-19  0:12 ` Ludovic Courtès
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Shann @ 2009-11-18 20:46 UTC (permalink / raw)
  To: guile-user

I wonder if anyone knows of a method to extract a list of top-level
procedure definitions from a string?
I ask because we are creating procedures for use in scripts written by
users of the GNU Denemo music program and would like to be able to list
them automatically for documentation purposes.
Richard Shann





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

* Re: Creating a list of procedures in a file.
  2009-11-18 20:46 Creating a list of procedures in a file Richard Shann
@ 2009-11-19  0:12 ` Ludovic Courtès
  0 siblings, 0 replies; 5+ messages in thread
From: Ludovic Courtès @ 2009-11-19  0:12 UTC (permalink / raw)
  To: guile-user

Hi,

Richard Shann <richard.shann@virgin.net> writes:

> I wonder if anyone knows of a method to extract a list of top-level
> procedure definitions from a string?

You can use ‘module-for-each’:

  (module-for-each (lambda (name var)
                     (format #t "variable `~A', value `~s'~%" name
                             (variable-ref var)))
                   (resolve-interface '(the denemo module)))

Is it what you’re looking for?

Thanks,
Ludo’.





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

* Re: Creating a list of procedures in a file.
       [not found] <4b057e4a.180db80a.4185.7a18SMTPIN_ADDED@mx.google.com>
@ 2009-11-19 17:53 ` Richard Shann
  2009-11-19 22:41   ` Neil Jerram
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Shann @ 2009-11-19 17:53 UTC (permalink / raw)
  To: guile-user

Thanks for this: the only problem might be that it is the top-level
definitions in Denemo's initialization script that I want to list. I
haven't created a module for it (I wouldn't know how! But as it is very
much an end user, I suppose there is no need).
I tried '(current-module) where you have '(the denemo module) with a
(no code for module (current-module) error message.
Any further thoughts?
Thanks again,

Richard



> From: ludo@gnu.org (Ludovic Court?s )
> Subject: Re: Creating a list of procedures in a file.
> To: guile-user@gnu.org
> Message-ID: <87ws1nfk3u.fsf@gnu.org>
> Content-Type: text/plain; charset=utf-8
> 
> Hi,
> 
> Richard Shann <richard.shann@virgin.net> writes:
> 
> > I wonder if anyone knows of a method to extract a list of top-level
> > procedure definitions from a string?
> 
> You can use module-for-each:
> 
>   (module-for-each (lambda (name var)
>                      (format #t "variable `~A', value `~s'~%" name
>                              (variable-ref var)))
>                    (resolve-interface '(the denemo module)))
> 
> Is it what youre looking for?
> 
> Thanks,
> Ludo.
> 
> 
> 
> 
> 
> ------------------------------
> 
> _______________________________________________
> guile-user mailing list
> guile-user@gnu.org
> http://lists.gnu.org/mailman/listinfo/guile-user
> 
> 
> End of guile-user Digest, Vol 84, Issue 12
> ******************************************





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

* Re: Creating a list of procedures in a file.
  2009-11-19 17:53 ` Richard Shann
@ 2009-11-19 22:41   ` Neil Jerram
  2009-11-20 10:43     ` Richard Shann
  0 siblings, 1 reply; 5+ messages in thread
From: Neil Jerram @ 2009-11-19 22:41 UTC (permalink / raw)
  To: richard.shann; +Cc: guile-user

Richard Shann <richard.shann@virgin.net> writes:

> Thanks for this: the only problem might be that it is the top-level
> definitions in Denemo's initialization script that I want to list. I
> haven't created a module for it (I wouldn't know how! But as it is very
> much an end user, I suppose there is no need).
> I tried '(current-module) where you have '(the denemo module) with a
> (no code for module (current-module) error message.
> Any further thoughts?
> Thanks again,

(current-module) should replace the whole (resolve-interface ...) form,
i.e.:

   (module-for-each (lambda (name var)
                      (format #t "variable `~A', value `~s'~%" name
                              (variable-ref var)))
                    (current-module))

Within Denemo, you could arrange things such that the initialization
script was loaded in the context of a specially created module; then an
approach like the above should be fine.

Alternatively, assuming that it is safe to do so - i.e. that there are
no possible side-effects from reading - you could just read and process
the script.  Something like:

(with-input-from-file FILENAME
  (lambda ()
    (let loop ((x (read)) (defs '()))
      (if (eof-object? x)
          defs
          (loop (read) (if (and (list? x)
                                (>= (length x) 3)
                                (eq? (car x) 'define)
                                (pair? (cadr x)))
                           (cons (caadr x) defs)
                           defs))))))

(completely untested, of course!)

       Neil




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

* Re: Creating a list of procedures in a file.
  2009-11-19 22:41   ` Neil Jerram
@ 2009-11-20 10:43     ` Richard Shann
  0 siblings, 0 replies; 5+ messages in thread
From: Richard Shann @ 2009-11-20 10:43 UTC (permalink / raw)
  To: guile-user

Works like a dream - thank you!
Richard


On Thu, 2009-11-19 at 22:41 +0000, Neil Jerram wrote:
> Richard Shann <richard.shann@virgin.net> writes:
> 
> > Thanks for this: the only problem might be that it is the top-level
> > definitions in Denemo's initialization script that I want to list. I
> > haven't created a module for it (I wouldn't know how! But as it is very
> > much an end user, I suppose there is no need).
> > I tried '(current-module) where you have '(the denemo module) with a
> > (no code for module (current-module) error message.
> > Any further thoughts?
> > Thanks again,
> 
> (current-module) should replace the whole (resolve-interface ...) form,
> i.e.:
> 
>    (module-for-each (lambda (name var)
>                       (format #t "variable `~A', value `~s'~%" name
>                               (variable-ref var)))
>                     (current-module))
> 
> Within Denemo, you could arrange things such that the initialization
> script was loaded in the context of a specially created module; then an
> approach like the above should be fine.
> 
> Alternatively, assuming that it is safe to do so - i.e. that there are
> no possible side-effects from reading - you could just read and process
> the script.  Something like:
> 
> (with-input-from-file FILENAME
>   (lambda ()
>     (let loop ((x (read)) (defs '()))
>       (if (eof-object? x)
>           defs
>           (loop (read) (if (and (list? x)
>                                 (>= (length x) 3)
>                                 (eq? (car x) 'define)
>                                 (pair? (cadr x)))
>                            (cons (caadr x) defs)
>                            defs))))))
> 
> (completely untested, of course!)
> 
>        Neil





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

end of thread, other threads:[~2009-11-20 10:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-18 20:46 Creating a list of procedures in a file Richard Shann
2009-11-19  0:12 ` Ludovic Courtès
     [not found] <4b057e4a.180db80a.4185.7a18SMTPIN_ADDED@mx.google.com>
2009-11-19 17:53 ` Richard Shann
2009-11-19 22:41   ` Neil Jerram
2009-11-20 10:43     ` Richard Shann

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