Skip to content

Instantly share code, notes, and snippets.

View dhilst's full-sized avatar
😻

Daniel Hilst dhilst

😻
View GitHub Profile
#![feature(try_blocks, try_trait_v2)]
#![allow(dead_code)]
#[derive(Debug)]
struct Foo<T>(T);
// Parametric types are bound during method calls
trait Bar<T> {
// Associated types are bound during Trait implementation
type AT;
from lark import Lark, Transformer, v_args
# 1. Define the grammar for second order logic using ASCII characters
grammar = """
start: formula
?expr: arith_expr
| bool_expr
?arith_expr: term
@dhilst
dhilst / README.md
Last active February 11, 2024 16:20
sexp parsing fun

A simple boolean language with definitions implemented over Sexp.t

Conclusions:

  • Is pretty easy to write a custom sexp_of_t and t_of_sexp functions.
  • This lets us to add some sugar over the atoms, I use ?v for variables as an example here
  • On top of that we can build superset of S-Expressions language which is easy to parse and very expressive

!!!! from manual !!!!

@TODO: FIX THIS!

@dhilst
dhilst / index.html
Last active August 28, 2024 02:06
html from js
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
</head>
<body>
<script>
function html(text, ...values) {
const html = text.flatMap((text, i) => {
return [text, values[i]?.outerHTML || values[i]]
@dhilst
dhilst / tco.py
Last active June 23, 2023 02:03
tco python with exceptions
from typing import ParamSpec, TypeVar, Callable, reveal_type
T = TypeVar("T")
P = ParamSpec("P")
def tco(f: Callable[P, T]) -> Callable[P, T]:
unwind = False
@dhilst
dhilst / monadproto.py
Created June 17, 2023 17:06
Py Monad Protocol
from typing import *
from typing_extensions import ParamSpec
A = TypeVar("A")
B = TypeVar("B")
C = TypeVar("C")
D = TypeVar("D")
E = TypeVar("E")
F = TypeVar("F")
G = TypeVar("G")
@dhilst
dhilst / grammar.y.rb
Created November 4, 2022 01:51
Getting started with racc (ruby LALR(1) parser lib)
class Calcparser
prechigh
left '*' '/'
left '+' '-'
preclow
options no_result_var
rule
target: expr
@dhilst
dhilst / lcdbjn.ml
Last active September 7, 2022 21:39
open Format
type term =
| Var of int
| Lamb of term
| App of term * term
let rec shift i depth = function
| Var x when x < depth -> Var x
| Var x -> Var (x + i)
@dhilst
dhilst / unicode_to_utf8.ml
Last active September 2, 2022 23:46
OCaml Unicode codepoints to UTF-8 string
open Printf
let (%) = Int.logor
let (<<) = Int.shift_left
let (>>) = Int.shift_right
let (&) = Int.logand
let utf_8_bytes_of_unicode i =
if i <= 0x007F
then
(**
* Closed Terms Lambda Caulcus with De Bruijn Indexes
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*)
open Format
type term =
| Var of int
| Lamb of int * term