Skip to content

Instantly share code, notes, and snippets.

@joedougherty
Created February 27, 2018 22:08
Show Gist options
  • Save joedougherty/bd5e99f9486c2fce500b95c582715344 to your computer and use it in GitHub Desktop.
Save joedougherty/bd5e99f9486c2fce500b95c582715344 to your computer and use it in GitHub Desktop.
forth ideas (in crystal)
class Stack
def initialize
@contents = [] of Int32
end
def pop
@contents.pop()
end
def push(value)
@contents << value
end
def peek
@contents[-1]
end
def height
@contents.size
end
end
data = Stack.new
stack_add = -> { data.push(data.pop() + data.pop()) }
dictionary = Hash{"add" => stack_add}
data.push(2)
data.push(3)
dictionary["add"].call()
puts data.peek()
puts data.height
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment