8.10.900
#lang racket ;; this code defines the sim-PAIG5 language as a module (module sim-PAIG5 racket (provide [rename-out (#%lam-app #%app) (my-with with) ] #%module-begin #%datum + - * / = equal? <= => true false) (define-syntax (#%lam-app stx) (syntax-case stx (? else: blam) [(_ blam (args ...) body) #'(lambda (args ...) body)] [(_ e1 ? e2 else: e3) #'(if e1 e2 e3)] #;[(_ if e1 : e2 else: e3) #'(if e1 e2 e3)] [(_ e ...) #'(#%app e ...)])) (define-syntax my-with (syntax-rules (as) [(with [e as x] ... : eb) ((lambda (x ...) eb) e ...)])) ) ;; this module uses the sim-PAIG5 language. That is, its ;; contents are written *in* the sim-PAIG5 language. ;; the only edits you should make are inside this module: (module my-mod1 (submod ".." sim-PAIG5) 1234 4567 {+ 4 5} {true ? 34 else: 39} {{blam {x y} {+ x y}} 4 3} ;; exercise 0: write a function that adds one to a number. ;; exercise 1: combining the definition and application forms, ;; apply the function that adds one to a number to the number 17. ;; thought exercise: does running this program "give a name to a value" anywhere? ;; if so, what name and what value? ;; exercise 2: write a function that accepts a function 'h' and applies ;; it to 8. ;; exercise 3: combining the definition and application forms, ;; apply the function that applies its argument to 8 to the function ;; that adds one to a number. ;; thought exercise: does running this program "give a name to a value" ;; anywhere? if so, what name(s) and what value(s)? ;; exercise 4 (a bit harder): write a function that performs function composition: ;; that is, it accepts functions named 'f' and 'g' and returns a new ;; function of one argument that applies first 'g' and then 'f' to its ;; argument ;; exercise 5 (harder): Write a program that gives the name "compose" to ;; the function defined in the previous exercise, gives the name "add1" to ;; the function that adds one, and then gives the name "add2" to the composition ;; of add1 and add1, and finally applies this add2 function to 99. ) ;; this code actually invokes the 'my-mod1 module, so that the ;; code runs. (require 'my-mod1)