Skip to content

Instantly share code, notes, and snippets.

View dhilst's full-sized avatar
😻

Daniel Hilst dhilst

😻
View GitHub Profile
@dhilst
dhilst / lambda_nums.py
Created May 12, 2021 20:00
Church encoding sketch in python
nums = [
(lambda f, x: x),
(lambda f, x: f(x)),
(lambda f, x: f(f(x))),
]
result = 0
calls = []
def f(x):
class sym:
def __init__(self, name):
self.name = name
def __str__(self):
return f":{self.name}"
def builtin_func(name):
def inner(f):
from ast import (
NodeTransformer,
arguments,
arg,
Lambda,
parse,
In,
Call,
Expression,
fix_missing_locations,
@dhilst
dhilst / bnf.py
Last active December 6, 2020 14:18
import sys
from sly import Lexer, Parser # type: ignore
from collections.abc import Iterable
# lamb -> LAMB ID DOT term
# lamb -> appl
# appl -> appl term
# appl -> term
# term -> LPAR lamb RPAR
# term -> ID
@dhilst
dhilst / bnf.py
Last active December 6, 2020 13:40
Parser BNF and output python module that can parse that grammar using SLY project
import sys
from sly import Lexer, Parser
from collections.abc import Iterable
# lamb -> LAMB ID DOT term
# lamb -> appl
# appl -> appl term
# appl -> term
# term -> LPAR lamb RPAR
# term -> ID
eval((λx.x) 1)
eval((λx.x))
eval(1)
appl((λx.1), 1) => 1
eval((λx.(λy.x)) 1 2)
eval((λx.(λy.x)) 1)
eval((λx.(λy.x)))
eval(1)
appl((λx.(λy.1)), 1) => (λy.1)
#!/Users/gecko/code/deployment/minsible
- debug:
@dhilst
dhilst / minsible
Last active November 27, 2020 19:51
#!/bin/sh
#
# Wrapper over ansible include tasks to make simple executable playbooks
# example https://gist.github.com/e39284344e3fd29b3202571678b6a343
task="${PWD}/$1"
ansible localhost -m include_tasks -a file=$task -c local -i /dev/null
@dhilst
dhilst / Program.cs
Last active November 21, 2020 13:13
Typed primitives in c#
using System;
namespace hello
{
// A typed primitive it narrows the type of primitive
class TypedPrim<T>
{
public T Value { get; set; }
public static implicit operator T(TypedPrim<T> v) => v.Value;
public static explicit operator TypedPrim<T>(T v) => new TypedPrim<T>() { Value = v };
@dhilst
dhilst / gist:858244a7f6b06c6929a0b022c362ff53
Created August 16, 2020 22:27
parse_combinator in python
from typing import *
import re
Result = Tuple[str, Any]
Parser = Callable[[str], Result]
class ParseError(Exception):
pass