Created
November 2, 2011 18:58
-
-
Save robotlolita/1334537 to your computer and use it in GitHub Desktop.
Harmonia's silly example
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
### core.harm --- Harmonia's core library | |
# | |
# This module provides the core functions from Harmonia implemented in | |
# Harmonia itself. | |
# Booleans are just plain functions, receiving two function bodies and | |
# calling the appropriate one. | |
let true [a {}, b {}] { | |
call a | |
}; | |
let false [a {}, b {}] { | |
call b | |
} | |
# The plain `if' function works on top of the Boolean functions. The | |
# consequent block is always required. | |
let if [condition, consequent, otherwise {}] { | |
condition consequent | |
otherwise | |
}; | |
# Function application is performed by the special `apply' macro, which | |
# just un-slices the list. | |
macro apply [fn, parms] { | |
~fn ~parms | |
}; | |
# Repetition constructions are based off recursion and the internal | |
# throw semantics. Other repetition structures are pilled on top of the | |
# core `loop' function. | |
# | |
# `break' is just a special function that throws itself. | |
let break { throw break }; | |
let loop [block] { | |
try { | |
call block } | |
catch matches break { | |
call return } | |
loop block; | |
}; | |
let while [condition, block] { | |
loop { | |
condition block break } | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment