Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. # ______ ______ __ __
  2. # /\ __ \ /\ ___\ /\ \_\ \
  3. # \ \ __ \\ \___ \\ \ __ \
  4. # \ \_\ \_\\/\_____\\ \_\ \_\
  5. # \/_/\/_/ \/_____/ \/_/\/_/
  6.  
  7.  
  8. # ─────────────────────────────────────────
  9. # Literal Values
  10. # ─────────────────────────────────────────
  11.  
  12. # Numbers
  13.  
  14. 1
  15. 2.71828
  16.  
  17. # Strings
  18.  
  19. "Hello World"
  20. "Ready\nSet\nGo"
  21.  
  22. # Bools
  23.  
  24. true
  25. false
  26.  
  27. # ─────────────────────────────────────────
  28. # Lists
  29. # ─────────────────────────────────────────
  30.  
  31. # Creating Lists
  32.  
  33. (list 1 2 3)
  34. (list 42 "Corge" true)
  35. (list 9 (list 10 11 12) 13)
  36.  
  37. # Count
  38.  
  39. (count (list 1 2 3))
  40.  
  41. # Map
  42.  
  43. (let add-one
  44. (lambda (x) (+ x 1)))
  45.  
  46. (map add-one (list 1 2 3))
  47.  
  48. # First
  49.  
  50. (first (list 9 8 7))
  51.  
  52. # Last
  53.  
  54. (last (list 9 8 7))
  55.  
  56. # ─────────────────────────────────────────
  57. # Comparison and Equality Operations
  58. # ─────────────────────────────────────────
  59.  
  60. (> 10 5)
  61. (< 5 10)
  62. (= 1 1)
  63.  
  64. # ─────────────────────────────────────────
  65. # Arithmetic Operations
  66. # ─────────────────────────────────────────
  67.  
  68. (+ 1.1 1.1)
  69. (- 3 2)
  70. (* 4 5)
  71. (/ 10 2)
  72. (% 2 3)
  73.  
  74. # ─────────────────────────────────────────
  75. # Let
  76. # ─────────────────────────────────────────
  77.  
  78. (let a 1)
  79. (let b "Hello World")
  80. (let c true)
  81.  
  82. # ─────────────────────────────────────────
  83. # Functions
  84. # ─────────────────────────────────────────
  85.  
  86. (lambda (x) (x))
  87.  
  88. (λ (x)
  89. (let a 1)
  90. (let b 2)
  91. (+ x (+ a b)))
  92.  
  93. (let square (lambda (x) (* x x)))
  94.  
  95. # ─────────────────────────────────────────
  96. # Conditionals
  97. # ─────────────────────────────────────────
  98.  
  99. (if (> 1 2) "A" "B")
  100. (if (= a 1) "X" true)
  101.  
  102. # ─────────────────────────────────────────
  103. # Console I/O
  104. # ─────────────────────────────────────────
  105.  
  106. # Input
  107.  
  108. (let name
  109. (input "What is your name?"))
  110.  
  111. # Print
  112.  
  113. (print "Hi " name "!")
  114.  
  115. (print
  116. "West of House\n"
  117. "This is an open field west of a white house, with a boarded front "
  118. "door.\n"
  119. "There is a small mailbox here.\n"
  120. "A rubber mat saying 'Welcome to Zork!' lies by the door.")
  121.  
  122. (print (list 1 2 3))
  123. (print true)
  124. (print (lambda (x) (x)))
  125.  
  126. # ─────────────────────────────────────────
  127. # Random Numbers
  128. # ─────────────────────────────────────────
  129.  
  130. # Generate a random number between 0 and 1
  131.  
  132. (let x (random))
  133.  
  134. # ─────────────────────────────────────────
  135. # Working With Strings
  136. # ─────────────────────────────────────────
  137.  
  138. (print (string-replace "The quick brown fox" "brown" "red"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement