Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Code Block
;; Given

(define-struct add (mleft nright))
(define-struct sub (mleft nright))
(define-struct mul (mleft nright))
(define-struct div (mleft nright))

;; an Arithmetic-Expression (AExp) is either:
;; - a number ;
;; - (make-add ml nr) where ml,nr are AExps;
;; - (make-sub ml nr) where ml,nr are AExps;
;; - (make-mul ml nr) where ml,nr are AExps; or
;; - (make-div ml nr) where ml,nr are AExps,

Using this data definition, the arithmetic expression above corresponds to the structure ae1 defined by

...

  1. Develop the function eval: AExp -> N where (eval ae) returns the number denoted by the expression ae. For example, (eval ae1) should return -51, and (eval ae2) should return 16.unmigrated-wiki-markup
  2. \[Challenge\] Assume that our expression language includes many basic operations, not just the four supported by {{AExp}}. We would want a single representation for the application of a binary operator to arguments and use a separate data definition enumerating all of our operations. Rewrite the preceding data definitions, examples, and the function {{eval}} using for this. As a further challenge, extend your data definition to accommodate unary operations including negation and absolute value as unary operators.

Files and Directories

The following are data definitions are idealized (for the sake of simplicity) representations of files and directories (folders). These definitions follow the Windows convention of attaching a name to a file. They also collapse the definition of the directory type into a clause in the definition of a file, which makes the set f definitions more compact but obfuscates how to write functions that process directories (instead of files). For this reason, none of the following exercises uses a directory as the primary input to a function.

...