8.8.0.8
#lang racket ;; this code defines the sim-IKEU5 language as a module (module sim-IKEU5 racket (provide [rename-out (#%lam-app #%app) (my-let let) (my-if if)] #%module-begin #%datum + - * / = equal? <=) (define-syntax (#%lam-app stx) (syntax-case stx (:) [(_ (args ...) : body) #'(lambda (args ...) body)] [(_ e ...) #'(#%app e ...)])) (define-syntax my-if (syntax-rules (then) [(if e1 then e2 else e3) (if e1 e2 e3)])) (define-syntax my-let (syntax-rules () [(let ([v = e] ...) eb) ((lambda (v ...) eb) e ...)])) ) ;; this module uses the sim-IKEU5 language. That is, its ;; contents are written *in* the sim-IKEU5 language. ;; the only edits you should make are inside this module: (module my-mod1 (submod ".." sim-IKEU5) 1234 4567 {+ 4 5} ;; 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)