From: Ian Price <ianprice90@googlemail.com>
To: Panicz Maciej Godek <godek.maciek@gmail.com>
Cc: guile-user@gnu.org
Subject: Re: Module reflection and the list of bound symbols
Date: Sun, 30 Sep 2012 14:21:13 +0100 [thread overview]
Message-ID: <87ehljr6ie.fsf@googlemail.com> (raw)
In-Reply-To: <CAMFYt2bkn4fv84FCtJCnkU6EnG+CT-MMzOdghCzOTTZ=HH-KhQ@mail.gmail.com> (Panicz Maciej Godek's message of "Fri, 28 Sep 2012 19:37:17 +0200")
Panicz Maciej Godek <godek.maciek@gmail.com> writes:
> On the other hand, there is no way (or I haven't found one)
> to list the bound symbols explicitly. It seems tempting to
> have a reflection function `module-symbols' or `environment-symbols'
> that would return the names of bound symbols,
> or to have functions like environment->list or module->list that
> would return assoc lists mapping symbols to their values.
Hmm, no, but you are able to get the "obarray" for the module which is a
hash of symbols -> variables.
(define (hash-keys hash)
(hash-fold (lambda (key val prev)
(cons key prev))
'()
hash))
(define (module-exports module)
(hash-keys (module-obarray module)))
scheme@(guile−user)> (module-exports (resolve-module '(pfds queues)))
$20 = (queue−>list queue−empty−condition? enqueue &queue−empty
queue−length make−queue rotate queue−l∧ dummy queue−l
make−queue−empty−condition %module−public−interface list−>queue
dequeue queue−empty? queue? queue %make−queue queue−r makeq)
This lists _all_ the bindings, even the non-public ones.
I'm sure there is a way to get only the public (exported) ones using the
interfaces, but that is beyond my knowledge at the moment.
--
Ian Price -- shift-reset.com
"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
next prev parent reply other threads:[~2012-09-30 13:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-28 17:37 Module reflection and the list of bound symbols Panicz Maciej Godek
2012-09-29 5:28 ` Thien-Thi Nguyen
2012-09-30 13:21 ` Ian Price [this message]
2012-09-30 16:21 ` David Pirotte
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ehljr6ie.fsf@googlemail.com \
--to=ianprice90@googlemail.com \
--cc=godek.maciek@gmail.com \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).