This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
NewerOlder