Skip to content

Instantly share code, notes, and snippets.

View quephird's full-sized avatar

danielle quephird

View GitHub Profile
@quephird
quephird / bidirectional_typechecker.swift
Created September 8, 2026 02:27
Simple bidirectional type checker in Swift
// NOTA BENE:
//
// The supports a _very_ tiny AST, with only a few possible
// types and just a few more expressions.
//
// Modelled on the excellent blog post here:
//
// https://jimmyhmiller.com/easiest-way-to-build-type-checker
indirect enum Type: Equatable, CustomStringConvertible {
(require ['clojure.string :as 'str])
(def cpu (atom {:x 1 :cycles 0}))
(def log (atom [1]))
(def crt (atom []))
(defn draw-pixel []
(let [x (get-in @cpu [:x])
(require ['clojure.string :as 'str])
(def head (atom [0 0]))
(def tail (atom [0 0]))
(def visited-tail-positions (atom #{[0 0]}))
(defn get-x [atom]
(get @atom 0))
(require ['clojure.string :as 'str])
(defn to-vec-of-ints [line]
(->> line
(map #(Integer/parseInt (str %)))
vec))
(defn to-grid [trees]
(->> trees
(map to-vec-of-ints)
(require ['clojure.string :as 'str])
;; The file system is represented by a deep hashmap
;; of file and directory names as keys, and either a
;; file size or list of subdirectory names and files as
;; their values.
(def file-system (atom {"/" {}}))
;; The current directory is always a vector of names.
;; For example, the path "/foo/bar/baz" is represented by
(require ['clojure.string :as 'str])
(def stacks
{1 ["Q" "M" "G" "C" "L"]
2 ["R" "D" "L" "C" "T" "F" "H" "G"]
3 ["V" "J" "F" "N" "M" "T" "W" "R"]
4 ["J" "F" "D" "V" "Q" "P"]
5 ["N" "F" "M" "S" "L" "B" "T"]
6 ["R" "N" "V" "H" "C" "D" "P"]
7 ["H" "C" "T"]

Sometimes you just want to be able to modularize/namespace your code without having to make a full-fledged library out of it. Go seems to discourage this sort of this as of 1.16 and wants you make a separate remote repo to house such code, and then you can import it into your main project. Unless I'm missing something, this feels like Go discourages local namespacing of code within a single project. But there is a way to accomplish this even if it's not considered idiomatic.

  • Relative to the root directory of your project, first create a new directory within your main project to house a local module, in this example zomg.
  • Then from within that directory create a new file, say, zomg.go, and put the following in it:
#version 100
precision mediump float;
uniform float u_time;
uniform vec2 u_resolution;
#define FIREWORK_COUNT 5.0
#define FIREWORK_DURATION_IN_SECONDS 10.0
#define PI 3.1415926
use std::io::stdin;
fn what_is_your_name() -> String {
println!("Hello! What's your name?");
let mut your_name = String::new();
stdin()
.read_line(&mut your_name)
.expect("You forgot to enter something!!!");
your_name