Difference between revisions of "MUPL Assignment"
Jump to navigation
Jump to search
Line 11: | Line 11: | ||
[https://www.coursera.org/learn/programming-languages-part-b/supplement/MfhBE/notes-and-tips-for-section-6 Notes and Tips] | [https://www.coursera.org/learn/programming-languages-part-b/supplement/MfhBE/notes-and-tips-for-section-6 Notes and Tips] | ||
+ | |||
+ | =Set-up= | ||
+ | For this assignment, edit a copy of hw5.rkt. In particular, replace | ||
+ | occurrences of "CHANGE" to complete the problems. Do not use any mutation (set!, set-mcar!, etc.) | ||
+ | anywhere in the assignment. | ||
+ | |||
+ | =Overview= | ||
+ | This homework has to do with mupl (a Made Up Programming Language). mupl programs | ||
+ | are written directly in Racket by using the constructors defined by the structs defined at the beginning of | ||
+ | hw5.rkt. This is the definition of mupl’s syntax: | ||
+ | |||
+ | * If s is a Racket string, then (var s) is a mupl expression (a variable use). | ||
+ | * If n is a Racket integer, then (int n) is a mupl expression (a constant). | ||
+ | * If e1 and e2 are mupl expressions, then (add e1 e2) is a mupl expression (an addition). | ||
+ | * If s1 and s2 are Racket strings and e is a mupl expression, then (fun s1 s2 e) is a mupl expression (a function). In e, s1 is bound to the function itself (for recursion) and s2 is bound to the (one) argument. Also, (fun #f s2 e) is allowed for anonymous nonrecursive functions. | ||
+ | * If e1, e2, and e3, and e4 are mupl expressions, then (ifgreater e1 e2 e3 e4) is a mupl expression. It is a conditional where the result is e3 if e1 is strictly greater than e2 else the result is e4. Only one of e3 and e4 is evaluated. | ||
+ | * If e1 and e2 are mupl expressions, then (call e1 e2) is a mupl expression (a function call). | ||
+ | * If s is a Racket string and e1 and e2 are mupl expressions, then (mlet s e1 e2) is a mupl expression (a let expression where the value resulting e1 is bound to s in the evaluation of e2). | ||
+ | * If e1 and e2 are mupl expressions, then (apair e1 e2) is a mupl expression (a pair-creator). | ||
+ | * If e1 is a mupl expression, then (fst e1) is a mupl expression (getting the first part of a pair). | ||
+ | * If e1 is a mupl expression, then (snd e1) is a mupl expression (getting the second part of a pair). | ||
+ | * (aunit) is a mupl expression (holding no data, much like () in ML or null in Racket). Notice (aunit) is a mupl expression, but aunit is not. | ||
+ | * If e1 is a mupl expression, then (isaunit e1) is a mupl expression (testing for (aunit)). | ||
+ | * (closure env f) is a mupl value where f is mupl function (an expression made from fun) and env is an environment mapping variables to values. Closures do not appear in source programs; they result from evaluating functions. |
Revision as of 06:21, 5 November 2020
Road To Victory
- UW MUPL Assignment Part 1 Warm Up
- UW MUPL Assignment Part 2 Implementing the MUPL Language
- UW MUPL Assignment Part 3 Expanding the Language
- MUPL Programs Studio
- UW MUPL Assignment Part 4 Using The Language mupl-map, mupl-mapAddN
- UW MUPL Assignment Part 5 Challenge Problem
Set-up
For this assignment, edit a copy of hw5.rkt. In particular, replace occurrences of "CHANGE" to complete the problems. Do not use any mutation (set!, set-mcar!, etc.) anywhere in the assignment.
Overview
This homework has to do with mupl (a Made Up Programming Language). mupl programs are written directly in Racket by using the constructors defined by the structs defined at the beginning of hw5.rkt. This is the definition of mupl’s syntax:
- If s is a Racket string, then (var s) is a mupl expression (a variable use).
- If n is a Racket integer, then (int n) is a mupl expression (a constant).
- If e1 and e2 are mupl expressions, then (add e1 e2) is a mupl expression (an addition).
- If s1 and s2 are Racket strings and e is a mupl expression, then (fun s1 s2 e) is a mupl expression (a function). In e, s1 is bound to the function itself (for recursion) and s2 is bound to the (one) argument. Also, (fun #f s2 e) is allowed for anonymous nonrecursive functions.
- If e1, e2, and e3, and e4 are mupl expressions, then (ifgreater e1 e2 e3 e4) is a mupl expression. It is a conditional where the result is e3 if e1 is strictly greater than e2 else the result is e4. Only one of e3 and e4 is evaluated.
- If e1 and e2 are mupl expressions, then (call e1 e2) is a mupl expression (a function call).
- If s is a Racket string and e1 and e2 are mupl expressions, then (mlet s e1 e2) is a mupl expression (a let expression where the value resulting e1 is bound to s in the evaluation of e2).
- If e1 and e2 are mupl expressions, then (apair e1 e2) is a mupl expression (a pair-creator).
- If e1 is a mupl expression, then (fst e1) is a mupl expression (getting the first part of a pair).
- If e1 is a mupl expression, then (snd e1) is a mupl expression (getting the second part of a pair).
- (aunit) is a mupl expression (holding no data, much like () in ML or null in Racket). Notice (aunit) is a mupl expression, but aunit is not.
- If e1 is a mupl expression, then (isaunit e1) is a mupl expression (testing for (aunit)).
- (closure env f) is a mupl value where f is mupl function (an expression made from fun) and env is an environment mapping variables to values. Closures do not appear in source programs; they result from evaluating functions.