Advertisement
Guest User

working

a guest
Aug 21st, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. (defun make-exp (x op y)
  2. (funcall op x y))
  3.  
  4. (defun eek (exp)
  5. (cond ((null (second exp)) exp)
  6. ((and (listp (first exp)) (listp (third exp)))
  7. (make-exp (eek (first exp)) (second exp) (eek (third exp))))
  8. ((listp (first exp)) (make-exp (eek (first exp)) (second exp) (third exp)))
  9. ((listp (third exp)) (make-exp (first exp) (second exp) (eek (third exp))))
  10. (t (make-exp (first exp) (second exp) (third exp)))))
  11.  
  12. (defun listify (exp)
  13. (if (endp (cdr exp))
  14. (car exp)
  15. (list (car exp) (cadr exp) (listify (cddr exp)))))
  16.  
  17. (defun listify-2 (exp)
  18. (cond ((endp (cdr exp)) (car exp))
  19. ((listp (car exp)) (list (listify-2 (car exp)) (cadr exp) (listify-2 (cddr exp))))
  20. (t (list (car exp) (cadr exp) (listify-2 (cddr exp))))))
  21.  
  22. (defun naive-infix (exp)
  23. (let ((listified (listify-2 exp)))
  24. (print listified)
  25. (eek listified)))
  26.  
  27. (naive-infix '(1 + (2 * (12 / 3) + 6) - 4))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement