Skip to content

Instantly share code, notes, and snippets.

View milesrout's full-sized avatar

Miles Rout milesrout

View GitHub Profile
def enumerate_vs(S, G):
"""Enumerate all hypotheses contained in the version space bounded by S and G."""
hypotheses = set()
for s in S:
for g in G:
places = [i for i in range(len(s)) if s[i] != g[i]]
for ss in all_subsets(places):
conj = Conjunction(g[i] if (i in ss) else s[i] for i in range(len(s)))
hypotheses.add(conj)
return hypotheses
using cons = struct {
template <typename car>
struct value {
struct type {
template <typename cdr>
using of = cons_literal<car, cdr>;
};
};
template <typename car>
template<typename... Args>
bool all(Args... args) { return (... && args); }
bool b = all(true, true, true, false);
// within all(), the unary left fold expands as
// return ((true && true) && true) && false;
// b is false
def vau(ptree, env):
t1, s, t2 = ptree
fv = set.union(
t2.free_variables(),
env.free_variables())
if s is Ignore:
c, env1, _ = definiend(t1, fv)
return c.subst(evaluate(t2, concat_envs(env1, env)))
else:
x, X = make_distinct_var(fv)
@milesrout
milesrout / cons.py
Last active September 7, 2016 11:30
def lazy_any(*args):
for arg in args:
if bool(arg()):
return True
return False
def is_self_evaluating_term(obj):
return lazy_any(
lambda: is_primitive_data(obj),
lambda: is_primitive_operative(obj),
def attempt(f, is_valid, *args):
return next(y for y in itertools.starmap(f, itertools.repeat(args)) if is_valid(y))
@milesrout
milesrout / file.py
Last active October 10, 2016 07:33
class _open_grailfile:
def __init__(self, path):
self.path = path
def __enter__(self):
"""Lock and open the Grailfile at the given path."""
# if the Grailfile is foobar/Grailfile, store a lock at foobar/.grail/LOCK
dotdir_path = _get_dotgrail_dir(path)
lock_path = dotdir_path / 'LOCK'
#ifndef FOO
#define FOO
#include <string>
namespace tec {
std::string utf8_encode(const std::wstring &wstr);
std::wstring utf8_decode(const std::string &str);
}
import itertools
import re
class Lexer:
def __init__(self, tokens):
self.tokens = tokens
self.regex = re.compile(self.combine_regexes(self.make_named_groups()))
def combine_regexes(self, named_groups):
return '|'.join(named_groups)

Chalice:

Chalice is a C-like language that attempts to be modern without being "modern". Without having to worry about backwards compatibility with the legacy of C, Chalice has an opportunity to clean up the language significantly, removing many aspects from the language that are considered to have been mistakes, but without removing the aspects of C that make it such a strong, simple, easy-to-use language.

The syntax of Chalice is intentionally very similar to C. Chalice does not have classes or methods. Chalice does not have references (neither Java-style nor C++-style). Chalice is pass-by-value, like C. That isn't to say that Chalice is identical to C. Chalice doesn't have a carcinogenic declaration syntax. Chalice is designed to be able to be parsed using a single token of lookahead, and compiled in a single pass.

Chalice takes a lot of inspiration from the Linux kernel coding style guidelines. For example, spaces cannot be used as indentation. Trailing whitespace is a compiler error. Chalice