Skip to content

Instantly share code, notes, and snippets.

class Iterator it -> a {
next : it -> Maybe a
}
type IotaIter {
mut cur : Int
end : Int
}
instance Iterator IotaIter Int {
-- What works now as of June 1, 2025.
-- Comments start with -- and go until the end of line.
-- Any combination of +-*/<>=:%^&|!~$?# is an operator.
-- But these are part of language syntax: | => -> = :
-- Identifiers start with a lowercase letter and then may have
-- letter, digits, _ and ?.
// Integrate timelike geodesics in the equatorial plane (θ = π/2) of a Schwarzschild spacetime
// -----------------------------------------------------------------------------
// Units: c = G = 1. Mass M is given in the same geometric units (Schwarzschild radius r_s = 2M).
// Coordinates: (t, r, φ) with affine parameter λ.
// State vector y = (t, r, φ, 𝑡̇, ṙ, φ̇) where dots denote d/dλ.
// -----------------------------------------------------------------------------
import Foundation
/// Complete phase–space state of a particle on the geodesic
struct State {
import Foundation
// This program is mostly generated by ChatGPT o1 in a long conversation
// based on this PDF: https://arxiv.org/pdf/2206.12042
// "Experimental Demonstration of Quantum Pseudotelepathy"
struct Complex: CustomStringConvertible {
var re: Double
var im: Double
import Foundation
// MARK: — Complex number struct
struct Complex {
var re: Double
var im: Double
func conjugate() -> Complex {
Complex(re: re, im: -im)
#lang racket/base
(require racket/file racket/string)
(for ([fname (current-command-line-arguments)])
(displayln fname)
(define ls (file->lines fname))
(display-lines-to-file
(map (λ (s) (string-trim (string-replace s "\t" " ") " " #:left? #f #:repeat? #t)) ls)
fname #:exists 'replace))
import std.stdio, core.bitop, std.array, std.format, std.exception : enforce;
struct Entry(K,V) {
K key;
V value;
uint id;
}
enum maxShift = 25;
enum Ible[e] {
case MkIter(Int32, Int32 -> e)
}
instance Iterable[Ible] {
pub def iterator(rc: Region[r], s: Ible[a]): Iterator[a, r, r] \ r =
let Ible.MkIter(n, f) = s;
Iterator.range(rc, 0, n) |> Iterator.map(f)
}
#lang br
(require br-parser-tools/lex brag/support br/macro "grammar.rkt")
(define-lex-abbrev digits (:+ numeric))
(define-lex-abbrev reserved-terms
(:or "+" "-" "*" "/" "=" "in" ";" "{" "}" "(" ")" "," "=>" "if" "then" "else" "==" "<"))
(define (tokenize ip)
(port-count-lines! ip)
(define my-lexer
#lang brag
s-prog: s-stmt (/";" s-stmt)*
@s-stmt: s-assn | s-fundef | s-expr
s-funcall: NAME /"(" [s-expr (/"," s-expr)*] /")"
s-fundef: NAME /"(" [NAME (/"," NAME)* ] /")" "=>" s-expr
s-block: /"{" [s-stmt (/";" s-stmt)* /"in"] s-expr /"}"
s-assn: NAME /"=" s-expr
s-expr: s-compterm | if
if: /"if" s-expr /"then" s-expr /"else" s-expr
s-compterm: s-term [("<" | "==") s-term]