Add amb utilities that are loaded at startup
This commit is contained in:
parent
f769d990ec
commit
34400a1bc4
|
@ -0,0 +1,18 @@
|
|||
;; 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))))))
|
||||
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
#lang sicp
|
||||
|
||||
(#%require "syntax.rkt"
|
||||
(#%require "amb-utilities.rkt"
|
||||
"syntax.rkt"
|
||||
"environment.rkt"
|
||||
"common.rkt"
|
||||
"special-forms.rkt")
|
||||
|
@ -192,6 +193,18 @@
|
|||
|
||||
(define (driver-loop)
|
||||
(define env (setup-environment))
|
||||
;; Need to pass success and failure continuations to ambeval, so
|
||||
;; will probably need a different eval-program.
|
||||
(eval-program amb-utilities-program
|
||||
(lambda (exp env) ; Evaluate exp using ambeval
|
||||
; passing in appropriate
|
||||
; continuations
|
||||
(ambeval exp
|
||||
env
|
||||
(lambda (value fail) value)
|
||||
(lambda () 'failed)))
|
||||
user-print
|
||||
env)
|
||||
(define (internal-loop try-again)
|
||||
(prompt-for-input input-prompt)
|
||||
(let ((input (read)))
|
||||
|
|
Loading…
Reference in New Issue