Changeset 14796 in project


Ignore:
Timestamp:
05/26/09 19:28:23 (10 years ago)
Author:
sjamaan
Message:

Make row/column-fold-right tail recursive; use this improved fold-right in map to reduce total LOC

Location:
release/4/postgresql/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/postgresql/trunk/postgresql.scm

    r14792 r14796  
    710710(define (make-result-fold-right item-count extract-item)
    711711  (lambda (kons knil result)
    712     (let ((items (item-count result)))
    713       (let loop ((seed knil)
    714                  (item 0))
    715         (if (= item items)
    716             seed
    717             (kons (extract-item result item) (loop seed (add1 item))))))))
     712    (let loop ((seed knil)
     713               (item (item-count result)))
     714      (if (= item 0)
     715          seed
     716          (loop (kons (extract-item result (sub1 item)) seed) (sub1 item))))))
    718717
    719718(define row-fold-right (make-result-fold-right row-count row-values))
    720719(define (row-fold-right* kons knil result)
    721   (row-fold-right (lambda (val seed)
    722                     (apply kons (append val (list seed)))) knil result))
     720  (row-fold-right (lambda (values seed)
     721                    (apply kons (append values (list seed)))) knil result))
    723722
    724723(define column-fold-right (make-result-fold-right column-count column-values))
     
    742741  (void))
    743742
    744 
    745743;; Like regular Scheme map, the order in which the procedure is applied is
    746744;; undefined.  We make good use of that by traversing the resultset from
    747745;; the end back to the beginning, thereby avoiding a reverse! on the result.
    748 (define (make-result-map item-count extract-item)
    749   (lambda (proc result)
    750     (let loop ((lst '())
    751                (item (item-count result)))
    752       (if (= item 0)
    753           lst
    754           (loop (cons (proc (extract-item result (sub1 item))) lst) (sub1 item))))))
    755 (define row-map (make-result-map row-count row-values))
    756 (define (row-map* proc result)
    757   (row-map (lambda (values) (apply proc values)) result))
    758 (define column-map (make-result-map column-count column-values))
    759 (define (column-map* proc result)
    760   (column-map (lambda (values) (apply proc values)) result))
     746(define (row-map proc res)
     747  (row-fold-right (lambda (row lst) (cons (proc row) lst)) '() res))
     748(define (row-map* proc res)
     749  (row-fold-right (lambda (row lst) (cons (apply proc row) lst)) '() res))
     750(define (column-map proc res)
     751  (column-fold-right (lambda (col lst) (cons (proc col) lst)) '() res))
     752(define (column-map* proc res)
     753  (column-fold-right (lambda (col lst) (cons (apply proc col) lst)) '() res))
    761754
    762755)
  • release/4/postgresql/trunk/postgresql.setup

    r14776 r14796  
    99 'postgresql
    1010 '("postgresql.so" "postgresql.import.so")
    11  '((version "3.1")
     11 '((version "3.2")
    1212   (documentation "postgresql.html")))
    1313
Note: See TracChangeset for help on using the changeset viewer.