example_parse_calc

example_parse_calc - [(list? sexp) (case (first sexp) [ (+)...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
#lang planet plai/plai ; define-type works like structure ; saying that (define-type AE ;defineing a type AE comes with three variation num add sub [num (n number?)] [add (lhs AE?) ;left hand side (rhs AE?)] [sub (lhs AE?) (rhs AE?)]) ;; parse : sexp -! AE ;; to convert s-expressions into AEs (define (parse sexp) (cond [(number? sexp) (num sexp)]
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: [(list? sexp) (case (first sexp) [ (+) (add (parse (second sexp)) (parse (third sexp)))] [ (-) (sub (parse (second sexp)) (parse (third sexp)))])])) (define (calc an-ae) (type-case AE an-ae [num (n) n] [add (l r) (+ (calc l) (calc r))] [sub (l r) (- (calc l) (calc r))]))...
View Full Document

This document was uploaded on 02/12/2010.

Ask a homework question - tutors are online