Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 1.14 KB | None | 0 0
  1. (define (check-arith)
  2.   (let ((test1 2)
  3.         (test2 '(cons '+
  4.                   (cons 2 (cons 3 null))))
  5.         (test3 '(cons '+
  6.                   (cons (cons '- (cons 2 (cons 3 null)))
  7.                     (cons (cons '* (cons 2 (cons 3 null)))
  8.                       null))))
  9.         (test4 '(cons '^
  10.                       (cons 2 (cons 3 null))))
  11.         (test5 '(cons '/
  12.                       (cons (cons '+
  13.                             (cons (cons '- (cons 2 (cons 3 null)))
  14.                                   (cons (cons '* (cons 2 (cons 3 null)))
  15.                                         null)))
  16.                             (cons (cons '+
  17.                                   (cons (cons '- (cons 3 (cons 1 null)))
  18.                                         (cons (cons '* (cons 2 (cons 2 null)))
  19.                                               null))) null)))))
  20.     (list (eval (arith-eval test1))      ;; 2
  21.           (eval (arith-eval test2))      ;; 5
  22.           (eval (arith-eval test3))      ;; 5
  23.           (eval (arith-eval test4))      ;; error:bad-operator
  24.           (eval (arith-eval test5)))))   ;; 5/6
  25.              
  26. (check-arith)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement