Created
February 27, 2018 22:08
-
-
Save joedougherty/bd5e99f9486c2fce500b95c582715344 to your computer and use it in GitHub Desktop.
forth ideas (in crystal)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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