Skip to content

Instantly share code, notes, and snippets.

View dannypsnl's full-sized avatar

Lîm Tsú-thuàn dannypsnl

View GitHub Profile
@dannypsnl
dannypsnl / egg.rkt
Last active December 17, 2025 08:25
egg first attempt and visualization
#lang racket
(require (for-syntax syntax/parse))
(require data/queue)
(require graphviz)
(struct e-class (e-nodes))
(struct e-graph (e-classes) #:transparent)
#|
The rewriter is a function that takes
1. a callback (to add result into same e-class), and
@dannypsnl
dannypsnl / syntax-parse-LL.rkt
Last active December 15, 2025 08:25
LL syntax-parse implementation
#lang racket
(require syntax/parse
(for-syntax syntax/parse))
(provide W)
(define-syntax (F stx)
(syntax-parse stx
#:datum-literals (+ * -)
[(_ (~seq a + b ...))
@dannypsnl
dannypsnl / parallel-thread.rkt
Created November 23, 2025 11:02
Playing parallel threads of Racket 9
#lang racket
(define (split-list lst n)
(for/list ([i (in-range 0 (length lst) n)])
(take (drop lst i) (min n (- (length lst) i)))))
(define P (make-parallel-thread-pool (processor-count)))
(define JOBS (split-list (range 1 10000000) 100000))
@dannypsnl
dannypsnl / EasierIndices.agda
Created September 29, 2025 18:49 — forked from yangzhixuan/EasierIndices.agda
Making working with de Brujin indices easier
{-
This file demonstrates a technique for making working with de Bruijn-indexed
terms easier that I learnt from the paper /The Linearity Monad/ by Jennifer
Paykin and Steve Zdancewic. After defining well-typed terms `Γ ⊢ τ` using de Bruijn
indices, we define an auxiliary function `lam` that takes in the variable term explicitly:
> lam : {V : Type} {Γ : Cxt V} {τ σ : Ty V}
> → (({Δ : Cxt V} → {{IsExt Δ (Γ , τ)}} → Δ ⊢ τ)
> → (Γ , τ) ⊢ σ)
> → Γ ⊢ τ ⇒ σ
@dannypsnl
dannypsnl / README.md
Last active September 1, 2025 07:09
Check given multiplication table form a grope structure or not

Grope

A grope is a set $G$ together with a binary operation $\circ$, in which the identity

$$ x \circ (y \circ x) = y $$

is satisfied for all $x, y \in G$.

@dannypsnl
dannypsnl / stuck.ss
Created February 21, 2025 13:13
Get chez scheme stuck
(import (chezscheme))
(define handler-key (gensym))
(define th #f)
(define x 0)
(define (sub)
(define n
(call/cc (lambda (k)
@dannypsnl
dannypsnl / miniKanren.rkt
Last active February 20, 2025 01:30
miniKanren in 40 minutes (so undone)
#lang racket
(require (for-syntax syntax/parse))
(define (reify-name n)
(string->symbol
(string-append "_" (number->string n))))
(struct fresh (value count)
#:methods gen:custom-write
[(define (write-proc self out mode)
(if (fresh-value self)
@dannypsnl
dannypsnl / substitution.rkt
Last active January 26, 2025 19:23
can naive substitution work, if we apply binding as sets of scopes?
#lang racket
(require nanopass)
(define-language L
(terminals
(symbol (x)))
(Expr (e)
(λ x e)
(e0 e1)
x))
@dannypsnl
dannypsnl / middle-convention.rkt
Last active January 23, 2025 05:02
math convention
#lang racket
(require (for-syntax syntax/parse))
(define-syntax (math stx)
(syntax-parse stx
#:datum-literals (+ *)
[(_ (o ...) op o* ...)
#'(let ([k (math o ...)])
(math k op o* ...))]
[(_ (o ...)) #'(math o ...)]
@dannypsnl
dannypsnl / mobius.rkt
Last active January 14, 2025 07:20
Möbius strip
#lang racket
(require plot
plot/utils)
(plot3d
(parametric-surface3d
(λ (θ t)
(define R 1)
(define s (/ t 2))
(list