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
use std::collections::HashMap; | |
use std::rc::Rc; | |
use std::sync::atomic::AtomicUsize; | |
use std::sync::atomic::Ordering; | |
pub fn main() { | |
let x = Value::Symbol(Symbol("x".into())); | |
let quote = Value::Symbol(Symbol("quote".into())); | |
let quotx = cons(quote.clone(), cons(x.clone(), nil())); | |
let lambda = Value::Symbol(Symbol("lambda".into())); |
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
use std::sync::atomic::{AtomicPtr, Ordering}; | |
use std::time::Duration; | |
fn main() { | |
let counter = Box::leak(Box::new(Atom::new(0))); | |
for _ in 0..100 { | |
std::thread::spawn(|| { | |
counter.swap(inc); | |
}); |
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
from __future__ import annotations | |
import dataclasses | |
from typing import Any, TypeAlias | |
Expr: TypeAlias = Any | |
@dataclasses.dataclass | |
class Context: | |
env: dict[str, Any] = dataclasses.field(default_factory=dict) |
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
digraph { | |
subgraph cluster1 { | |
label="Any" | |
0 [ color=blue; label = "0: Var(0)" ] | |
1 [ color=red; label = "1: Value((VTop, Span(5)))" ] | |
} | |
subgraph cluster2 { |
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
use std::cell::RefCell; | |
use std::collections::{HashMap, HashSet}; | |
use std::rc::Rc; | |
use std::sync::atomic::{AtomicU64, Ordering}; | |
fn main() { | |
use Term::*; | |
let id = Lam { | |
name: "x".into(), | |
body: Var { name: "x".into() }.into(), |
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
""" | |
Abstract Data Types in Python | |
============================= | |
(Python meta programming at its ugliest) | |
The implementation of `adt` is horrible. It could be improved by a few abstractions | |
for generating the different flavors of variant arguments. | |
I'm no longer sure if the use of exec is as bad as I initially thought. At least it's | |
relatively readable. |
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
from __future__ import annotations | |
import ctypes | |
import dataclasses | |
from typing import Any | |
LEAF_SIZE = 32 | |
LEAF_MASK = LEAF_SIZE - 1 | |
HASH_BITS = 64 | |
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
// This is "Typying Haskell in Rust", based on "Typing Haskell in Haskell": | |
// https://web.cecs.pdx.edu/~mpj/thih/thih.pdf?_gl=1*1kpcq97*_ga*MTIwMTgwNTIxMS4xNzAyMzAzNTg2*_ga_G56YW5RFXN*MTcwMjMwMzU4NS4xLjAuMTcwMjMwMzU4NS4wLjAuMA.. | |
use crate::Pred::IsIn; | |
use std::iter::once; | |
use std::rc::Rc; | |
type Result<T> = std::result::Result<T, String>; | |
macro_rules! list { |
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
use std::cell::RefCell; | |
use std::collections::HashMap; | |
use std::rc::Rc; | |
// What's missing: | |
// - branching (or more general, control flow) operations | |
// - records / structs or some form of named compound data type | |
type Symbol = &'static str; | |
type Block = Rc<[Op]>; |
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
import ast | |
import dataclasses | |
from typing import Any, Optional, TypeAlias | |
Expr: TypeAlias = Any | |
class Context: | |
def __init__(self, env=None): |
NewerOlder