Skip to content

Instantly share code, notes, and snippets.

Leonard Ritter paniq

  • Duangle GbR
View GitHub Profile
View runtime_closures_version_2.md

Transparent Runtime Closures, Second Attempt

Some thoughts on how to do native runtime closures in Scopes in a transparent, yet controllable way:

While we're typechecking a function, the function is eventually accessing a runtime variable outside its function scope. Currently, I'm detecting that already, but just to produce a compiler error. But it could be allowed, and a environment record could be built as the function is typed, of all the expressions outside of its boundary that need to be put into it.

The only way we're going to get these expressions into the function is through an environment parameter of tuple type. So we're not just recording unbound variables, we also rewrite their access; a new equivalent value is added to the environment tuple, and the environment tuple entry is extracted instead. We also record in a map which exterior values need to be mapped to which member in the environment.

When we're done typing the function, we have a complete

View test_nanovg.sc
define sdl
import ..tukan.sdl
define glmain
import ..tukan.glmain
using import glm
using import glsl
using import ..tukan.gl
using import ..tukan.nanovg
View gist:bbe6610d4e61b527eef45c866c3825d6
using import Array
let C =
import-c "lib.c"
""""int printf (const char *fmt, ...);
'()
let SerialArray = (GrowingArray hash)
let salt = (hash "a bit of salt")
View gist:e69abff3e51338c5d119e77e9e103364
inline svf~ (srate)
let srate = (srate as f32)
let invsrate = (/ (2.0 * srate))
stateful-map
inline "svf~" (src state...)
# signal 523.0 0.0 0.0
let in cutoff res drive = (src)
drive := (drive * 0.1)
freq := 2.0 * (sin (pi * (min 0.25 (cutoff * invsrate))))
damp := (min 2.0
View gist:a44a6ea103693192bb7fbfe18c8e1792
import ..tukan.audio
using import ..tukan.sdl
using import itertools
let audio = tukan.audio
let BUFFERSIZE = 256
let NUMBUFFERS = 2
inline audio-queue (srate)
View gist:dd26a2a8701ba98ef8a0d59303f1f93e
let infinite-range =
Generator
inline () 0
inline (x) true
inline (x) x
inline (x) (x + 1)
inline zip (a b)
let start-a valid-a at-a next-a = ((a as Generator))
let start-b valid-b at-b next-b = ((b as Generator))
View gist:6b2013d1a0c8214826c9f0f48f4d3e6f
# last value in an expression block is returned
do
true
# when we want to return multiple arguments, there's a pass-through token:
do
_ true true
# how do we pass zero arguments?
do
View polyrhythmic_primes.py
# Polyrhythmic Prime Discovery
# by Leonard Ritter <contact@leonard-ritter.com>
primes = []
phases = []
counter = 2
def is_any_phase_zero ():
View gist:df7f21bb8a4a9363dba486f44904cbb0
say we start with two linear functions
f(x) = a*x + b
g(x) = c*x + d
from previous work, we have their integrals (ignoring the offset)
F(x) = 1/2*a*x^2 + b*x
View wow.md

71 41 83 70 28 5 3 4 7 71 4 3 4 48 92 26 60 46 15 95 84 93 16 60 18 53 17 15 6 74 94 96 73 27 83 72 16 81 91 3 53 51 92 43 38 15 48 42 71 51 40 37 71 37 73 61 72 45 96 26 6 30 27 71 61 51 48 7 95 83 27 73 6 29 15 16 29 16 27 17 53 16 57 51 26 6 73 95 27 81 53 51 27 6 51 70 84 28 82 92 5 92 27 94 28 65 64 36 71 6 73 73 70 16 29 38 16 35 50 25 64 27 16 17 5 71 7 38 93 4 45 72 16 15 50 27 62 95 80 56 61 83 27 6 29 72 42 92 56 17 83 25 47 38 16 29 4 93 63 18 64 15 6 3 50 26 28 82 73 4 7 42 49 7 17 94 52 40 41 28 83 95 54 6 74 56 26 72 93 72 4 7 16 5 70 49 83 58 82 62 59 53 62 28 50 72 50 44 61 15 49 38 72 71 27 72 30 59 17 61 42 70 62 27 48 15 50 18 27 17 60 82 73 49 3 16 82 49 92 82 39 73 74 42 28 62 93 48 28 39 95 16 93 35 59 35 5 82 46 38 28 34 95 83 55 72 39 84 17 49 84 62 39 94 95 73 26 94 72 4 28 94 46 5 3 15 70 60 72 16 28 82 25 61 64 58 30 48 36 70 59 82 37 48 81 47 72 63 50 95 92 15 93 71 83 5 29 93 94 83 81 29 92 27 69 28 95 5 51 83 4 51 50 94 15 43 95 6 83 81 85 41 62 61 82 72 85 27 15 6 82 81 94 62 47

You can’t perform that action at this time.