; Starting writing your own arithmetic DSL in Lisp
; ------------------------------
; The Little Lisper 3rd Edition
; Chapter 7
; Exercise 1
; Common Lisp
; http://t...content-available-to-author-only...r.com/thelittlelisper
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper-chapter-7-shadows.html
; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
; ------------------------------
(setf l1 '())
(setf l2 '(3 + (66 6)))
(setf aexp4 5)
; ------------------------------
(defun mk\+exp (aexp1_ aexp2_)
(cons aexp1_
(cons '+
(cons aexp2_ '()))))
(print (mk\+exp 1 2))
;(1 + 2)
(defun mk\*exp (aexp1_ aexp2_)
(cons aexp1_
(cons '*
(cons aexp2_ '()))))
(print (mk\*exp 1 2))
;(1 * 2)
(defun mk\^exp (aexp1_ aexp2_)
(cons aexp1_
(cons '^
(cons aexp2_ '()))))
(print (mk\^exp 1 2))
;(1 ^ 2)
(setf aexp1 (mk\+exp 1 (mk\*exp 3 4)))
(setf aexp2 (mk\+exp (mk\^exp 3 4) 5))
(setf aexp3 (mk\*exp 3 (mk\*exp 4 (mk\*exp 5 6))))
OyBTdGFydGluZyB3cml0aW5nIHlvdXIgb3duIGFyaXRobWV0aWMgRFNMIGluIExpc3AKOyAtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KOyBUaGUgTGl0dGxlIExpc3BlciAzcmQgRWRpdGlvbgo7IENoYXB0ZXIgNwo7IEV4ZXJjaXNlIDEKOyBDb21tb24gTGlzcAo7IGh0dHA6Ly90Li4uY29udGVudC1hdmFpbGFibGUtdG8tYXV0aG9yLW9ubHkuLi5yLmNvbS90aGVsaXR0bGVsaXNwZXIKOyBodHRwOi8vdC4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4udC5jb20vMjAxMC8wNi9saXR0bGUtbGlzcGVyLWNoYXB0ZXItNy1zaGFkb3dzLmh0bWwKOyBodHRwOi8vdC4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci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