Skip to content

Instantly share code, notes, and snippets.

@jbclements
Created May 4, 2020 15:53
Show Gist options
  • Save jbclements/b25849cee37da026296ff04a3a84e2b2 to your computer and use it in GitHub Desktop.
Save jbclements/b25849cee37da026296ff04a3a84e2b2 to your computer and use it in GitHub Desktop.
#lang racket
;; this module defines the sim-AQSE3 language, which
;; simulates AQSE3, by providing
;; only a few key forms from Racket. Specifically: lambda,
;; function calls, if, constants, and a few arithmetic
;; operators.
(module sim-AQSE3 racket
(provide
(rename-out [lambda lam]
[1-form-module-begin #%module-begin])
#%top
#%datum
#%app
+ - * / = <=
if)
(define-syntax-rule (1-form-module-begin e)
(#%module-begin e)))
;; exercise 0: Give the name `f` to the function that
;; accepts an argument `x` and computes x^2 + 4x + 4.
;; apply `f` to seven.
;; exercise 1: Use the trick discussed in class to define
;; a `fact` function that computes the factorial of a given
;; number. Use it to compute the factorial of 12.
;; exercise 2: Define a 'pow' function that accepts a base
;; and a (natural number) exponent, and computes the base to
;; the power of the exponent. Don't worry about non-natural
;; number exponents (6^1.5, 5^-4).
;; exercise 3: use `fact` and `pow` to build a "sin" function
;; that accepts a number x and a number of terms `n`, and computes
;; (sin x) using `n` terms of the taylor expansion. (Note that
;; this is a little ambigious; do zero-coefficient terms count?
;; You can go either way on this.) Use this function to compute
;; the sine of 1 radian to an error of no more than ten to the minus
;; 30th.
(module my-mod (submod ".." sim-AQSE3)
;; WRITE YOUR PROGRAM IN HERE
1234
)
(require 'my-mod)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment