Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

LISP ZIPPERS

Name: Anonymous 2013-01-17 2:23

Integrating zippers into the very core of Lisp as a replacement/enhancement of cons lists.

Discuss.

Name: Anonymous 2013-01-17 4:21

That's neat. A much needed addition to my spell book.


(library (my-sheiit zippers)
  (export make-zipper zipper zup-list zdown-list zdown zup zdown-null? zup-null? zup-car zdown-car)
  (import (rnrs))

  (define (make-zipper behind forward)
    (cons behind forward))

  (define (zipper . lis)
    (make-zipper '() lis))

  (define zup-list car)

  (define zdown-list cdr)

  (define (zup-null? z)
    (null? (zup-list z)))

  (define (zdown-null? z)
    (null? (zdown-list z)))

  (define (zup-car z)
    (assert (not (zup-null? z)))
    (car (zup-list z)))

  (define (zdown-car z)
    (assert (not (zdown-null? z)))
    (car (zdown-list z)))

  (define (zup z)
    (assert (not (zup-null? z)))
    (make-zipper (cdr (zup-list z))
                 (cons (zup-car z) (zdown-list z))))

  (define (zdown z)
    (assert (not (zdown-null? z)))
    (make-zipper (cons (zdown-car z) (zup-list z))
                 (cdr (zdown-list z)))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List