in1 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. make "f [[x] [
  2. make "g [[y] [return add :x :y]]
  3. return g 42
  4. ]]
  5. print f 233
  6. make "f1 [[x] [
  7. make "g1 [[y] [return add :x :y]]
  8. return :g1
  9. ]
  10. ]
  11. make "c1 f1 42
  12. make "c2 f1 24
  13. print c1 1
  14. print c2 2
  15. make "curry_two [[f x] [
  16. return [[y] [return f :x :y]]
  17. ]]
  18. make "f2 [[x y] [
  19. return add :x :y
  20. ]]
  21. make "f2p curry_two :f2 42
  22. print f2p 233
  23. make "fact_base [
  24. [rec x]
  25. [
  26. if eq :x 0
  27. [return 1]
  28. [return mul :x rec :rec sub :x 1]
  29. ]
  30. ]
  31. make "fact_simple [
  32. [x]
  33. [return fact_base :fact_base :x]
  34. ]
  35. print fact_simple 5
  36. make "fact_nice [
  37. [rec]
  38. [
  39. make "g [
  40. [x]
  41. [
  42. if eq :x 0
  43. [return 1]
  44. [
  45. make "tmp rec :rec
  46. return mul :x tmp sub :x 1
  47. ]
  48. ]
  49. ]
  50. return :g
  51. ]
  52. ]
  53. make "fact_curry fact_nice :fact_nice
  54. print fact_curry 5
  55. make "fact_nicer [
  56. [rec]
  57. [
  58. make "g [
  59. [x]
  60. [
  61. if eq :x 0
  62. [return 1]
  63. [return mul :x rec sub :x 1]
  64. ]
  65. ]
  66. return :g
  67. ]
  68. ]
  69. make "z_comb [
  70. [g]
  71. [
  72. make "t [
  73. [r]
  74. [
  75. make "y [
  76. [yy]
  77. [
  78. make "tmp r :r
  79. return tmp :yy
  80. ]
  81. ]
  82. return g :y
  83. ]
  84. ]
  85. return t :t
  86. ]
  87. ]
  88. make "fact_z z_comb :fact_nicer
  89. print fact_z 5
  90. make "logic_test [[b] [return b 1 0]]
  91. make "F_TRUE [[x y] [return :x]]
  92. make "F_FALSE [[x y] [return :y]]
  93. make "F_AND [[p q] [return p :q :p]]
  94. make "F_OR [[p q] [return p :p :q]]
  95. make "F_NOT [[p] [return p :F_FALSE :F_TRUE]]
  96. print logic_test F_AND F_AND :F_TRUE :F_TRUE :F_FALSE
  97. print logic_test F_AND F_OR :F_TRUE :F_FALSE :F_FALSE
  98. print logic_test F_NOT F_AND :F_TRUE :F_FALSE :F_TRUE
  99. print logic_test F_OR F_NOT :F_TRUE F_NOT :F_FALSE :F_TRUE
  100. make "church_test [
  101. [n]
  102. [
  103. make "inc [[x] [return add :x 1]]
  104. return n :inc 0
  105. ]
  106. ]
  107. make "O [
  108. [f x]
  109. [return :x]
  110. ]
  111. make "succ [
  112. [n]
  113. [
  114. make "t [
  115. [f x]
  116. [
  117. make "tt n :f :x
  118. return f :tt
  119. ]
  120. ]
  121. return :t
  122. ]
  123. ]
  124. print church_test succ :O
  125. print church_test succ succ :O
  126. print church_test succ succ succ :O