[Top][All Lists]

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

[Guile-commits] GNU Guile branch, cky-hygienic-macros, updated. v2.0.9-9

From: Chris K. Jester-Young
Subject: [Guile-commits] GNU Guile branch, cky-hygienic-macros, updated. v2.0.9-99-g5b491e4
Date: Sun, 27 Oct 2013 23:11:25 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

The branch, cky-hygienic-macros has been updated
       via  5b491e4f2829d3644c1194c1dcccd320dd7c3ef6 (commit)
      from  98a1e95e9997b8a9b38693bd772fb0e20e88a935 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5b491e4f2829d3644c1194c1dcccd320dd7c3ef6
Author: Chris K. Jester-Young <address@hidden>
Date:   Sun Oct 27 19:06:44 2013 -0400

    Convert (ice-9 i18n) to use hygienic macros.
    * module/ice-9/i18n.scm (define-vector-langinfo-mapping)
      (define-simple-langinfo-mapping, define-monetary-langinfo-mapping):
      Convert to syntax-rules macros. Also change the use of rest parameters
      to instead use case-lambda, in order to fail fast when given more than
      one argument.


Summary of changes:
 module/ice-9/i18n.scm |   65 +++++++++++++++++++++++++-----------------------
 1 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/module/ice-9/i18n.scm b/module/ice-9/i18n.scm
index ca949b4..093a9e4 100644
--- a/module/ice-9/i18n.scm
+++ b/module/ice-9/i18n.scm
@@ -102,18 +102,18 @@
 ;; Helper macro: Define a procedure named NAME that maps its argument to
 ;; NL-ITEMS.  Gnulib guarantees that these items are available.
-(define-macro (define-vector-langinfo-mapping name nl-items)
-  (let* ((item-count (length nl-items))
-         (defines   `(define %nl-items (vector #f ,@nl-items)))
-         (make-body (lambda (result)
-                      `(if (and (integer? item) (exact? item))
-                           (if (and (>= item 1) (<= item ,item-count))
-                               ,result
-                               (throw 'out-of-range "out of range" item))
-                           (throw 'wrong-type-arg "wrong argument type" 
-    `(define (,name item . locale)
-       ,defines
-       ,(make-body '(apply nl-langinfo (vector-ref %nl-items item) locale)))))
+(define-syntax-rule (define-vector-langinfo-mapping name (nl-item ...))
+  (define name
+    (let* ((%nl-items (vector nl-item ...))
+           (nl-item-ref (lambda (item)
+                          (cond ((not (and (integer? item) (exact? item)))
+                                 (throw 'wrong-type-arg "wrong argument type" 
+                                ((not (<= 1 item (vector-length %nl-items)))
+                                 (throw 'out-of-range "out of range" item))
+                                (else
+                                 (vector-ref %nl-items (1- item)))))))
+      (case-lambda ((item)        (nl-langinfo (nl-item-ref item)))
+                   ((item locale) (nl-langinfo (nl-item-ref item) locale))))))
 (define-vector-langinfo-mapping locale-day-short
@@ -140,12 +140,12 @@
 ;; (for instance, `GROUPING' is lacking on Darwin and Gnulib provides no
 ;; replacement), so use DEFAULT as the default value when ITEM is not
 ;; available.
-(define-macro (define-simple-langinfo-mapping name item default)
-  (let ((body (if (defined? item)
-                  `(apply nl-langinfo ,item locale)
-                  default)))
-    `(define (,name . locale)
-       ,body)))
+(define-syntax-rule (define-simple-langinfo-mapping name item default)
+  (define name
+    (if (defined? 'item)
+        (case-lambda (()       (nl-langinfo item))
+                     ((locale) (nl-langinfo item locale)))
+        (lambda* (#:optional locale) default))))
 (define-simple-langinfo-mapping locale-am-string
   AM_STR "AM")
@@ -181,19 +181,22 @@
 ;; or not.  Since Gnulib's `nl_langinfo' module doesn't guarantee that
 ;; all these items are available, use DEFAULT/LOCAL and DEFAULT/INTL as
 ;; default values when the system does not support them.
-(define-macro (define-monetary-langinfo-mapping name local-item intl-item
-                                                default/local default/intl)
-  (let ((body
-         (let ((intl  (if (defined? intl-item)
-                          `(apply nl-langinfo ,intl-item locale)
-                          default/intl))
-               (local (if (defined? local-item)
-                          `(apply nl-langinfo ,local-item locale)
-                          default/local)))
-           `(if intl? ,intl ,local))))
-    `(define (,name intl? . locale)
-       ,body)))
+(define-syntax-rule (define-monetary-langinfo-mapping name local-item intl-item
+                                                      default/local 
+  (define name
+    (let ((intl  (if (defined? 'intl-item)
+                     (case-lambda
+                      (()       (nl-langinfo intl-item))
+                      ((locale) (nl-langinfo intl-item locale)))
+                     (lambda* (#:optional locale) default/intl)))
+          (local (if (defined? 'local-item)
+                     (case-lambda
+                      (()       (nl-langinfo local-item))
+                      ((locale) (nl-langinfo local-item locale)))
+                     (lambda* (#:optional locale) default/local))))
+      (case-lambda
+       ((intl?)        (if intl? (intl) (local)))
+       ((intl? locale) (if intl? (intl locale) (local locale)))))))
 ;; FIXME: How can we use ALT_DIGITS?
 (define-monetary-langinfo-mapping locale-currency-symbol

GNU Guile

reply via email to

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