Com S 342 meeting -*- Outline -*- * Conditional Evaluation (5.2) ------------------------------------------ CONDITIONALS (5.2) What should be the concrete syntax for if-expressions in the defined language? ------------------------------------------ ... ::= if then else give examples: if less(2,3) then 5 else 4 Q: What would this be like if we had a distinction between statements and expressions? ------------------------------------------ FOR YOU TO DO IN GROUPS Close your books. 1. What should the abstract syntax be? 2. What type should the test have? 3. Write the part you need to add to the interpreter, and any needed code. 4. Do any primitive procedures need to be built-in to make this useful? Write the necessary changes for them. ------------------------------------------ ... (define-record if (test-exp then-exp else-exp)) ... (variant-case exp (if (test-exp then-exp else-exp) (if (true-value? (expressed->number (eval-exp test-exp))) (eval-exp then-exp) (eval-exp else-exp))) ...) (define true-value? ; TYPE: (-> (number) boolean) (lambda (v) (not (zero? v)))) Be sure to clarify what the actual syntax is that will be used from here on in the defined language. But it isn't necessary to use that. ... need primitives for equal, less, greater Can we have "not" as a primitive?