Implement till 2.83

This commit is contained in:
2020-11-20 22:04:19 -05:00
parent b28c0a1e9f
commit bebccac4c2
2 changed files with 138 additions and 13 deletions

View File

@@ -35,16 +35,21 @@
nil
(cons low (enumerate-interval (+ low 1) high))))
; Put and get functions. We could have implemented this via a list of
; three-tuples, but I don't know how to create global variables yet so we just
; use this code from SO. Doesn't look too complicated.
; https://stackoverflow.com/questions/5499005/how-do-i-get-the-functions-put-and-get-in-sicp-scheme-exercise-2-78-and-on
(define *op-table* (make-hash-table))
(define (put op type proc)
(hash-table/put! *op-table* (list op type) proc))
(define (get op type)
(let ((e (hash-table/get *op-table* (list op type) #f)))
(if (eq? e #f)
(error "Unknown op type -- GET" (list op type))
e)))
; Returns #t if there is no #f in xs, otherwise returns #f.
(define (all? xs)
(cond ((null? xs) #t)
((eq? (car xs) #f) #f)
(else (all? (cdr xs)))))
(define (all-eq? xs)
(cond ((null? xs) #t)
((null? (cdr xs)) #t)
((eq? (car xs) (cadr xs)) (all-eq? (cdr xs)))
(else #f)))
(define (fold-right op initial sequence) ; same as accumulate
(if (null? sequence)
initial
(op (car sequence)
(fold-right op initial (cdr sequence)))))