Noah Lavine <noah.b.lav...@gmail.com> writes: > Hello all, > > I just completed packaging Alex Shinn's fmt library for Guile, and I'd > like us to include it in the trunk. The library's home page (with > documentation!) is http://synthcode.com/scheme/fmt/. > Not that I have any say in that, but IMHO, it would be preferable to keep external libraries maintained separatly from the Guile core; however in this case, including it in the core might be justified by its proposed use in the JIT compiler.
FWIW, there's already an R6RS adaption of "fmt"[1] as part of the Wak project[0], which works nicely with Guile (from the stable-2.0 branch). [0] http://home.gna.org/wak/ [1] http://gitorious.org/wak/wak-fmt > It looks like a nice formatting library, > Indeed! > and I imagine it would be useful to people who want to generate html > for the web module. > For that, I'd rather suggest building up SXML and use SSAX[2] or HtmlPrag[3] for serialization. [2] http://ssax.sourceforge.net/ [3] http://www.neilvandyke.org/htmlprag/ > However, the real reason I want it in is because it has the ability to > format C source code nicely, and all of the plans for the JIT complier > involve automatically generating a lot of C. > Yeah, that makes sense. > (I'm only attaching the basic library right now, but I hope to package > up the C formatting stuff soon.) > Well, the Wak adaption has this stuff already done ;-). > The files are all attached. To use the library, put all of the files > in a folder, open Guile in that folder, do (load "fmt-guile.scm"), and > then (use-modules (fmt fmt)). If you want to test the library, do > (load "test-fmt.scm"). It passes all tests on my machine. > Having a quick glance at the code, I think you should refrain from using `load', and use `include' instead (it seems that the latter is undocumented, unfortunatly). Also, it should not be necessary to `load' any file before doing `(use-modules (fmt fmt))' -- the latter should be enough if the code is organized appropriatly (i.e. files placed into the right directories). You might want to have a look at how the R6RS port is organized (see the git repo at [1]). > fmt-guile.scm is a new file, but the other ones are almost identical > to the upstream version. I'm going to try to get the changes merged so > it will be easy for us to maintain. > Could you produce a diff? FWIW, I've attached the changes in the Wak adaption -- there are only differences in the test suite, which uses some implementation-specifics, and also `cond-expand' which is not available on Racket (which is one of the implementations targetet by Wak). I've not yet bothered to submit those upstream, since I assume they would not be accepted, as they (a) disable some tests that rely on implementation-specific extensions (b) probably break on the author's system.
Only in .: +changes-0.7.diff Only in /home/rotty/src/_readonly/fmt-0.7/: .hgignore Only in /home/rotty/src/_readonly/fmt-0.7/: Makefile Only in /home/rotty/src/_readonly/fmt-0.7/: README Only in /home/rotty/src/_readonly/fmt-0.7/: VERSION Only in /home/rotty/src/_readonly/fmt-0.7/: fmt Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-c-chicken.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-c-gauche.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-c-mzscheme.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-chicken.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-color-chicken.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-color-gauche.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-color-mzscheme.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-gauche.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-mzscheme.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-scheme48.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-unicode-chicken.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-unicode-gauche.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt-unicode-mzscheme.scm Only in /home/rotty/src/_readonly/fmt-0.7/: fmt.css Only in /home/rotty/src/_readonly/fmt-0.7/: fmt.html Only in /home/rotty/src/_readonly/fmt-0.7/: fmt.meta Only in /home/rotty/src/_readonly/fmt-0.7/: fmt.mistie Only in /home/rotty/src/_readonly/fmt-0.7/: fmt.setup Only in /home/rotty/src/_readonly/fmt-0.7/: let-optionals.scm Only in /home/rotty/src/_readonly/fmt-0.7/: make-eq-table.scm Only in /home/rotty/src/_readonly/fmt-0.7/: read-line.scm Only in /home/rotty/src/_readonly/fmt-0.7/: srfi-33.scm Only in /home/rotty/src/_readonly/fmt-0.7/: srfi-69.scm Only in /home/rotty/src/_readonly/fmt-0.7/: string-ports.scm diff -bur /home/rotty/src/_readonly/fmt-0.7//test-fmt.scm ./test-fmt.scm --- /home/rotty/src/_readonly/fmt-0.7//test-fmt.scm 2009-10-11 10:04:55.000000000 +0200 +++ ./test-fmt.scm 2010-04-12 11:03:16.000000000 +0200 @@ -1,21 +1,20 @@ -(cond-expand - (chicken (use test) (load "fmt-chicken.scm")) - (gauche - (use gauche.test) - (use text.fmt) - (define test-begin test-start) - (define orig-test (with-module gauche.test test)) - (define-syntax test +(define-syntax test (syntax-rules () - ((test name expected expr) - (guard (e (else #f)) - (orig-test name expected (lambda () expr)))) ((test expected expr) - (test (let ((s (with-output-to-string (lambda () (write 'expr))))) - (substring s 0 (min 60 (string-length s)))) - expected expr))))) - (else)) + (test-equal expected expr)))) + +;; pretty printing + +;; (define-macro (test-pretty str) +;; (let ((sexp (with-input-from-string str read))) +;; `(test ,str (fmt #f (pretty ',sexp))))) + +(define-syntax test-pretty + (syntax-rules () + ((test-pretty str) + (let ((sexp (call-with-string-input-port str read))) + (test str (fmt #f (pretty sexp))))))) (test-begin "fmt") @@ -123,12 +122,10 @@ (test "1.00" (fmt #f (fix 2 (num/fit 4 1)))) (test "#.##" (fmt #f (fix 2 (num/fit 4 12.345)))) -;; (cond -;; ((feature? 'full-numeric-tower) -;; (test "1+2i" (fmt #f (string->number "1+2i"))) -;; (test "1+2i" (fmt #f (num (string->number "1+2i")))) -;; (test "1.00+2.00i" (fmt #f (fix 2 (num (string->number "1+2i"))))) -;; (test "3.14+2.00i" (fmt #f (fix 2 (num (string->number "3.14159+2i"))))))) +(test "1+2i" (fmt #f (string->number "1+2i"))) +(test "1+2i" (fmt #f (num (string->number "1+2i")))) +(test "1.00+2.00i" (fmt #f (fix 2 (num (string->number "1+2i"))))) +(test "3.14+2.00i" (fmt #f (fix 2 (num (string->number "3.14159+2i"))))) (test "3.9Ki" (fmt #f (num/si 3986))) (test "4k" (fmt #f (num/si 3986 1000))) @@ -185,7 +182,7 @@ (test "prefix: defgh" (fmt #f "prefix: " (fit/left 5 "abcdefgh"))) (test "prefix: cdefg" (fmt #f "prefix: " (fit/both 5 "abcdefgh"))) -(test "abc\n123\n" (fmt #f (fmt-join/suffix (cut trim 3 <>) (string-split "abcdef\n123456\n" "\n") nl))) +(test "abc\n123\n" (fmt #f (fmt-join (cut trim 3 <>) (string-split "abcdef\n123456\n" "\n") nl))) ;; utilities @@ -224,18 +221,6 @@ (wrt/unshared (let ((ones (list 1))) (set-cdr! ones ones) ones))))) -;; pretty printing - -;; (define-macro (test-pretty str) -;; (let ((sexp (with-input-from-string str read))) -;; `(test ,str (fmt #f (pretty ',sexp))))) - -(define-syntax test-pretty - (syntax-rules () - ((test-pretty str) - (let ((sexp (with-input-from-string str read))) - (test str (fmt #f (pretty sexp))))))) - (test-pretty "(foo bar)\n") (test-pretty @@ -422,22 +407,24 @@ ;; misc extras +#; (define (string-hide-passwords str) (string-substitute (regexp "(pass(?:w(?:or)?d)?\\s?[:=>]\\s+)\\S+" #t) "\\1******" str #t)) - +#; (define hide-passwords (make-string-fmt-transformer string-hide-passwords)) +#; (define (string-mangle-email str) (string-substitute (regexp "\\b([-+.\\w]+)@((?:[-+\\w]+\\.)+[a-z]{2,4})\\b" #t) "\\1 _at_ \\2" str #t)) - +#; (define mangle-email (make-string-fmt-transformer string-mangle-email))
Regards, Rotty -- Andreas Rottmann -- <http://rotty.yi.org/>