sicp/mceval/amb-utilities.rkt

36 lines
866 B
Racket

;; Lisp code to be evaluated by amb evaluator to implement utility procedures.
#lang sicp
(#%provide amb-utilities-program)
(define amb-utilities-program
'((define (require p)
(if (not p) (amb)))
(define (an-element-of items)
(require (not (null? items)))
(amb (car items) (an-element-of (cdr items))))
(define (an-integer-starting-from n)
(amb n (an-integer-starting-from (+ n 1))))
(define (distinct? items)
(cond ((null? items) true)
((null? (cdr items)) true)
((member (car items) (cdr items)) false)
(else (distinct? (cdr items)))))
(define (map f l)
(if (null? l) '()
(cons (f (car l))
(map f (cdr l)))))
(define (and-map f l)
(if (null? l) true
(if (f (car l))
true
false)))))