Last active
September 25, 2015 22:57
-
-
Save mre/997991 to your computer and use it in GitHub Desktop.
Prototype of a functional scripting language.
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
# Prototype of a functional scripting language. Just fooling around. Nothing to see here. | |
# | |
A long comment. | |
Very long, they say. | |
# | |
# There's only one data type: list | |
# Assign variables with : | |
# Create a list | |
l: 1 2 3 | |
# Concatenate lists | |
l2: l 4 5 6 | |
# A statement without an = is a print statement | |
l2 # Output: 1 2 3 4 5 6 | |
"hello" # Output hello | |
# Functions | |
even: mod 2 is 0 | |
# Use the function | |
evens: filter even l2 | |
evens # Output: 2 4 6 | |
# Every variable which is not defined before use | |
# is a parameter | |
add: | |
a + b | |
# Variables and functions are the same | |
sum: reduce add l2 | |
sum # Output: 1+2+3+4+5+6 = 21 | |
# Classes are functions | |
# Creates a person constructor with public members name and gender | |
person name gender | |
# Inheritance | |
student person id | |
id # Private member | |
p1: "hans" "male" | |
s1: student p1 1234 | |
s1 # Output: Hans male 1234 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment