Created
April 21, 2013 02:29
-
-
Save beakr/5428226 to your computer and use it in GitHub Desktop.
Schnops programming language syntax.
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
# Welcome to Schnops! This is a comment. | |
# Comments are ignored when you run the program. | |
#- | |
If you have a lot of cool comments you can put | |
them all in a multiline commment. Multiline comments | |
can space multiple lines and have to be opened and closed | |
with '#-' and '-#'. | |
-# | |
# The most simple program you can get is adding two numbers | |
# together. Schnops acts like you'd expect, and handles all | |
# sorts of math fine. | |
2 + 4 | |
8 - 2 | |
3 * 2 | |
12 / 2 | |
# There's also some pretty cool mathematical functions, like | |
# tan(), log(), sin(), cos(), and sqrt()! | |
# | |
# Since these functions aren't as common, you call them on the | |
# Math class, which contains a lot of methematical stuff. | |
Math sqrt(10) | |
Math tan(5) | |
Math cosh(6) | |
# Let's define our own simple class for a cow, with some methods! | |
class Cow { | |
def initialize() { | |
@legs = 4 | |
@legs_butchered = 0 | |
} | |
def moo { | |
print("Moo!") | |
} | |
def legs { | |
return @legs | |
} | |
def legs_butchered { | |
return @legs_butchered | |
} | |
# This may be supported instead of the above | |
# two methods... | |
property ^legs | |
property ^legs_butchered | |
def butcher(legs_butchered) { | |
@legs - legs_butchered | |
@legs_butchered + legs_butchered | |
} | |
} | |
# Initialize a new cow named Berble | |
berble = new Cow | |
# Let's make Berble make moo noises with a loop! | |
3 times: | |
berble moo. | |
# Now let's be evil and cut off some of Berble's legs! | |
berble butcher(2) # Only two legs... | |
# Since we were evil, let's see how many legs remain... | |
berble legs #=> 2 | |
# We also cut off two legs... let's make sure: | |
berble legs_butchered #=> 2 - great! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment