Skip to content

Instantly share code, notes, and snippets.

View be5invis's full-sized avatar

Belleve be5invis

View GitHub Profile
var SequenceRule = function() {
var parts = arguments;
if(!parts.length) return function(phase, onmatch, onfail) {
return onmatch(phase, '')
}
var last = parts[parts.length - 1];
var trailing = function(phase, onmatch, onfail){
last(phase, function(phase1, result){ onmatch(phase1, [result]) }, onfail)
};
for(var j = parts.length - 2; j >= 0; j--) {
@be5invis
be5invis / gist:9377026
Created March 5, 2014 21:29
A draft for some weird language
[semantics [or a b]
[let [ta [evaluate a]]
[if ta [return ta] [return [evaluate b]]]]]
[semantics [while condition body]
[block LOOP_START
[let [continue? [evaluate condition]]
[if continue?
[begin
[evaluate body]
var Ref = function(s){ this.ref = s }
var newt = function(n){
return function(){
return new Ref("_" + (n++))
}
}(0);
function id(x){ return x }
function normalizeTerm(form){ return normalize(form, id) }
function normalize(form, ctx){
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
var H = 3
var Η = 2
console.log(Η + H) // 5
@be5invis
be5invis / interpreter.js
Last active July 1, 2019 11:26
A CPS-style S-exp interpreter (with call/cc)
function interpret(form, env, k){
if(form instanceof Array){
switch(form[0]){
case 'lambda': {
var params = form[1];
var body = form[2];
return k(function(k){ return function() {
var e = Object.create(env);
for(var j = 0; j < params.length; j++)
e[params[j]] = arguments[j];
@be5invis
be5invis / ceki-tco.js
Last active January 28, 2016 20:55
CEK interpreter with TCO example
// noprotect
function Lambda(param, body, e){
this.param = param
this.body = body
this.env = e
};
Lambda.prototype.apply = function(t, args, k0){
var e_ = Object.create(this.env);
for(var j = 0; j < this.param.length; j++){
e_[this.param[j]] = args[j];
@be5invis
be5invis / autohint.js
Last active June 28, 2020 16:58
Automatic gridfit generator for Han characters.
var upm = 1000;
function Point(x, y, on, interpolated){
this.xori = x;
this.yori = y;
this.xtouch = x;
this.ytouch = y;
this.touched = false;
this.donttouch = false;
this.on = on;
function $(C,E,K){if(!(C instanceof Array))return K("string"==typeof C?
E[C]:C);switch(C[0]){case"lambda":return K(function(K){return function(
){for(var e=Object.create(E),u=0;u<C[1].length;u++)e[C[1][u]]=arguments
[u];return $(C[2],e,K)}});case"if":return $(C[1],E,function(e){return e
?$(C[2],E,K):$(C[3],E,K)});case"callcc":return $(C[1],E,function(C){var
E=function(){return function(C){return K(C)}};return C(E)(E)});case "'"
:return K(C[1]);default:return $c(C,E,K)}}function $c(C,E,K){return $(C
[0],E,function(e){return $$(C.slice(1),E,function(C){return e(K).apply(
null,C)})})}; function $$(C,E,K) {return C.length?$(C[0],E,function(e){
return $$(C.slice(1),E,function(C){return K(C?[e]:[e].concat(C))})}):K(