unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: David Pirotte <david@altosw.be>
To: Ian Price <ianprice90@googlemail.com>
Cc: guile-user@gnu.org
Subject: Re: Module reflection and the list of bound symbols
Date: Sun, 30 Sep 2012 13:21:06 -0300	[thread overview]
Message-ID: <20120930132106.49c5edac@capac> (raw)
In-Reply-To: <87ehljr6ie.fsf@googlemail.com>

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

Hello,

> ... to get only the public (exported) ones using the
> interfaces, but that is beyond my knowledge at the moment.

Here is what i do, see the attached code [which i copied from
guile-gnome], then you can use it this way, as an example:

1. you define a module b and export some ...

2.

   ;;; file a.scm STARTS here
   (define-module (a)
     :use-module (reexport)  
     :use-module (b))
     :export ... ...

   (eval-when (compile load eval)
     (re-export-public-interface (b)))

   ;; your code here...
   ;; ...
   ;;; file a.scm ENDS here

3.

   finally:

   guile
   scheme@(guile-user)> (use-modules (a))
   ;; then you can use both public interface from a and b
      

Of course this is true for any module which uses the module a [it can
refers to the public interface of b too...]

Hope this helps,
Cheers,
David

ps:	i have always tought guile itself should provide this feature as built-in

[-- Attachment #2: reexport.scm --]
[-- Type: text/x-scheme, Size: 1417 bytes --]

;; -*- mode: scheme; coding: utf-8 -*-

;;;; Copyright (C) 2011, 2012
;;;; Free Software Foundation, Inc.

;;;; This library is free software: you can redistribute it and/or
;;;; modify it under the terms of the GNU General Public License as
;;;; published by the Free Software Foundation, either version 3 of
;;;; the License, or (at your option) any later version.

;;;; This library is distributed in the hope that it will be useful, but
;;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;;; General Public License for more details.

;;;; You should have received a copy of the GNU General Public License
;;;; along with this library.  If not, see <http://www.gnu.org/licenses/>.
;;;;

;;; Commentary:

;; this code is the same as the one use by guile-gnome, see
;; /usr/local/share/guile-gnome-2/gnome/gw/support/modules.scm

;;; Code:

(define-module (macros reexport)
  :export (re-export-public-interface))


(define-macro (re-export-public-interface . args)
  "Re-export the public interface of a module or modules. Invoked as
@code{(re-export-modules (mod1) (mod2)...)}."
  (if (null? args)
      '(if #f #f)
      `(begin
	 ,@(map (lambda (mod)
		  (or (list? mod)
		      (error "Invalid module specification" mod))
		  `(module-use! (module-public-interface (current-module))
				(resolve-interface ',mod)))
		args))))

      reply	other threads:[~2012-09-30 16: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
2012-09-30 16:21   ` David Pirotte [this message]

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=20120930132106.49c5edac@capac \
    --to=david@altosw.be \
    --cc=guile-user@gnu.org \
    --cc=ianprice90@googlemail.com \
    /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).