guile-devel
[Top][All Lists]
Advanced

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

Re: %module-public-interface


From: Ludovic Courtès
Subject: Re: %module-public-interface
Date: Tue, 30 Mar 2010 23:52:01 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Hello,

Andy Wingo <address@hidden> writes:

> On Tue 30 Mar 2010 22:56, address@hidden (Ludovic Courtès) writes:
>
>>> I'm pretty sure that the submodule thing can be changed without any
>>> problem. But it seems that the %module-public-interface is used
>>> explicitly, at least by texmacs and lilypond.
>>
>> How do they use it?
>
> Linking to the evil empire:
>
> http://www.google.com/codesearch?hl=en&lr=&q=%25module-public-interface&sbtn=Search
> http://www.google.com/codesearch?hl=en&lr=&q=%25module-public-interface+lang%3Ac%2B%2B&sbtn=Search

Lilypond does:

--8<---------------cut here---------------start------------->8---
      mod = scm_call_0 (maker);
      scm_module_define (mod, ly_symbol2scm ("%module-public-interface"),
                         mod);
--8<---------------cut here---------------end--------------->8---

Solution: do something like:

--8<---------------cut here---------------start------------->8---
#ifdef HAVE_SCM_SET_MODULE_PUBLIC_INTERFACE_X
  scm_set_module_public_interface_x (mod, mod);
#else
  scm_module_define (mod, ly_symbol2scm ("%module-public-interface"),
                     mod);
#endif
--8<---------------cut here---------------end--------------->8---

(We just need to add that function.)

TeXmacs does:

--8<---------------cut here---------------start------------->8---
    (let* ((m (resolve-module which))
           (m-public (module-ref m '%module-public-interface)))
      (module-map (lambda (sym var) sym) m-public)))
--8<---------------cut here---------------end--------------->8---

and:

--8<---------------cut here---------------start------------->8---
           (let* ((m (resolve-module ',module))
                  (p (module-ref texmacs-user '%module-public-interface))
                  (r (module-ref p ',name #f)))
             (if (not r)
                 (texmacs-error "lazy-define"
                                ,(string-append "Could not retrieve "
                                                (symbol->string name))))
             (apply r args))))))
--8<---------------cut here---------------end--------------->8---

Solution: use ‘resolve-interface’.

Gossip does:

--8<---------------cut here---------------start------------->8---
        (append! (delq! '%module-public-interface
                        (module-map (lambda (sym var) sym) mod))
                 (hash-fold (lambda (k v r) (cons k r)) '() blocks)))
--8<---------------cut here---------------end--------------->8---

This snippet won’t see any difference.

>> And we could add a ‘public-interface’ slot to ‘module-type’ and have
>> ‘module-public-interface’ and ‘set-module-public-interface!’ refer to
>> it; for backward compatibility we’d also initialize the
>> ‘%module-public-interface’ binding.  How does it sound?

Actually the trick wouldn’t work in cases where the
‘%module-public-interface’ binding is mutated, as with Lilypond.

Given this and the above examples, I’d suggest dropping that binding
completely and sending patches to the Lilypond/TeXmacs people.

What do you think?

Thanks,
Ludo’.





reply via email to

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