From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Rottmann Newsgroups: gmane.lisp.guile.devel Subject: Re: Fmt Module Date: Sun, 13 Mar 2011 22:37:29 +0100 Message-ID: <87y64ig0rq.fsf@gmx.at> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1300052282 4555 80.91.229.12 (13 Mar 2011 21:38:02 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 13 Mar 2011 21:38:02 +0000 (UTC) Cc: guile-devel To: Noah Lavine Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Mar 13 22:37:57 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Pysz4-0002qk-9C for guile-devel@m.gmane.org; Sun, 13 Mar 2011 22:37:54 +0100 Original-Received: from localhost ([127.0.0.1]:40199 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pysz3-0002oj-Pl for guile-devel@m.gmane.org; Sun, 13 Mar 2011 17:37:53 -0400 Original-Received: from [140.186.70.92] (port=40290 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pysyu-0002lS-GX for guile-devel@gnu.org; Sun, 13 Mar 2011 17:37:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pysys-0004Ln-RI for guile-devel@gnu.org; Sun, 13 Mar 2011 17:37:44 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.22]:55164) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Pysys-0004LY-Al for guile-devel@gnu.org; Sun, 13 Mar 2011 17:37:42 -0400 Original-Received: (qmail invoked by alias); 13 Mar 2011 21:37:38 -0000 Original-Received: from 83-215-154-5.hage.dyn.salzburg-online.at (EHLO nathot.lan) [83.215.154.5] by mail.gmx.net (mp004) with SMTP; 13 Mar 2011 22:37:38 +0100 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX18caFAA6YQcTAnMLEwxRkye/55R0HShalfbeHtYLd VpBEuvG0Ivd/2T Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by nathot.lan (Postfix) with ESMTP id 37A5C3A68F; Sun, 13 Mar 2011 22:37:38 +0100 (CET) Original-Received: from nathot.lan ([127.0.0.1]) by localhost (nathot.lan [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tmxODVdbSF3R; Sun, 13 Mar 2011 22:37:30 +0100 (CET) Original-Received: from delenn.lan (delenn.lan [192.168.3.11]) by nathot.lan (Postfix) with ESMTP id 9DFF83A685; Sun, 13 Mar 2011 22:37:30 +0100 (CET) Original-Received: by delenn.lan (Postfix, from userid 1000) id 0C0E42C00C8; Sun, 13 Mar 2011 22:37:29 +0100 (CET) In-Reply-To: (Noah Lavine's message of "Sat, 12 Mar 2011 16:14:16 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 213.165.64.22 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11865 Archived-At: --=-=-= Content-Type: text/plain Noah Lavine 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. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=+changes-0.7.diff 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)) --=-=-= Content-Type: text/plain Regards, Rotty -- Andreas Rottmann -- --=-=-=--