fork download
  1. ; Starting writing your own arithmetic DSL in Lisp
  2. ; ------------------------------
  3. ; The Little Lisper 3rd Edition
  4. ; Chapter 7
  5. ; Exercise 1
  6. ; Common Lisp
  7. ; http://t...content-available-to-author-only...r.com/thelittlelisper
  8. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper-chapter-7-shadows.html
  9. ; http://t...content-available-to-author-only...t.com/2010/06/little-lisper.html
  10. ; ------------------------------
  11. (setf l1 '())
  12. (setf l2 '(3 + (66 6)))
  13. (setf aexp4 5)
  14. ; ------------------------------
  15. (defun mk\+exp (aexp1_ aexp2_)
  16. (cons aexp1_
  17. (cons '+
  18. (cons aexp2_ '()))))
  19.  
  20. (print (mk\+exp 1 2))
  21. ;(1 + 2)
  22.  
  23. (defun mk\*exp (aexp1_ aexp2_)
  24. (cons aexp1_
  25. (cons '*
  26. (cons aexp2_ '()))))
  27.  
  28. (print (mk\*exp 1 2))
  29. ;(1 * 2)
  30.  
  31. (defun mk\^exp (aexp1_ aexp2_)
  32. (cons aexp1_
  33. (cons '^
  34. (cons aexp2_ '()))))
  35.  
  36. (print (mk\^exp 1 2))
  37. ;(1 ^ 2)
  38.  
  39. (setf aexp1 (mk\+exp 1 (mk\*exp 3 4)))
  40. (setf aexp2 (mk\+exp (mk\^exp 3 4) 5))
  41. (setf aexp3 (mk\*exp 3 (mk\*exp 4 (mk\*exp 5 6))))
  42.  
Success #stdin #stdout 0.02s 10544KB
stdin
Standard input is empty
stdout
(1 + 2) 
(1 * 2) 
(1 ^ 2)