3 ms·
I'm partial to this snippet from SICP (4.2.3 Streams as Lazy Lists): (define (cons x y) (lambda (m) (m x y))) (define (car z) (z (lambda (p q) p)))
by amake 4y ago
I'm partial to this snippet from SICP (4.2.3 Streams as Lazy Lists):
(define (cons x y) (lambda (m) (m x y)))
(define (car z) (z (lambda (p q) p)))
(define (cdr z) (z (lambda (p q) q)))
This implements cons-style linked lists in terms of only functions. In other words lists need not be the fundamental construct of a Lisp/Scheme—you can use functions instead.