[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: What's the deal with the module system?
From: |
David Kastrup |
Subject: |
Re: What's the deal with the module system? |
Date: |
Tue, 24 Nov 2009 16:03:07 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) |
Han-Wen Nienhuys <address@hidden> writes:
> On Mon, Nov 23, 2009 at 1:21 PM, David Kastrup <address@hidden> wrote:
>
>>> lilypond a.ly b.ly
>>>
>>> we want to reuse the built-in definitions, without changes effected in
>>> a.ly leaking into the processing of b.ly
>>
>> Wouldn't just putting the built-in definition at public scope accomplish
>> that?
>
> I don't know. Why don't you try it, and send us a patch if it passes
> the regression tests?
After applying <URL:http://codereview.appspot.com/160048> first,
indeed the following diff that throws out all the toplevel scoping
constructs and separate definitions of define-markup-command and
define-markup-list-command passes the regressions tests. Furthermore,
tests show that the namespace of markups defined in one input file does
not extend into the next input file.
Shrug.
diff --git a/ly/markup-init.ly b/ly/markup-init.ly
index 5749c7b..c678391 100644
--- a/ly/markup-init.ly
+++ b/ly/markup-init.ly
@@ -2,119 +2,3 @@
\version "2.12.0"
-%%;; to be define later, in a closure
-#(define-public toplevel-module-define-public! #f)
-#(define-public toplevel-module-ref #f)
-#(let ((toplevel-module (current-module)))
- (set! toplevel-module-define-public!
- (lambda (symbol value)
- (module-define! toplevel-module symbol value)
- (module-export! toplevel-module (list symbol))))
- (set! toplevel-module-ref
- (lambda (symbol)
- (module-ref toplevel-module symbol))))
-
-#(defmacro-public define-public-toplevel
- (first-arg . rest)
- "Define a public variable or function in the toplevel module:
- (define-public-toplevel variable-name value)
-or:
- (define-public-toplevel (function-name . args)
- ..body..)"
- (if (symbol? first-arg)
- ;; (define-public-toplevel symbol value)
- (let ((symbol first-arg)
- (value (car rest)))
- `(toplevel-module-define-public! ',symbol ,value))
- ;; (define-public-toplevel (function-name . args) . body)
- (let ((function-name (car first-arg))
- (arg-list (cdr first-arg))
- (body rest))
- `(toplevel-module-define-public!
- ',function-name
- (let ((proc (lambda ,arg-list
- ,@body)))
- (set-procedure-property! proc
- 'name
- ',function-name)
- proc)))))
-
-#(defmacro-public define-markup-command (command-and-args signature . body)
- "
-* Define a COMMAND-markup function after command-and-args and body,
-register COMMAND-markup and its signature,
-
-* add COMMAND-markup to markup-function-list,
-
-* sets COMMAND-markup markup-signature and markup-keyword object properties,
-
-* define a make-COMMAND-markup function.
-
-Syntax:
- (define-markup-command (COMMAND layout props arg1 arg2 ...)
- (arg1-type? arg2-type? ...)
- \"documentation string\"
- ...command body...)
-or:
- (define-markup-command COMMAND (arg1-type? arg2-type? ...) function)
-"
- (let* ((command (if (pair? command-and-args)
- (car command-and-args)
- command-and-args))
- (command-name (string->symbol (format #f "~a-markup" command)))
- (make-markup-name (string->symbol (format #f "make-~a-markup"
command))))
- `(begin
- ;; define the COMMAND-markup procedure in toplevel module
- ,(if (pair? command-and-args)
- ;; 1/ (define (COMMAND-markup layout props arg1 arg2 ...)
- ;; ..command body))
- `(define-public-toplevel (,command-name ,@(cdr command-and-args))
- ,@body)
- ;; 2/ (define (COMMAND-markup . args) (apply function args))
- (let ((args (gensym "args"))
- (command (car body)))
- `(define-public-toplevel (,command-name . ,args)
- (apply ,command ,args))))
- (let ((command-proc (toplevel-module-ref ',command-name)))
- ;; register its command signature
- (set! (markup-command-signature command-proc)
- (list ,@signature))
- ;; define the make-COMMAND-markup procedure in the toplevel module
- (define-public-toplevel (,make-markup-name . args)
- (make-markup command-proc
- ,(symbol->string make-markup-name)
- (list ,@signature)
- args))))))
-
-#(defmacro-public define-markup-list-command (command-and-args signature .
body)
- "Same as `define-markup-command', but defines a command that, when
interpreted,
-returns a list of stencils, instead of a single one."
- (let* ((command (if (pair? command-and-args)
- (car command-and-args)
- command-and-args))
- (command-name (string->symbol (format #f "~a-markup-list" command)))
- (make-markup-name (string->symbol (format #f "make-~a-markup-list"
command))))
- `(begin
- ;; define the COMMAND-markup-list procedure in toplevel module
- ,(if (pair? command-and-args)
- ;; 1/ (define (COMMAND-markup-list layout props arg1 arg2 ...)
- ;; ..command body))
- `(define-public-toplevel (,command-name ,@(cdr command-and-args))
- ,@body)
- ;; 2/ (define (COMMAND-markup-list . args) (apply function args))
- (let ((args (gensym "args"))
- (command (car body)))
- `(define-public-toplevel (,command-name . ,args)
- (apply ,command ,args))))
- (let ((command-proc (toplevel-module-ref ',command-name)))
- ;; register its command signature
- (set! (markup-command-signature command-proc)
- (list ,@signature))
- ;; it's a markup-list command:
- (set-object-property! command-proc 'markup-list-command #t)
- ;; define the make-COMMAND-markup-list procedure in the toplevel module
- (define-public-toplevel (,make-markup-name . args)
- (list (make-markup command-proc
- ,(symbol->string make-markup-name)
- (list ,@signature)
- args)))))))
diff --git a/scm/markup.scm b/scm/markup.scm
index 194c971..2a784b3 100644
--- a/scm/markup.scm
+++ b/scm/markup.scm
@@ -144,6 +144,8 @@ where:
(let ((sig (list ,@signature)))
(make-markup ,command-name ,(symbol->string make-markup-name) sig
args))))))
+(define-public define-markup-command define-builtin-markup-command)
+
(defmacro* define-builtin-markup-list-command
(command-and-args signature #:key (properties '()) #:rest body)
"Same as `define-builtin-markup-command, but defines a command that, when
@@ -208,6 +210,8 @@ interpreted, returns a list of stencils instead os a single
one"
(list (make-markup ,command-name
,(symbol->string make-markup-name) sig
args)))))))
+(define-public define-markup-list-command define-builtin-markup-list-command)
+
(define-public (make-markup markup-function make-name signature args)
" Construct a markup object from MARKUP-FUNCTION and ARGS. Typecheck
against SIGNATURE, reporting MAKE-NAME as the user-invoked function.
--
David Kastrup
- What's the deal with the module system?, David Kastrup, 2009/11/23
- Re: What's the deal with the module system?, Han-Wen Nienhuys, 2009/11/23
- Re: What's the deal with the module system?, David Kastrup, 2009/11/23
- Re: What's the deal with the module system?, Han-Wen Nienhuys, 2009/11/23
- Re: What's the deal with the module system?, David Kastrup, 2009/11/23
- Re: What's the deal with the module system?, Nicolas Sceaux, 2009/11/23
- Re: What's the deal with the module system?, David Kastrup, 2009/11/23
- Re: What's the deal with the module system?, Nicolas Sceaux, 2009/11/24
- Re: What's the deal with the module system?, David Kastrup, 2009/11/24
- Re: What's the deal with the module system?, David Kastrup, 2009/11/24
- Re: What's the deal with the module system?,
David Kastrup <=
- Re: What's the deal with the module system?, Neil Puttock, 2009/11/24
- Re: What's the deal with the module system?, David Kastrup, 2009/11/25
- Re: What's the deal with the module system?, David Kastrup, 2009/11/25
- Re: What's the deal with the module system?, Reinhold Kainhofer, 2009/11/25
- Re: What's the deal with the module system?, David Kastrup, 2009/11/25
- Re: What's the deal with the module system?, John Mandereau, 2009/11/25
- Re: What's the deal with the module system?, David Kastrup, 2009/11/25
- Re: What's the deal with the module system?, John Mandereau, 2009/11/25
- Re: What's the deal with the module system?, David Kastrup, 2009/11/25
- Re: What's the deal with the module system?, Graham Percival, 2009/11/25