chicken-users
[Top][All Lists]
Advanced

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

[Chicken-users] srfi-101 egg


From: Jörg F. Wittenberger
Subject: [Chicken-users] srfi-101 egg
Date: Sat, 07 Nov 2015 16:37:27 +0100
User-agent: Mozilla/5.0 (X11; Linux armv7l; rv:31.0) Gecko/20100101 Icedove/31.7.0

Hi,

Am 07.11.2015 um 14:51 schrieb "Jörg F. Wittenberger":> Am 06.11.2015 um
22:16 schrieb Mario Domenech Goulart:
...
>> Note that we already have srfi-101 packaged as an egg:
>> http://wiki.call-cc.org/eggref/4/srfi-101

I'm curious how much chicken will do on this wrt. optimization.  While
packaging I noticed that the reference implementations is rather heavy
in the way it implements car and cdr.   When packaging I took the
freedom to change to implementation in a way I believe should be more
efficient.  See below.

(Besides I added type declarations, which may be sometimes useful to  have.)

So maybe this is mostly going to Konv Lovett as the one who packaged the
srfi-101 egg...

Best

/Jörg


The reference implementation does it like this:

(define ra:car+cdr
  (lambda (p)
    (assert (kons? p))
    (if (node? (kons-tree p))
        (let ((s* (half (kons-size p))))
          (values (tree-val (kons-tree p))
                  (make-kons s*
                             (node-left (kons-tree p))
                             (make-kons s*
                                        (node-right (kons-tree p))
                                        (kons-rest p)))))
        (values (kons-tree p) (kons-rest p)))))

;; (RaPair X Y) -> X
(define (ra:car p)
  (call-with-values (lambda () (ra:car+cdr p))
                    (lambda (car cdr) car)))


I changed it into this, to avoid construction of objects just to be
ignored (and multiple value passing).

(define (ra:car p)
    #;(assert (kons? p))
    (if (node? (kons-tree p))
        (tree-val (kons-tree p))
        (kons-tree p)))

  ;; [RaPair X Y] -> Y
  (: ra:cdr (:kons: --> *))
  (define (ra:cdr p)
    #;(assert (kons? p))
    (if (node? (kons-tree p))
        (let ((s* (half (kons-size p))))
          (make-kons s*
                     (node-left (kons-tree p))
                     (make-kons s*
                                (node-right (kons-tree p))
                                (kons-rest p))))
        (kons-rest p)))






reply via email to

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