in0 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. make "rev_func [
  2. [f]
  3. [
  4. [
  5. [a b]
  6. [f :b :a]
  7. ]
  8. ]
  9. ]
  10. make "rev_sub rev_func [[x y] [sub :x :y]]
  11. print rev_sub 2 5
  12. print rev_sub 26.5 10.3
  13. make "rev_ge rev_func [[x y] [or gt :x :y eq :x :y]]
  14. print rev_ge 3 7
  15. print rev_ge "abc "aBc
  16. print rev_ge 8 8
  17. make "rev_imply rev_func [[x y] [or not :x :y]]
  18. print rev_imply false false
  19. print rev_imply false true
  20. print rev_imply true false
  21. print rev_imply true true
  22. print "abcd12
  23. make "a 16
  24. print :a
  25. make "b "a
  26. print thing :b
  27. make "c mul add :a 13 :a
  28. print sub :c "6
  29. print div 12 5
  30. print mod 12 5
  31. make "d read
  32. 1234dd
  33. make "e print :d
  34. print :e
  35. make "l []
  36. make "q join :l "[
  37. print :q[0]
  38. print eq "] "\]
  39. make "t print [ \[1\]\\\] [1]]
  40. print islist :t[0]
  41. print islist :t[1]
  42. make "x "t
  43. make "y "x
  44. print :::y
  45. make "arr [ [ a b ] c ]
  46. print :arr[0]
  47. print :arr[1]
  48. print :arr[0][0]
  49. print :arr[0][1]
  50. make "arr[0][1] "d
  51. print :arr[0]
  52. print :arr[0][1]
  53. make "arr[1] [ add :a :d ]
  54. print :arr
  55. print arr 2 3
  56. make "arr[0][1] [ e [ f ] ]
  57. make "arr join :arr [ g [ h i ] ]
  58. print :arr[0][1]
  59. print :arr[0][1][0]
  60. print :arr[0][1][1][0]
  61. make "x 1
  62. print :arr[x:]
  63. print word "hello "world
  64. print word "hello true
  65. print word "hello -134.5
  66. print sentence 483 "dba
  67. print sentence sentence [ [ a b ] c ] [ d [ e f ] ] [ g ]
  68. print list 483 "dba
  69. print list list [ [ a b ] c ] [ d [ e f ] ] [ g ]
  70. print join [ 483 ] "dba
  71. print join join [ [ a b ] c ] [ d [ e f ] ] [ g ]
  72. print first "hello
  73. print first butlast list list [ [ a b ] c ] [ d [ e f ] ] [ g ]
  74. make "pow [[a b] [
  75. if lt :b 1 [
  76. return 1
  77. ] [
  78. make "r pow :a div sub :b mod :b 2 2
  79. make "r mul :r :r
  80. if mod :b 2 [
  81. return mul :r :a
  82. ] [
  83. return :r
  84. ]
  85. print :r
  86. ]
  87. ]]
  88. print pow 2 18
  89. print make "ts readlist
  90. [1 ] c 1 \\\\[2 3\\]
  91. print islist :ts[1]
  92. make "reverse_list [
  93. [list]
  94. [if isempty :list [] [join reverse_list butfirst :list first :list]]
  95. ]
  96. print reverse_list []
  97. print reverse_list [x y z]
  98. print reverse_list [12 345 6 78 9 0]
  99. print reverse_list [a b c d [e f] g]
  100. print reverse_list [h [i [j k]] l m n]
  101. make "fib_wrap [
  102. [x]
  103. [
  104. make "fib [
  105. [x]
  106. [
  107. if lt :x 2 [return 1] []
  108. add fib sub :x 1 fib sub :x 2
  109. ]
  110. ]
  111. fib :x
  112. ]
  113. ]
  114. print fib_wrap 0
  115. print fib_wrap 1
  116. print fib_wrap 2
  117. print fib_wrap 3
  118. print fib_wrap 4
  119. print fib_wrap 5
  120. print fib_wrap 6
  121. print fib_wrap 7
  122. print fib_wrap 8
  123. print fib_wrap 20
  124. make "f [[x] [
  125. make "g [[y] [return add :x :y]]
  126. return g 42
  127. ]]
  128. print f 233
  129. make "f1 [[x] [
  130. make "g1 [[y] [return add :x :y]]
  131. return :g1
  132. ]]
  133. make "c1 f1 42
  134. make "c2 f1 24
  135. print c1 1
  136. print c2 2
  137. make "curry_two [[f x] [
  138. return [[y] [return f :x :y]]
  139. ]]
  140. make "f2 [[x y] [
  141. return add :x :y
  142. ]]
  143. make "f3 curry_two :f2 42
  144. print f3 233
  145. make "fun [
  146. [x]
  147. [[[y] [make "x add :x :y]]]
  148. ]
  149. make "adder fun 5
  150. print adder 1
  151. print adder 2
  152. print adder 3
  153. make "prt [
  154. [a]
  155. [
  156. make "b [
  157. []
  158. [print :a]
  159. ]
  160. return :b
  161. ]
  162. ]
  163. make "c prt "hello
  164. c
  165. make "x 2
  166. print :x
  167. make "test [
  168. []
  169. [
  170. make "x 1
  171. export "x
  172. print :x
  173. ]
  174. ]
  175. test
  176. print :x
  177. print poall
  178. make "fun1 [
  179. [x]
  180. [add :x 10]
  181. ]
  182. print fun1 5
  183. make "fun2 [
  184. []
  185. [
  186. print fun1 5
  187. make "fun1 [
  188. [x]
  189. [add :x 100]
  190. ]
  191. print fun1 5
  192. export "fun1
  193. make "fun1 [
  194. [x]
  195. [add :x 1000]
  196. ]
  197. print fun1 5
  198. if eq fun1 5 1005 [return 0] []
  199. make "fun1 [
  200. [x]
  201. [add :x 10000]
  202. ]
  203. export "fun1
  204. print fun1 5
  205. return 1
  206. ]
  207. ]
  208. print fun2
  209. print fun1 5