will look at this tomorrow when I'm more clearheaded
This commit is contained in:
parent
2bb72b6c44
commit
6dff02d606
|
@ -12,6 +12,8 @@
|
|||
(require (prefix-in racket: racket/base))
|
||||
|
||||
|
||||
;; Use Racket's compiler, and then parse the resulting bytecode
|
||||
;; to our own AST structures.
|
||||
(define (parse stx)
|
||||
(parameterize ([current-namespace (make-base-namespace)])
|
||||
(let ([bc (racket:compile stx)]
|
||||
|
@ -326,10 +328,17 @@
|
|||
#:control-limit 4)
|
||||
|
||||
|
||||
(test '(pair? '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
#t)
|
||||
|
||||
(test '(eq? (car '(+ (* 3 x x) (* a x x) (* b x) 5))
|
||||
'+)
|
||||
#t)
|
||||
|
||||
|
||||
|
||||
;; deriv
|
||||
(test '(let ()
|
||||
(test '(let ()
|
||||
(define (deriv-aux a) (list '/ (deriv a) a))
|
||||
(define (map f l)
|
||||
(if (null? l)
|
||||
|
@ -342,8 +351,7 @@
|
|||
(if (eq? (car a) '+)
|
||||
(cons '+ (map deriv (cdr a)))
|
||||
(if (eq? (car a) '-)
|
||||
(cons '- (map deriv
|
||||
(cdr a)))
|
||||
(cons '- (map deriv (cdr a)))
|
||||
(if (eq? (car a) '*)
|
||||
(list '*
|
||||
a
|
||||
|
@ -366,6 +374,7 @@
|
|||
(* (* b x) (+ (/ 0 b) (/ 1 x)))
|
||||
0))
|
||||
|
||||
|
||||
;; Foldl
|
||||
(test '(let()
|
||||
(define (foldl f acc lst)
|
||||
|
|
Loading…
Reference in New Issue
Block a user