Skip to content

Instantly share code, notes, and snippets.

@jackfirth
jackfirth / stream-fusion-to-completeness.rkt
Created December 27, 2024 00:21
A Racket port of some of the code in the paper "Stream Fusion, to Completeness"
#lang racket
;; Ported from the paper "Stream Fusion, to Completeness" (POPL 2017)
(struct staged-stream (init-function step-function))
(struct staged-vec-stream-state (index-id vec-id))
(define (staged-vec-stream vec-expr)
(define (init state-accepting-result-continuation)
@jackfirth
jackfirth / syntax-format.rkt
Created August 15, 2024 09:57
`fmt`-style pretty printing, but of syntax objects
#lang racket
;; This module defines a Racket syntax formatter that uses pretty-expressive as
;; the underlying formatting engine. The formatter takes *syntax objects* as
;; input and produces a pretty-expressie document as output. Formatting occurs
;; in steps, similar to macro expansion: each step analyzes a syntax object and
;; returns a *partially formatted* syntax object, which consists of strings
;; interleaved with unformatted syntax objects representing the subforms of the
;; input object. Formatting begins with the outermost syntax object and
@jackfirth
jackfirth / dispatch-benchmark.rkt
Last active November 8, 2023 05:32
Measuring the performance of various ways of dispatching on the type of something in Racket
#lang racket
(require racket/generic)
(define-generics vable
(get-v vable))
(struct a (v)
#:methods gen:vable
[(define (get-v a)
@jackfirth
jackfirth / transducer.effekt
Last active August 26, 2022 21:47
An Effekt implementation of transducers and stream pipelines.
// This is my attempt at translating the stream pipeline and transducer library I wrote for Racket
// into Effekt, using algebraic effects to model the actions of consuming and emitting values in a
// stream pipeline. The stream pipeline library I wrote is part of my package Rebellion, see its docs
// here: https://docs.racket-lang.org/rebellion/Streaming_Computations.html. The basics are that a
// stream pipeline combines an initial source (a lazy stream, sequence, or other similar object) and
// a terminal sink, called a *reducer*, along with any number of intermediate transformations called
// *transducers*.
type Option[A] { Present(value: A); Absent() }
class Map<K, V> {
   ...

    V getOrSignal(K key) {
        if containsKey(key) {
            return get(key);
        } else {
            MissingKeySignal signal = throw new MissingKeyException(this, key);
            return switch signal {
@jackfirth
jackfirth / collection-api-sketch.md
Last active May 26, 2022 09:49
Rhombus collection API ideas

Mandatory APIs:

interface List {
  size
  add(x)
  get(i)
  set(i, x)
  removeAt(i)
  insert(i, x)
@jackfirth
jackfirth / mutable-red-black-tree-pict.rkt
Created February 16, 2022 02:57
A debugging tool that draws a pict of a mutable red black tree. Useful for debugging Rebellion's RB trees in mutable sorted collection implementations.
#lang racket/base
(require racket/contract/base)
(provide
(contract-out
[mutable-rb-tree-pict (-> mutable-rb-tree? pict?)]))
@jackfirth
jackfirth / static-continuations.rkt
Last active December 10, 2021 08:22
A "static continuation" system for Racket macros.
#lang racket/base
;; This is a "static continuation" system, which I developed as a foundation for building macros like
;; the following:
;;
;; - The guard, guard-match, and guard-define statement macros in rebellion/private/guarded-block
;; - A (parameterize! id expr) statement macro that sets a parameter for the rest of the block
;; - An (open! disposable-expr) expression macro that allocates a resource and closes it at the end of
;; the block
@jackfirth
jackfirth / generic-list.rkt
Created July 21, 2021 03:20
Generic interface for Racket lists
#lang racket/base
(require racket/generic
(prefix-in racket/list. racket/list)
racket/match
racket/stream
racket/struct
racket/unsafe/ops
(prefix-in racket/vector. racket/vector)
#lang racket/base
(provide sdfn-register-id scalar-sdfn-register-id vec3-sdfn-register-id (struct-out sdfn-register))
(require syntax/parse)
(struct sdfn-register (size offset initial-values) #:transparent)