Skip to content

Instantly share code, notes, and snippets.

#include "MIDIUSB.h"
#define STATUS_LED 13
int pressed[72] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int changed[72] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
#define ROW_COUNT 9
#define COL_COUNT 8
int rows[ROW_COUNT] = {5, 6, 9, 10, 11, 12, 20, 19, 18};
int cols[COL_COUNT] = {21, 22, 23, 15, 16, 14, 0, 1};
@ianthehenry
ianthehenry / unquasiquote.md
Last active July 12, 2023 06:48
Lisp without quasiquote

I think that you can write a reasonable lisp entirely without quasiquote.

There are three pieces that you need:

  1. Functions can appear literally in the AST (à la Janet and Common Lisp)
  2. Macros can appear literally in the AST, and specifically they have to have a different runtime representation than functions
  3. Special forms are their own thing explained below

Basically when you're writing Janet-style macros, you can/should unquote pretty much every symbol in order to do lexical lookup at the macro-definition at compile time, rather than the call-site at runtime:

@ianthehenry
ianthehenry / synth.ino
Created May 15, 2023 02:34
Binary synthesizer
#include "MIDIUSB.h"
#define STATUS_LED 13
int pressed[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int intervals[8] = {1, 2, 4, 8, -1, -2, -4, -8};
int rows[2] = {5, 6};
int cols[4] = {9, 10, 11, 12};
int note = 0;
@ianthehenry
ianthehenry / turtle.janet
Last active July 12, 2023 07:00
Bauble: animated turtle
(def eye-target [100 20 40])
(def eye-shapes
(sphere 5
| move [8 10 10]
| mirror :z))
(def eyes
(eye-shapes
| color (c + 0.5)
$ hyperfine --warmup 10 --shell=none 'zig-out/cyber/cyber test/bench/fib/fib.cy' 'janet test/bench/fib/fib.janet' 'lua test/bench/fib/fib.lua' 'luajit test/bench/fib/fib.lua'
Benchmark 1: zig-out/cyber/cyber test/bench/fib/fib.cy
Time (mean ± σ): 54.6 ms ± 1.4 ms [User: 53.1 ms, System: 1.1 ms]
Range (min … max): 52.8 ms … 59.7 ms 55 runs
Benchmark 2: janet test/bench/fib/fib.janet
Time (mean ± σ): 191.3 ms ± 5.4 ms [User: 188.5 ms, System: 1.6 ms]
Range (min … max): 184.1 ms … 203.6 ms 16 runs
Benchmark 3: lua test/bench/fib/fib.lua
@ianthehenry
ianthehenry / hot-air-balloon.janet
Last active September 9, 2022 15:36
Bauble: hot air balloon
(def bottom (+ -100 -50))
(defn quantize [x y]
(x * y | round / y))
(def envelope
(sphere 100
| union :r 50 (cylinder :y 25 50 | move :y -100)
| scale
:y (ss p.y bottom 100 1 0.80)