Skip to content

Instantly share code, notes, and snippets.

#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]
L=11
@field = Array.new(32*32) {0}
@vecs = [[1,0], [0,-1], [-1,0], [0,1]]
def fld(x,y) @field[y*32+x] end
def set(x,y,v) @field[y*32+x] = v end
def step(x, y, ang)
vx,vy = @vecs[ang & 3]
return x+vx, y+vy
end
import Text.Read
import Data.Foldable
sampleData =
[
["10", "20", "30"],
["0", "1", "aa", "2"],
["0", "eheh", "1", "bb", "2"],
["2", "really", "bad"],
["3", "4", "5"]
@thedeemon
thedeemon / eu300.d
Last active February 21, 2021 18:14
import std.stdio, std.parallelism, std.range, std.algorithm;
enum L = 12;
struct V {int x,y;}
int optLen(int seed) {
int[32*32] field;
V[4] vecs = [V(1,0), V(0,-1), V(-1,0), V(0,1)];
V[L] path;
@thedeemon
thedeemon / liev.d
Last active November 22, 2020 19:54
A test of @LiVe in D
// dmd -preview=dip1021 liev.d
import std.stdio;
struct S { string name; }
@live void use(scope const S* p) { // ok
writeln(p.name);
}
void release(S *p) { } // consumes the ownership
@thedeemon
thedeemon / dn.d
Last active April 20, 2020 09:35
import std.stdio;
// secret sauce: https://dlang.org/spec/class.html#alias-this
struct DayNum {
int dn;
alias dn this; // this line makes DayNum look like an int with dn as the value
}
DayNum next(DayNum d) {