3 ms·
Looking at file church.scm from the provided zip file [1], I see the following functions used to construct lists: (define kons (lambda (x) (lambda (y
by tromp 1y ago
Looking at file church.scm from the provided zip file [1], I see the following
functions used to construct lists:
(define kons
(lambda (x) (lambda (y) ((pair false) ((pair false) ((pair x) y))))))
(define kar (lambda (x) (first (second (second x)))))
(define kdr (lambda (x) (second (second (second x)))))
(define nil ((pair true) ((pair true) false)))
(define null first)
(define atom (lambda (x) (first (second x))))
That's 2 extra booleans per list element.
While the one for recognizing atoms is probably necessary, the other one for recognizing nil is not:
(define kons
(lambda (x) (lambda (y) ((pair false) ((pair x) y)))))
(define kar (lambda (x) (first (second x))))
(define kdr (lambda (x) (second (second x))))
(define nil ((pair true) false))
(define null (lambda (x) (((second x) (lambda (a) (lambda (d) (lambda (z) false)))) true)))
(define atom (lambda (x) (first x)))
The use of null+car+cdr can usually be avoided by using a matching construct instead like
(((second list) (lambda (a) (lambda (d) (lambda (z) deal_with_car_a_and_cdr_d ) deal_with_nil)
[1] https://t3x.org/lfn/church.zip https://t3x.org/lfn/church.zip
- deleted 1y ago[deleted]
- nils-m-holm 1y agoBut then (ATOM NIL) is neither TRUE nor FALSE.
- tromp 1y agoI forgot to add the atom boolean to the nil representation. I made some changes that hopefully fix that.
- nils-m-holm 1y agoIndeed, thanks!