This file contains hidden or 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
#include <assert.h> | |
#include <stdlib.h> | |
#define LIST(a) struct { \ | |
a v; \ | |
void *n; \ | |
} | |
#define CAR(xs) xs->v | |
#define CDR(xs) xs->n |
This file contains hidden or 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
# Computes ab in the symmetric group S_n, where a and b are given in cyclic | |
# notation. | |
def compose(a, b, n): | |
i = 1 | |
out = [] | |
while not i in out: | |
out.append(i) | |
i = apply(a, apply(b, i)) | |
This file contains hidden or 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
%option noyywrap | |
%{ | |
/* | |
* Copyright (c) 2010 Forest Belton (apples) | |
* | |
* Permission is hereby granted, free of charge, to any person | |
* obtaining a copy of this software and associated documentation | |
* files (the "Software"), to deal in the Software without |
This file contains hidden or 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
var tenyr = (function() { | |
"use strict"; | |
var regbuf = new ArrayBuffer(4 * 16); | |
var regs = new Int32Array(regbuf); | |
var mem = {}; | |
var hooks = []; | |
var add_hook = function(hook) { | |
hooks.push(hook); |
This file contains hidden or 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
intro = [ | |
'=======================================', | |
'VVTB (Very Very Tiny Basic) interpreter', | |
'(c) 2012 Forest Belton (case)', | |
'=======================================' | |
] | |
prgm = {} | |
vars = {} |
This file contains hidden or 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
{-# LANGUAGE DeriveFunctor #-} | |
import Text.ParserCombinators.Parsec | |
import Data.Functor.Foldable | |
import qualified Data.Set as S | |
data FormF a = Var Char | |
| Not a | |
| And a a | |
| Or a a |
This file contains hidden or 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
-module(zipr). | |
-export([new/1, cur/1, to_list/1, next/1, prev/1, addl/2, addr/2]). | |
new(X) -> {[], X, []}. | |
cur({_L, X, _R}) -> X. | |
to_list({L, X, R}) -> lists:reverse(L) ++ [X] ++ R. | |
next({L, X, [H|R]}) -> {[X]++L, H, R}. | |
prev({[H|L], X, R}) -> {L, X, [H]++R}. | |
addl({L, X, R}, X1) -> {L, X1, [X]++R}. | |
addr({L, X, R}, X1) -> {[X]++L, X1, R}. |
This file contains hidden or 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
macro lam { | |
rule { $x:ident $y:expr -> $body:expr } => { | |
(function($x) { return lam $y -> $body; }) | |
} | |
rule { $x:ident -> $body:expr } => { | |
(function($x) { return $body; }) | |
} | |
} |
This file contains hidden or 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
var rm_lr = function(name, grammar) { | |
var p_with = grammar[name].filter(function(x) { return x[0] == name; }), | |
p_wo = grammar[name].filter(function(x) { return x[0] != name; }); | |
grammar[name] = p_wo.concat(p_wo.map(function(wo) { | |
return wo.concat([name + "'"]); | |
})); | |
grammar[name + "'"] = [['e']].concat(p_with.map(function(x) { | |
return x.slice(1).concat([name + "'"]); |
This file contains hidden or 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
macro lazy { | |
rule { $e:expr } => { | |
new function() { | |
this.done = false; | |
this.valueOf = function() { | |
if(!this.done) { | |
this.done = true; | |
this.value = $e; | |
} | |
return this.value; |