When clicking on Simulation
Eval Window the read-eval-print-loop sends the commands defined above, one after the other, to the evaluator. Eventually coming up with the line we will focus on: (defconstraint (V = pi * (sqr 15) * h)).
The base of our evaluator (myeval.scm) consists of a conditional function trying to determine what kind of element we are asking to interpret. Here is an extract of it:
(define (my-eval exp env)
(cond ((self-evaluating? exp) exp)
((variable? exp) (lookup-variable-value exp env))
((quoted? exp) (text-of-quotation exp))
((assignment? exp) (eval-assignment exp env))
((definition? exp) (eval-definition exp env))
((if? exp) (eval-if exp env))
((lambda? exp)
(make-procedure (lambda-parameters exp)
(lambda-body exp)
env))
((begin? exp)
(eval-sequence (begin-actions exp) env))
((cond? exp) (my-eval (cond->if exp) env))
;added-scheme-functions
((let? exp) (eval-let exp env))
((let*? exp) (eval-let* exp env))
((and? exp) (eval-and exp env))
((or? exp) (eval-or exp env))
;added arinet functions
((defvariable? exp) (eval-defvariable exp env))
((defconstant? exp) (eval-defconstant exp env))
((defconstraint? exp) (eval-defconstraint exp env))
((defmodule? exp) (eval-defmodule exp env))
;end of arinet added functions
((application? exp)
(my-apply (my-eval (operator exp) env)
(list-of-values (operands exp) env)))
(else
(error "Unknown expression type -- EVAL" exp))))
As the car of our operation is defconstraint the line ((defconstraint? exp) (eval-defconstraint exp env)) is selected.
This drives us to the following code:
(define (defconstraint-constraint exp) (cdr exp)) (define (eval-defconstraint exp env) (prefix->arinet (infix->prefix (defconstraint-constraint exp)) env) "DONE -- defconstraint")
which first passes our equation to the infix_to_prefix function (infix_to_prefix.scm). The aim of this function is simply to transform the infix expression (V = pi * (sqr 15) * h) into an prefix function.22 The result is sent to the prefix_to_AriNET function. (prefix_to_arinet.scm):
(prefix_to_arinet '(= v (* (* pi (sqr 15)) h)) env)