Skip to content

Instantly share code, notes, and snippets.

@Glorp
Glorp / 16.lua
Last active December 16, 2023 16:19
local Vec, allvecs = {}, {}
setmetatable(allvecs, { __mode = "kv" })
local function vec(x, y)
local key = x .. "," .. y
local found = allvecs[key]
if found then return found end
local v = { x = x, y = y }
setmetatable(v, Vec)
allvecs[key] = v
return v
local function point(x, y)
return { x = x, y = y, key = x .. "," .. y }
end
local function points(lend)
local i = lend.idx
local off = 0 - lend.off
local other = lend.other.idx
local ended = false
local line = lend.line
local Cons = {
__tostring = function(cons) return "(" .. tostring(cons.car) .. " . " .. tostring(cons.cdr) .. ")" end
}
local function cons(car, cdr)
local res = { car = car, cdr = cdr }
setmetatable(res, Cons)
return res
end
#lang racket
(define start '(0 3 3 3 0 1))
(define a '(3 2 1 1 0 0))
(define b '(0 0 1 0 1 0))
(define c '(-1 1 -2 1 -2 1))
(define d '(1 1 1 0 3 1))
(define e '(-2 +2 0 -2 +2 -2))
@Glorp
Glorp / input.txt
Last active August 16, 2021 13:16
term frequency
White tigers live mostly in India
Wild lions live mostly in Africa
#lang lazy
; put racket instead of lazy in the line above to make it less lazy
(struct zero () #:transparent)
(struct succ (pred) #:transparent)
(define one (succ (zero)))
(define two (succ one))
(define (inf) (succ (inf)))
// to run: jshell caesar.jsh
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.io.PrintStream;
public class Caechar {
public static Caechar fromAlphabet(String str) {
#lang racket
(define alphabet (list->vector (string->list "abcdefghijklmnopqrstuvwxyzæøå ")))
(define (caeschar shift char)
(match char
[#\newline #\newline]
[#\return #\return]
[c (match (vector-member c alphabet)
[#f #f]
type KuEgenskaper =
{ navn : string
hoyde : int
}
type Animal =
| Coo of KuEgenskaper
| Hest of int
| Bamse
@Glorp
Glorp / trees.js
Last active January 7, 2023 16:43
// sums, constructing
const tag = t => (...args) => ({ tag: t, values: [...args] });
// testing
tag("label")(1, "horse", [2,3]);
// fruit
const Peach = tag("Peach")();
const Apple = tag("Apple")();
const Pear = tag("Pear")();