Skip to content

Instantly share code, notes, and snippets.

@kkestell
Last active July 30, 2019 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkestell/bb06b147c27a21eb131259293d6fb767 to your computer and use it in GitHub Desktop.
Save kkestell/bb06b147c27a21eb131259293d6fb767 to your computer and use it in GitHub Desktop.

Ash

Literal Values

Numbers

1
2.71828

Strings

"Hello World"
"Ready\nSet\nGo"

Bools

true
false

Lists

Creating Lists

(list 1 2 3)
(list 42 "Corge" true)
(list 9 (list 10 11 12) 13)

Count

(count (list 1 2 3))

Map

(let add-one 
    (lambda (x) (+ x 1)))

(map add-one (list 1 2 3))

First

(first (list 9 8 7))

Last

(last (list 9 8 7))

Range

(range 10)

Comparison and Equality Operations

(> 10 5)
(< 5 10)
(= 1 1)

Arithmetic Operations

(+ 1.1 1.1)
(- 3 2)
(* 4 5)
(/ 10 2)
(% 2 3)

Assignment

(let a 1)
(let b "Hello World")
(let c true)

Functions

(lambda (x) (x))
    
(λ (x)
    (let a 1)
    (let b 2)
    (+ x (+ a b)))

(let square (lambda (x) (* x x)))

Conditionals

(if (> 1 2) "A" "B")
(if (= a 1) "X" true)

Console I/O

Input

(let name 
    (input "What is your name?"))

Output

(print "Hi " name "!")
    
(print
    "West of House\n"
    "This is an open field west of a white house, with a boarded front "
    "door.\n"
    "There is a small mailbox here.\n"
    "A rubber mat saying 'Welcome to Zork!' lies by the door.")
    
(print (list 1 2 3))
(print true)
(print (lambda (x) (x)))

Random Numbers

Generate a random number between 0 and 1

(let x (random))

Working With Strings

(print (string-replace "The quick brown fox" "brown" "red"))

Records

(let person (record :foo 10 :bar 3.14159 :baz true))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment