Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
@fogus
fogus / mbpew.clj
Last active October 30, 2025 16:28
(defn eval-expr [expr env]
(cond (symbol? expr) (env expr)
(and (seq? expr) (= 'lambda (first expr)))
(let [[_ [a] body] expr]
(fn [arg]
(eval-expr body (fn [x] (if (= a x)
arg
(env x))))))
@fogus
fogus / tester.java
Last active October 28, 2025 19:41
package fogus.rete;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.lang.ref.WeakReference;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadFactory;
public class Tester {
You are ChatGPT, a large language model based on the GPT-5 model and trained by OpenAI.
Knowledge cutoff: 2024-06
Current date: 2025-08-08
Image input capabilities: Enabled
Personality: v2
Do not reproduce song lyrics or any other copyrighted material, even if asked.
You're an insightful, encouraging assistant who combines meticulous clarity with genuine enthusiasm and gentle humor.
Supportive thoroughness: Patiently explain complex topics clearly and comprehensively.
Lighthearted interactions: Maintain friendly tone with subtle humor and warmth.
(defn dynamic-require [& args]
(let [p (promise)
n *ns*]
(.start
(Thread.
(fn [] (deliver p (binding [*ns* n] (apply require args))))))
@p))
@fogus
fogus / ap.md
Last active May 13, 2025 17:43

Arities as pseudo-protocol

Recently the Clojure team released an alpha version of the core.async library that includes a new library named Flow. While the new functionality is amazing and is already inspiring devs to use it, this post is not about Flow. Instead, I'd like to talk about a small part of the Flow API where process behavior is implemented in terms of step-fns. Simply put, step-fns are functions of four arities, where each arity is called at key points in the life-cycle of a process to provide configuration information or perform behaviors.

The four arities are as follows:

  1. Describe the step-fn by returning a data-structure describing its boundaries
  2. Returns the initialization state for the enclosing process given compatible arguments
  3. Called every time a life-cycle transition occurs with a state and transition key and returns an updated state
  4. Called in a loop for every mes
; Stumbling towards Y
;
; The applicative-order Y combinator is a function that allows one
; to create a recursive function without using define.
; This may seem strange. Usually a recursive function has to call
; itself, and thus relies on itself having been defined.
;
; Regardless, here we will stumble towards the implementation of the
; Y combinator (in Scheme).
@fogus
fogus / d6.clj
Last active April 7, 2025 15:08
(defn range-3d6
"A function to return the possible rolls with 3d6 between start and end inclusive."
([n] (list n))
([start end]
(for [d100s (range 1 7)
d10s (range 1 7)
d1s (range 1 7)
:let [num (+ (* 100 d100s) (* 10 d10s) d1s)]
:when (and (<= start num) (<= num end))]
num)))
:async-259
(System/setProperty "clojure.core.async.go-checking" "true")
(Boolean/getBoolean "clojure.core.async.go-checking")
(require '[clojure.core.async :as async])
(require '[clojure.core.async.impl.dispatch :as d])
@#'clojure.core.async.impl.go/go-checking
(let [c (async/chan 1)]
A
B
C
D
E
F
G
H
I
J
(ns fogus.vthreads
(:require [clojure.core.async :as ca]))
(set! *warn-on-reflection* true)
ca/io-thread-exec
(let [c (ca/chan)]
(ca/io-thread (ca/>!! c "hello"))
(assert (= "hello" (ca/<!! (ca/io-thread (ca/<!! c)))))