Skip to content

Instantly share code, notes, and snippets.

View armstnp's full-sized avatar
🏗️

Nathan Armstrong armstnp

🏗️
View GitHub Profile

Further Lisp compression tinkering. Basic idea: most languages optimize for sequence structure, which fits for procedural code:

Statement A modifies the environment
Statement B modifies the environment
Statement C uses the modified environment to produce value
...

But a more functional style tends to structure things as a nested recursive tree, with the right-most branch being the heaviest.

@armstnp
armstnp / conversion.wpi
Last active January 20, 2022 23:10
A wispy syntax for Pie, from the excellent The Little Typer.
#lang wispie
;; 'encompassing' forms: claim, define, →, λ, Π - basically all the binding forms -
;; and a couple others that gain utility, such as ::
;; These implicitly encompass the remaining lines in the form as their sole remaining
;; parameter, unless explicitly indented to show boundaries (especially useful for
;; multiple lambda arguments, or to make clear that a lambda body is nested, e.g. a
;; lambda at the end of a line of other arguments)
claim Pear
ns medley.core
"A small collection of useful, mostly pure functions that might not look out
of place in the clojure.core namespace."
:refer-clojure :exclude [| boolean? ex-cause ex-message uuid uuid? random-uuid regexp?
defn find-first
"Finds the first item in a collection that matches a predicate. Returns a
transducer when no collection is provided."
[pred]
λ [rf]
@armstnp
armstnp / aoc-2021-18.cwj
Last active December 18, 2021 18:06
Wisply Clojure Test 2
ns advent-of-code-2021.day18
:require :[ advent-of-code-2021.core :as core
. :[ clojure.string :as str
. :[ clojure.zip :as z
def input
->> "day18.txt"
. core/read-input
. str/split-lines
. map read-string
@armstnp
armstnp / aoc-2021-16.cwj
Created December 16, 2021 19:57
Wispy Clojure - Cwojure?
ns advent-of-code-2021.day16
:require [advent-of-code-2021.core :as core]
. [clojure.string :as str]
def bitmap
. {\0 [0 0 0 0]
\1 [0 0 0 1]
\2 [0 0 1 0]
\3 [0 0 1 1]
\4 [0 1 0 0]
@armstnp
armstnp / gw2_guild_widget.js
Created December 24, 2020 06:14
Scriptable: GW2 Guild Widget
// #############
// ## Setup ##
// #############
// Step 1: Fill in your API key, or leave blank to use none; this will only present public info.
// - Don't have an API key? Create one! https://wiki.guildwars2.com/wiki/API:API_key
// - API key must have 'account' and 'guild' permissions for full guild access.
// - The key must belong to the guild owner account for full guild access.
const API_KEY = '';
@armstnp
armstnp / gw2_item_widget.js
Last active December 23, 2020 06:06
Scriptable: GW2 Random Item Widget
let item = await randomItem()
let size = await getSize()
if(size === null) { Script.complete() }
let widget = await createWidget(item, size)
if (config.runsInWidget) {
Script.setWidget(widget)
} else {
switch(size) {
case "small":
@armstnp
armstnp / BatchTestingMachine.java
Created August 7, 2020 06:12
Java Anonymous Classes and Lambdas
import java.util.ArrayList;
import java.util.List;
/***
* Tests collections of samples all at once.
*/
class BatchTestingMachine {
public List<String> processBatch(List<PatientSample> batch, ImmunityTest test) {
List<String> results = new ArrayList<>(batch.size());
@armstnp
armstnp / jda_bind.clj
Last active April 18, 2018 21:35
A quick-and-dirty echo bot using JDA in Clojure
(ns astralaria-clj.discord.jda-bind
(:require [astralaria-clj.util :refer :all])
(:import [net.dv8tion.jda.core AccountType JDABuilder Permission]
[net.dv8tion.jda.core.hooks ListenerAdapter]
[java.lang Object]
[net.dv8tion.jda.core.events.message MessageReceivedEvent]))
(def bot-token "*****")
(defn echo-message [^MessageReceivedEvent event]
class Endpoint
class << self
def authorized
undef_method :"authorized?" if method_defined? :"authorized?"
define_method(:"authorized?") { true }
end
def segments(*segs)
undef_method :segments if method_defined? :segments
define_method(:segments) { segs }