lisp

solutions to Lisp in Small Pieces
Log | Files | Refs | Feed

commit 2ee26add32d22f2ca72eda8565b25f34d4b91b0f
parent a7623c44c105759897ad4b9f2e76734d5b31376e
Author: Jenny Doe <tng@soykaf.me>
Date:   Tue,  8 Jan 2019 14:10:04 +0100

Solved 1-5 through 1-8

Diffstat:
Mchapter1/sample-global-environment.scm | 44++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+), 0 deletions(-)

diff --git a/chapter1/sample-global-environment.scm b/chapter1/sample-global-environment.scm @@ -8,3 +8,47 @@ (definitial t #t) (definitial f the-false-value) (definitial nil '()) + +; Exercise 1-5 + +(defprimitive > + (lambda (x y) + (or (> x y) the-false-value)) + 2) + +(defprimitive = + (lambda (x y) + (or (= x y) the-false-value)) + 2) + +; Exercise 1-6 + +;; we're using definitial so we don't have +;; to set the arity + +(definitial list + (lambda (values) values)) + +; Exercise 1-7 + +(defprimitive call/cc + (lambda (p) + (call-with-current-continuation + (lambda (k) + (invoke p (list (lambda (values) + (if (null? values) + (error 'call/cc + "Provided 0 values when I needed 1" + values) + (if (null? (cdr values)) + (k (car values)) + (error 'call/cc + "Too much values when I nedded 1" + values))))))))) + 1) + +; Exercise 1-8 + +(definitial apply + (lambda (values) + (invoke (car values) (cdr values))))