A fork of Crisp for HARP
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
2.0 KiB

  1. ;; Testing non-macro function
  2. (not (= 1 1))
  3. ;=>false
  4. ;;; This should fail if it is a macro
  5. (not (= 1 2))
  6. ;=>true
  7. ;; Testing trivial macros
  8. (defmacro! one (fn* () 1))
  9. (one)
  10. ;=>1
  11. (defmacro! two (fn* () 2))
  12. (two)
  13. ;=>2
  14. ;; Testing unless macros
  15. (defmacro! unless (fn* (pred a b) `(if ~pred ~b ~a)))
  16. (unless false 7 8)
  17. ;=>7
  18. (unless true 7 8)
  19. ;=>8
  20. (defmacro! unless2 (fn* (pred a b) `(if (not ~pred) ~a ~b)))
  21. (unless2 false 7 8)
  22. ;=>7
  23. (unless2 true 7 8)
  24. ;=>8
  25. ;; Testing macroexpand
  26. (macroexpand (unless2 2 3 4))
  27. ;=>(if (not 2) 3 4)
  28. ;; Testing nth, first and rest functions
  29. (nth '(1) 0)
  30. ;=>1
  31. (nth '(1 2) 1)
  32. ;=>2
  33. (def! x "x")
  34. (def! x (nth '(1 2) 2))
  35. x
  36. ;=>"x"
  37. (first '())
  38. ;=>nil
  39. (first '(6))
  40. ;=>6
  41. (first '(7 8 9))
  42. ;=>7
  43. (rest '())
  44. ;=>()
  45. (rest '(6))
  46. ;=>()
  47. (rest '(7 8 9))
  48. ;=>(8 9)
  49. ;; Testing or macro
  50. (or)
  51. ;=>nil
  52. (or 1)
  53. ;=>1
  54. (or 1 2 3 4)
  55. ;=>1
  56. (or false 2)
  57. ;=>2
  58. (or false nil 3)
  59. ;=>3
  60. (or false nil false false nil 4)
  61. ;=>4
  62. (or false nil 3 false nil 4)
  63. ;=>3
  64. (or (or false 4))
  65. ;=>4
  66. ;; Testing cond macro
  67. (cond)
  68. ;=>nil
  69. (cond true 7)
  70. ;=>7
  71. (cond true 7 true 8)
  72. ;=>7
  73. (cond false 7 true 8)
  74. ;=>8
  75. (cond false 7 false 8 "else" 9)
  76. ;=>9
  77. (cond false 7 (= 2 2) 8 "else" 9)
  78. ;=>8
  79. (cond false 7 false 8 false 9)
  80. ;=>nil
  81. ;;
  82. ;; Loading core.mal
  83. (load-file "../core.mal")
  84. ;; Testing and macro
  85. (and)
  86. ;=>true
  87. (and 1)
  88. ;=>1
  89. (and 1 2)
  90. ;=>2
  91. (and 1 2 3)
  92. ;=>3
  93. (and 1 2 3 4)
  94. ;=>4
  95. (and 1 2 3 4 false)
  96. ;=>false
  97. (and 1 2 3 4 false 5)
  98. ;=>false
  99. ;; Testing -> macro
  100. (-> 7)
  101. ;=>7
  102. (-> (list 7 8 9) first)
  103. ;=>7
  104. (-> (list 7 8 9) (first))
  105. ;=>7
  106. (-> (list 7 8 9) first (+ 7))
  107. ;=>14
  108. (-> (list 7 8 9) rest (rest) first (+ 7))
  109. ;=>16
  110. ;; Testing EVAL in let*
  111. (let* (x (or nil "yes")) x)
  112. ;=>"yes"
  113. ;;
  114. ;; -------- Optional Functionality --------
  115. ;; Testing nth, first, rest with vectors
  116. (nth [1] 0)
  117. ;=>1
  118. (nth [1 2] 1)
  119. ;=>2
  120. (def! x "x")
  121. (def! x (nth [1 2] 2))
  122. x
  123. ;=>"x"
  124. (first [])
  125. ;=>nil
  126. (first [10])
  127. ;=>10
  128. (first [10 11 12])
  129. ;=>10
  130. (rest [])
  131. ;=>()
  132. (rest [10])
  133. ;=>()
  134. (rest [10 11 12])
  135. ;=>(11 12)
  136. ;; Testing EVAL in vector let*
  137. (let* [x (or nil "yes")] x)
  138. ;=>"yes"