[plt-scheme] reverse operation - how fast?

From: Hans Oesterholt-Dijkema (hdnews at gawab.com)
Date: Fri Apr 8 08:18:54 EDT 2005

Dear All,

Could someone tell me what the performance impact
is of the 'reverse' primitive in the code beneath:

*********************************************
(define (get-element-from-fifo fifo)
  (let ((elem (car (reverse (car fifo)))))
    (set-car! fifo (reverse (cdr (reverse (car fifo)))))
    elem))
*********************************************

*********************************************
...rest of code...

(define (fifo? fifo)
  (if (list? fifo)
      (if (null? fifo)
      #f
      (if (null? (cdr fifo))
          #f
          (eq? (cadr fifo) 'fifo)))
      #f))

(define (new-fifo) (list (list) 'fifo))

(define (empty-fifo? fifo)
  (null? (car fifo)))

(define (add-element-to-fifo fifo elem)
  (set-car! fifo (cons elem (car fifo))))

(define (empty-fifo! fifo)
  (set-car! fifo (list)))
*********************************************

Thank you in advance for your answer,

Hans



Posted on the users mailing list.