Changeset 11803 in project


Ignore:
Timestamp:
08/30/08 09:15:42 (12 years ago)
Author:
Alex Shinn
Message:

Copying bugfixes from upstream.

Location:
release/3/fmt
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • release/3/fmt/fmt-c.scm

    r10190 r11803  
    618618(define (c-extern x) (cat "extern " (c-expr x)))
    619619(define (c-extern/C . body)
    620   (cat "extern \"C\" {" fl (apply c-begin body) fl "}" fl))
     620  (cat "extern \"C\" {" nl (apply c-begin body) nl "}" nl))
    621621
    622622(define (c-var type name . init)
  • release/3/fmt/fmt.html

    r10190 r11803  
    1 <html><head></head><body bgcolor=white>
     1<html><head><title>Combinator Formatting</title>
     2</head><body bgcolor=white>
    23
    34<h1><span class=subject>Combinator Formatting</span></h1>
     
    7576</style>
    7677<div align=right><a href="http://synthcode.com/">Alex Shinn</a></div>
    77 <div align=right><a href="http://synthcode.com/scheme/fmt/fmt-0.5.tar.gz">Download Version 0.5</a></div>
     78<div align=right><a href="http://synthcode.com/scheme/fmt/fmt-0.6.tar.gz">Download Version 0.6</a></div>
    7879<p>
    7980
     
    163164  (<span class=variable>load</span> <span class=string>&quot;let-optionals.scm&quot;</span>)  <span class=comment>; if you don't have LET-OPTIONALS*</span>
    164165  (<span class=variable>load</span> <span class=string>&quot;read-line.scm&quot;</span>)      <span class=comment>; if you don't have READ-LINE</span>
     166  (<span class=variable>load</span> <span class=string>&quot;string-ports.scm&quot;</span>)   <span class=comment>; if you don't have CALL-WITH-OUTPUT-STRING</span>
     167  (<span class=variable>load</span> <span class=string>&quot;make-eq-table.scm&quot;</span>)
    165168  (<span class=variable>load</span> <span class=string>&quot;mantissa.scm&quot;</span>)
    166169  (<span class=variable>load</span> <span class=string>&quot;fmt.scm&quot;</span>)
     
    169172  (<span class=variable>load</span> <span class=string>&quot;fmt-c.scm&quot;</span>)          <span class=comment>; optional C formatting utilities</span>
    170173  (<span class=variable>load</span> <span class=string>&quot;fmt-color.scm&quot;</span>)      <span class=comment>; optional color utilities</span>
    171   (<span class=variable>load</span> <span class=string>&quot;fmt-unicode.scm&quot;</span>)    <span class=comment>; optional Unicode-aware formatting</span>
     174  (<span class=variable>load</span> <span class=string>&quot;fmt-unicode.scm&quot;</span>)    <span class=comment>; optional Unicode-aware formatting,</span>
     175                              <span class=comment>;   also requires SRFI-4 or SRFI-66</span>
    172176</pre>
    173177<p>
     
    458462<p>
    459463
    460 <h3>(join &lt;formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
     464<h3>(fmt-join &lt;formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
    461465
    462466Formats each element <code class=scheme><span class=variable>&lt;elt&gt;</span></code> of <code class=scheme><span class=variable>&lt;list&gt;</span></code> with <code class=scheme>(<span class=variable>&lt;formatter&gt;</span>
     
    465469<p>
    466470
    467 <code class=scheme>(<span class=variable>fmt</span> <span class=boolean>#f</span> (<span class=variable>join</span> <span class=variable>dsp</span> '(<span class=variable>a</span> <span class=variable>b</span> <span class=variable>c</span>) <span class=string>&quot;, &quot;</span>))</code>
     471<code class=scheme>(<span class=variable>fmt</span> <span class=boolean>#f</span> (<span class=variable>fmt-join</span> <span class=variable>dsp</span> '(<span class=variable>a</span> <span class=variable>b</span> <span class=variable>c</span>) <span class=string>&quot;, &quot;</span>))</code>
    468472<p>
    469473
     
    471475<p>
    472476
    473 <h3>(join/prefix &lt;formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
    474 
    475 <h3>(join/suffix &lt;formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
    476 
    477 <code class=scheme>(<span class=variable>fmt</span> <span class=boolean>#f</span> (<span class=variable>join/prefix</span> <span class=variable>dsp</span> '(<span class=variable>usr</span> <span class=variable>local</span> <span class=variable>bin</span>) <span class=string>&quot;/&quot;</span>))</code>
     477<h3>(fmt-join/prefix &lt;formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
     478
     479<h3>(fmt-join/suffix &lt;formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
     480
     481<code class=scheme>(<span class=variable>fmt</span> <span class=boolean>#f</span> (<span class=variable>fmt-join/prefix</span> <span class=variable>dsp</span> '(<span class=variable>usr</span> <span class=variable>local</span> <span class=variable>bin</span>) <span class=string>&quot;/&quot;</span>))</code>
    478482<p>
    479483
     
    481485<p>
    482486
    483 As <code class=scheme><span class=variable>join</span></code>, but inserts <code class=scheme><span class=variable>&lt;sep&gt;</span></code> before/after every element.
    484 <p>
    485 
    486 <h3>(join/last &lt;formatter&gt; &lt;last-formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
    487 
    488 As <code class=scheme><span class=variable>join</span></code>, but the last element of the list if formatted with
     487As <code class=scheme><span class=variable>fmt-join</span></code>, but inserts <code class=scheme><span class=variable>&lt;sep&gt;</span></code> before/after every element.
     488<p>
     489
     490<h3>(fmt-join/last &lt;formatter&gt; &lt;last-formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
     491
     492As <code class=scheme><span class=variable>fmt-join</span></code>, but the last element of the list if formatted with
    489493<code class=scheme><span class=variable>&lt;last-formatter&gt;</span></code> instead.
    490494<p>
    491495
    492 <h3>(join/dot &lt;formatter&gt; &lt;dot-formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
    493 
    494 As <code class=scheme><span class=variable>join</span></code>, but if the list is a dotted list, then formats the dotted
     496<h3>(fmt-join/dot &lt;formatter&gt; &lt;dot-formatter&gt; &lt;list&gt; [&lt;sep&gt;])</h3>
     497
     498As <code class=scheme><span class=variable>fmt-join</span></code>, but if the list is a dotted list, then formats the dotted
    495499value with <code class=scheme><span class=variable>&lt;dot-formatter&gt;</span></code> instead.
    496500<p>
     
    639643    (<span class=keyword>define</span> (<span class=variable>print-line</span> <span class=variable>x</span>)
    640644      (<span class=variable>cat</span> (<span class=variable>car</span> <span class=variable>x</span>) (<span class=variable>space-to</span> <span class=number>72</span>) (<span class=variable>pad</span> <span class=number>3</span> (<span class=variable>cdr</span> <span class=variable>x</span>))))
    641     (<span class=variable>fmt</span> <span class=boolean>#t</span> (<span class=variable>pad-char</span> <span class=char>#\.</span> (<span class=variable>join</span> <span class=variable>print-line</span> <span class=variable>alist</span> <span class=variable>nl</span>))))
     645    (<span class=variable>fmt</span> <span class=boolean>#t</span> (<span class=variable>pad-char</span> <span class=char>#\.</span> (<span class=variable>fmt-join</span> <span class=variable>print-line</span> <span class=variable>alist</span> <span class=variable>nl</span>))))
    642646
    643647  (<span class=variable>print-table-of-contents</span>
     
    14091413<tr><td>~&amp; </td><td> <code class=scheme><span class=variable>fl</span></code></td></tr>
    14101414<tr><td>~[...~] </td><td> normal <code class=scheme><span class=keyword>if</span></code> or <code class=scheme><span class=variable>fmt-if</span></code> (delayed test)</td></tr>
    1411 <tr><td>~{...~} </td><td> <code class=scheme>(<span class=variable>join</span> ... <span class=variable>&lt;list&gt;</span> [<span class=variable>&lt;sep&gt;</span>])</code></td></tr>
     1415<tr><td>~{...~} </td><td> <code class=scheme>(<span class=variable>fmt-join</span> ... <span class=variable>&lt;list&gt;</span> [<span class=variable>&lt;sep&gt;</span>])</code></td></tr>
    14121416</table>
    14131417<p>
  • release/3/fmt/fmt.scm

    r10190 r11803  
    11;;;; fmt.scm -- extensible formatting library
    22;;
    3 ;; Copyright (c) 2006-2007 Alex Shinn.  All rights reserved.
     3;; Copyright (c) 2006-2008 Alex Shinn.  All rights reserved.
    44;; BSD-style license: http://synthcode.com/license.txt
    55
     
    673673               ;;     (generate-sci r s m+ m- k)))
    674674               ((and (not digits) (or (> k 14) (< k -4)))
    675                 (write n port))     ; XXXX using native write for now
     675                (write n port))      ; XXXX using native write for now
    676676               (else
    677677                (cond
     
    717717              (let ((i0 (- (+ k digits) 1))
    718718                    (stack (if (<= k 0)
    719                                (append (make-list (- k) 0)
     719                               (append (make-list (min (- k) digits) 0)
    720720                                       (list decimal-sep 0))
    721721                               '())))
     
    759759                     ((< i 0)
    760760                      (let ((d2 (* 2 (if (>= (* r 2) s) (+ d 1) d))))
    761                         (if (or (> d2 base)
    762                                 (and (= d2 base)
    763                                      (pair? stack)
    764                                      (number? (car stack))
    765                                      (odd? (car stack))))
     761                        (if (and (not (> (- k) digits))
     762                                 (or (> d2 base)
     763                                     (and (= d2 base)
     764                                          (pair? stack)
     765                                          (number? (car stack))
     766                                          (odd? (car stack)))))
    766767                            (flush/rounded)
    767768                            (flush))))
    768769                     ((smaller r m-)
    769                       (flush)
    770                       (if (bigger (+ r m+) s)
    771                           (pad (if (< (* r 2) s) d (+ d 1)) i)
    772                           (pad d i)))
     770                      (cond
     771                       ((= d base)
     772                        (flush/rounded)
     773                        (pad 0 i))
     774                       (else
     775                        (flush)
     776                        (if (bigger (+ r m+) s)
     777                            (pad (if (< (* r 2) s) d (+ d 1)) i)
     778                            (pad d i)))))
    773779                     ((bigger (+ r m+) s)
    774780                      (flush)
     
    820826        (let ((imag (imag-part n)))
    821827          (cond
     828           ((and base (not (and (integer? base) (<= 2 base 36))))
     829            (error "invalid base for numeric formatting" base))
    822830           ((zero? imag)
    823831            (cond
     
    828836             (else
    829837              (write-real n sign?))))
    830            (else (write-real imag sign?)
    831                  (write-real (real-part n) #t)
     838           (else (write-real (real-part n) sign?)
     839                 (write-real imag #t)
    832840                 (write-char #\i port))))))))
    833841
  • release/3/fmt/fmt.setup

    r10312 r11803  
    99 'fmt
    1010 '("fmt.so")
    11  `((version 0.515)
     11 `((version 0.516)
    1212   (documentation "fmt.html")
    1313         ,@(if has-exports? `((exports "fmt.exports")) '())) )
     
    2121 'fmt-c
    2222 '("fmt-c.so")
    23  `((version 0.515)
     23 `((version 0.516)
    2424   (documentation "fmt.html")
    2525         ,@(if has-exports? `((exports "fmt-c.exports")) '())) )
     
    3333 'fmt-color
    3434 '("fmt-color.so")
    35  `((version 0.515)
     35 `((version 0.516)
    3636   (documentation "fmt.html")
    3737         ,@(if has-exports? `((exports "fmt-color.exports")) '())) )
     
    4545 'fmt-unicode
    4646 '("fmt-unicode.so")
    47  `((version 0.515)
     47 `((version 0.516)
    4848   (documentation "fmt.html")
    4949         ,@(if has-exports? `((exports "fmt-unicode.exports")) '())) )
  • release/3/fmt/test-fmt.scm

    r10190 r11803  
    6161(test "3.00" (fmt #f (fix 2 3.)))
    6262(test "1.10" (fmt #f (num 1.099 10 2)))
     63(test "0.00" (fmt #f (fix 2 1e-17)))
     64(test "0.0000000000" (fmt #f (fix 10 1e-17)))
     65(test "0.00000000000000001000" (fmt #f (fix 20 1e-17)))
     66(test-error (fmt #f (num 1e-17 0)))
    6367
    6468(test "11.75" (fmt #f (num 47/4 10 2)))
     
    7983(test "1.00" (fmt #f (fix 2 (num/fit 4 1))))
    8084(test "#.##" (fmt #f (fix 2 (num/fit 4 12.345))))
     85
     86(cond
     87 ((feature? 'full-numeric-tower)
     88  (test "1+2i" (fmt #f (string->number "1+2i")))
     89  (test "1+2i" (fmt #f (num (string->number "1+2i"))))
     90  (test "1.00+2.00i" (fmt #f (fix 2 (num (string->number "1+2i")))))
     91  (test "3.14+2.00i" (fmt #f (fix 2 (num (string->number "3.14159+2i")))))))
    8192
    8293(test "3.9Ki" (fmt #f (num/si 3986)))
Note: See TracChangeset for help on using the changeset viewer.