Refactoring
This commit is contained in:
parent
fd1d3682f3
commit
a457194e11
|
@ -10,7 +10,8 @@
|
||||||
"timing.rkt")
|
"timing.rkt")
|
||||||
|
|
||||||
(#%provide ambeval
|
(#%provide ambeval
|
||||||
driver-loop)
|
amb-driver-loop
|
||||||
|
amb-eval-program)
|
||||||
|
|
||||||
(define (amb? exp) (tagged-list? exp 'amb))
|
(define (amb? exp) (tagged-list? exp 'amb))
|
||||||
(define (amb-choices exp) (cdr exp))
|
(define (amb-choices exp) (cdr exp))
|
||||||
|
@ -192,20 +193,11 @@
|
||||||
(define input-prompt ";;; Amb-Eval input:")
|
(define input-prompt ";;; Amb-Eval input:")
|
||||||
(define output-prompt ";;; Amb-Eval value:")
|
(define output-prompt ";;; Amb-Eval value:")
|
||||||
|
|
||||||
(define (driver-loop)
|
(define (amb-driver-loop)
|
||||||
(define env (setup-environment))
|
(define env (setup-environment))
|
||||||
;; Need to pass success and failure continuations to ambeval, so
|
;; Need to pass success and failure continuations to ambeval, so
|
||||||
;; will probably need a different eval-program.
|
;; will probably need a different eval-program.
|
||||||
(eval-program amb-utilities-program
|
(amb-eval-program-in-env amb-utilities-program env)
|
||||||
(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)
|
(define (internal-loop try-again)
|
||||||
(prompt-for-input input-prompt)
|
(prompt-for-input input-prompt)
|
||||||
(let ((input (read)))
|
(let ((input (read)))
|
||||||
|
@ -226,12 +218,12 @@
|
||||||
(announce-output
|
(announce-output
|
||||||
";;; There are no more values of")
|
";;; There are no more values of")
|
||||||
(user-print input)
|
(user-print input)
|
||||||
(driver-loop)))))))
|
(amb-driver-loop)))))))
|
||||||
(internal-loop
|
(internal-loop
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(newline)
|
(newline)
|
||||||
(display ";;; There is no current problem")
|
(display ";;; There is no current problem")
|
||||||
(driver-loop))))
|
(amb-driver-loop))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -252,7 +244,21 @@
|
||||||
(make-combination (make-lambda (map let-var bindings)
|
(make-combination (make-lambda (map let-var bindings)
|
||||||
(let-body exp))
|
(let-body exp))
|
||||||
(map let-val bindings))))
|
(map let-val bindings))))
|
||||||
|
|
||||||
|
(define (amb-eval-program-in-env program env)
|
||||||
|
(eval-program program
|
||||||
|
(lambda (exp env)
|
||||||
|
(ambeval exp
|
||||||
|
env
|
||||||
|
(lambda (value fail) value)
|
||||||
|
(lambda () 'failed)))
|
||||||
|
user-print
|
||||||
|
env))
|
||||||
|
|
||||||
|
(define (amb-eval-program program)
|
||||||
|
(define env (setup-environment))
|
||||||
|
(amb-eval-program-in-env amb-utilities-program env)
|
||||||
|
(amb-eval-program-in-env program env))
|
||||||
|
|
||||||
|
|
||||||
'AMB-EVALUATOR-LOADED
|
'AMB-EVALUATOR-LOADED
|
||||||
|
|
Loading…
Reference in New Issue