git @ Cat's Eye Technologies Argyle / master eg / cons-list-attempt.argyle
master

Tree @master (Download .tar.gz)

cons-list-attempt.argyle @masterraw · history · blame

;
; An initial, but misguided, attempt to implement cons lists in ABTs
; using ABT application nodes.
;
(let ((cons
        (lambda (x y)
          (quote (x y))))
      (car
        (lambda (lst)
          (destruct-abt lst
            (lambda (name) (neg 1))
            (lambda (val) (neg 2))
            (lambda (param body) (neg 3))
            (lambda (name expr body)
                (destruct-abt lst
                    (lambda (name) (neg 11))
                    (lambda (val) (neg 12))
                    (lambda (param body) (neg 13))
                    (lambda (name expr body)
                        (destruct-abt lst
                            (lambda (name) (neg 21))
                            (lambda (val) (neg 22))
                            (lambda (param body) (neg 23))
                            (lambda (name expr body) body)  ; Intruiging and somewhat disappointing,
                                                            ; but even moreso intruiging.  This is an
                                                            ; infinite regress, because every time we
                                                            ; extract these bound variables, we bring
                                                            ; binders with us!
                            (lambda (fn arg) (neg 25))
                            (lambda (name arg) (neg 26))))
                    (lambda (fn arg) (neg 15))
                    (lambda (name arg) (neg 16))))
            (lambda (fn arg) (neg 5))
            (lambda (name arg) (neg 6)))))
      (cdr
        (lambda (lst)
          (destruct-abt lst
            (lambda (name) (neg 1))
            (lambda (val) (neg 1))
            (lambda (param body) (neg 1))
            (lambda (name expr body)
                (destruct-abt lst
                    (lambda (name) (neg 2))
                    (lambda (val) (neg 2))
                    (lambda (param body) (neg 2))
                    (lambda (name expr body)
                        (destruct-abt lst
                            (lambda (name) (neg 3))
                            (lambda (val) (neg 3))
                            (lambda (param body) (neg 3))
                            (lambda (name expr body) (neg 3))
                            (lambda (fn arg) arg)               ; doesn't do what we want, see above!
                            (lambda (name arg) (neg 3))))
                    (lambda (fn arg) (neg 2))
                    (lambda (name arg) (neg 2))))
            (lambda (fn arg) (neg 2))
            (lambda (name arg) (neg 1)))))
      (lst (cons 1 (cons 2 (cons 3 0)))))
        (car lst))