guile-user
[Top][All Lists]
Advanced

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

Re: modules, 2nd try.


From: Neil Jerram
Subject: Re: modules, 2nd try.
Date: 19 Sep 2002 22:14:38 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

>>>>> "Han-Wen" == Han-Wen Nienhuys <address@hidden> writes:

    Han-Wen> After getting no response on the devel list, let me try once more,

OK, here's roughly how I think I'd do it ...

First you need a root module.

(define (next-module-name)
  ;; Procedure that generates unique module names
  ;; (lily m0), (lily m1), (lily m2), ...
  )
(define root-module (resolve-module (next-module-name)))
(beautify-user-module! root-module)

(define lily-current-module root-module)

    Han-Wen>    %identifier = ... defines a variable 
    Han-Wen>    variableOne = 5.0

(module-define! lily-current-module 'variableOne 5.0)
(module-export! lily-current-module 'variableOne)

    Han-Wen>    \score {

Moving into a sub-scope, so ...

(define submodule (resolve-module (next-module-name)))
(beautify-user-module submodule)

(module-use! submodule (module-public-interface lily-current-module))

;; At this point you want to mark all the variables imported from
;; lily-current-module for re-export.  I'm not sure how you could do
;; this.  Perhaps something involving module-map or module-for-each.

(set! lily-current-module submodule)

    Han-Wen>           ..music..

    Han-Wen>           \paper  {

Another sub-scope, so same again.

    Han-Wen>                   % The paper block introduces a new scope.

    Han-Wen>                   variableTwo = 5.0\cm

(module-define! lily-current-module 'variableTwo 5.0)
(module-export! lily-current-module 'variableTwo)

    Han-Wen>                   % \identifier references a variable.
    Han-Wen>                   linewidth = \variableOne * \variableTwo

(module-define! lily-current-module 'linewidth (* variableOne variableTwo))
(module-export! lily-current-module 'linewidth)

    Han-Wen>           }

Ah :-) For exiting scopes, you should restore the previous
lily-current-module; so you'll need to keep a stack of
lily-current-modules.

As usual, I haven't actually tested any of this (!)  If you want to
see working examples of manual module munging code (although with
different aims from yours, kind of), look at `use-elisp-file' in
lang/elisp/interface.scm and `fset' in lang/elisp/internals/fset.scm,
both in CVS.

Hoping this helps ...

        Neil





reply via email to

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