2006-12-07 02:48:31 -05:00
|
|
|
|
2007-02-11 21:42:01 -05:00
|
|
|
|
2007-05-05 05:06:32 -04:00
|
|
|
(library (ikarus pairs)
|
2007-05-06 18:43:04 -04:00
|
|
|
(export
|
|
|
|
cons weak-cons set-car! set-cdr! car cdr caar cdar cadr cddr
|
|
|
|
caaar cdaar cadar cddar caadr cdadr caddr cdddr caaaar cdaaar
|
|
|
|
cadaar cddaar caadar cdadar caddar cdddar caaadr cdaadr cadadr
|
|
|
|
cddadr caaddr cdaddr cadddr cddddr)
|
2007-05-05 02:28:30 -04:00
|
|
|
(import
|
2007-05-06 18:43:04 -04:00
|
|
|
(except (ikarus) cons weak-cons set-car! set-cdr! car cdr caar
|
|
|
|
cdar cadr cddr caaar cdaar cadar cddar caadr cdadr caddr
|
|
|
|
cdddr caaaar cdaaar cadaar cddaar caadar cdadar caddar
|
|
|
|
cdddar caaadr cdaadr cadadr cddadr caaddr cdaddr cadddr
|
|
|
|
cddddr)
|
|
|
|
(rename (only (ikarus) cons) (cons sys:cons))
|
|
|
|
(ikarus system $pairs))
|
2007-04-30 00:35:28 -04:00
|
|
|
|
2007-05-05 05:07:49 -04:00
|
|
|
(define cons (lambda (x y) (sys:cons x y)))
|
2007-05-05 05:15:53 -04:00
|
|
|
|
2007-05-05 06:18:29 -04:00
|
|
|
(define weak-cons
|
|
|
|
(lambda (a d)
|
|
|
|
(foreign-call "ikrt_weak_cons" a d)))
|
|
|
|
|
2007-05-05 05:15:53 -04:00
|
|
|
(define set-car!
|
|
|
|
(lambda (x y)
|
|
|
|
(unless (pair? x)
|
|
|
|
(error 'set-car! "~s is not a pair" x))
|
|
|
|
($set-car! x y)))
|
|
|
|
|
|
|
|
(define set-cdr!
|
|
|
|
(lambda (x y)
|
|
|
|
(unless (pair? x)
|
|
|
|
(error 'set-cdr! "~s is not a pair" x))
|
|
|
|
($set-cdr! x y)))
|
|
|
|
|
2007-04-30 00:35:28 -04:00
|
|
|
(define err
|
|
|
|
(lambda (who x)
|
|
|
|
(error who "invalid list structure ~s" x)))
|
2007-05-08 19:19:50 -04:00
|
|
|
|
|
|
|
(define-syntax cxr
|
|
|
|
(syntax-rules ()
|
|
|
|
[(_ err $car/$cdr)
|
|
|
|
(lambda (x)
|
|
|
|
(if (pair? x) ($car/$cdr x) err))]
|
|
|
|
[(_ err rest ... $car/$cdr)
|
|
|
|
(lambda (x)
|
|
|
|
(if (pair? x)
|
|
|
|
((cxr err rest ...) ($car/$cdr x))
|
|
|
|
err))]))
|
|
|
|
|
|
|
|
(define-syntax define-cxr*
|
|
|
|
(syntax-rules ()
|
|
|
|
[(_ [name* ops** ...] ...)
|
|
|
|
(begin
|
|
|
|
(define name*
|
|
|
|
(lambda (x) ((cxr (err 'name* x) ops** ...) x)))
|
|
|
|
...)]))
|
|
|
|
|
|
|
|
(define-cxr*
|
|
|
|
[car $car]
|
|
|
|
[cdr $cdr]
|
|
|
|
[caar $car $car]
|
|
|
|
[cdar $cdr $car]
|
|
|
|
[cadr $car $cdr]
|
|
|
|
[cddr $cdr $cdr]
|
|
|
|
[caaar $car $car $car]
|
|
|
|
[cdaar $cdr $car $car]
|
|
|
|
[cadar $car $cdr $car]
|
|
|
|
[cddar $cdr $cdr $car]
|
|
|
|
[caadr $car $car $cdr]
|
|
|
|
[cdadr $cdr $car $cdr]
|
|
|
|
[caddr $car $cdr $cdr]
|
|
|
|
[cdddr $cdr $cdr $cdr]
|
|
|
|
[caaaar $car $car $car $car]
|
|
|
|
[cdaaar $cdr $car $car $car]
|
|
|
|
[cadaar $car $cdr $car $car]
|
|
|
|
[cddaar $cdr $cdr $car $car]
|
|
|
|
[caadar $car $car $cdr $car]
|
|
|
|
[cdadar $cdr $car $cdr $car]
|
|
|
|
[caddar $car $cdr $cdr $car]
|
|
|
|
[cdddar $cdr $cdr $cdr $car]
|
|
|
|
[caaadr $car $car $car $cdr]
|
|
|
|
[cdaadr $cdr $car $car $cdr]
|
|
|
|
[cadadr $car $cdr $car $cdr]
|
|
|
|
[cddadr $cdr $cdr $car $cdr]
|
|
|
|
[caaddr $car $car $cdr $cdr]
|
|
|
|
[cdaddr $cdr $car $cdr $cdr]
|
|
|
|
[cadddr $car $cdr $cdr $cdr]
|
|
|
|
[cddddr $cdr $cdr $cdr $cdr]))
|