(examples-for pp/breaker ("breaks 'if forms" (pp/breaker '(if a b c d e)) ((if a) (b) (c) (d) (e))) ("breaks 'let forms" (pp/breaker '(let a b c d)) ((let a b) (c) (d))) ("breaks 'def forms" (pp/breaker '(def yoyo (x y) a b)) ((def yoyo (x y)) (a) (b)))) (examples-for pp/dotify ("nothing" (pp/dotify nil) nil) ("atom" (inspect:pp/dotify 'a) "a") ("plain list" (inspect:pp/dotify '(a b c)) "(a b c)") ("dotted list" (map inspect (pp/dotify '(a b c . d))) ("a" "b" "c" "." "d")) ("nested dotted list" (inspect:pp/dotify '(def foo (a b c . d) (a (fn (x y . z) (d z) )))) "(def foo (a b c . d) (a (fn (x y . z) (d z))))")) (examples-for pp/indent ("nothing" (pp/indent nil (list " ")) (" ")) ("number" (pp/indent 22 (list " ")) (" " " ")) ("string" (pp/indent "forty-two" (list " ")) (" " " ")) ("symbol" (pp/indent 'forty-two (list " ")) (" " " ")) ("list" (pp/indent '(fn (x) (blow x)) (list " ")) (" "))) (examples-for pp/cleanup ("empty" (pp/cleanup "") "") ("atom" (pp/cleanup "foo") "foo") ("already clean" (pp/cleanup "foo\nbar") "foo bar") ("removes trailing whitespace on each line" (pp/cleanup "foo \nbar \ntoto ") "foo bar toto") ("removes trailing whitespace on each line but preserves leading whitespace" (pp/cleanup "foo \n bar \n toto ") "foo bar toto")) (examples-for pp/unsyntax ("nil" (to-string:pp/unsyntax nil) "") ("atom" (to-string:pp/unsyntax 42) "42") ("list" (to-string:pp/unsyntax '(for a 1 10 (p 'hello 'world))) "(for a 1 10 (p 'hello 'world))") ("list with embedded syntax" (to-string:pp/unsyntax '(for (colon-syntax a b) 1 10 ((dot-syntax p q) 'hello 'world))) "(for a:b 1 10 (p.q 'hello 'world))") ("percent-syntax" (to-string:pp/unsyntax '(percent-syntax this that)) "this%that") ("prefix percent-syntax" (to-string:pp/unsyntax '(percent-syntax || that)) "%that") ("postfix percent-syntax" (to-string:pp/unsyntax '(percent-syntax this ||)) "this%") ("postfix multiple percent-syntax" (to-string:pp/unsyntax '(percent-syntax this that || another)) "this%that%%another") ("nested syntax" (to-string:pp/unsyntax '(percent-syntax this (ampersand-syntax x y) that)) "this%x&y%that")) (examples-for pp/split-form ("first item" (pp/split-form '(a b c d) 1) ((a) (b) (c) (d))) ("first two items" (pp/split-form '(a b c d e) 2) ((a b) (c) (d) (e))) ("first three items" (pp/split-form '(a b c d e f) 3) ((a b c) (d) (e) (f)))) (examples-for pp/flatly ("nil" (pp/flatly nil) "nil") ("number" (pp/flatly 22) "22") ("symbol" (pp/flatly 'qwerty) "qwerty") ("list" (pp/flatly '(a b c d 21 22 23 'quoting) ) "(a b c d 21 22 23 'quoting)") ("macro example" (pp/flatly '(mac johnny (foo bar) `(this ,foo ,@(map twisty bar)))) "(mac johnny (foo bar) `(this ,foo ,@(map twisty bar)))")) (examples-for pp ("a quote" (pp '(quote a)) "'a") ("unquote" (pp '(unquote a)) ",a") ("unquote-splicing" (pp '(unquote-splicing a)) ",@a") ("quasiquote" (pp '(quasiquote a)) "`a") ("quote unquote" (pp '(quote (unquote a))) "',a") ("a macro invocation" (pp '(mac pp/def (name args . body) `(hash-set pp/special-forms ',name (fn ,args ,@body)))) "(mac pp/def (name args . body) `(hash-set pp/special-forms ',name (fn ,args ,@body)))") ("a 'def invocation" (pp '(def pp (form) (pp/main form 0))) "(def pp (form) (pp/main form 0))") ("a longer 'def invocation" (pp '(def pp (form) (pp/main form 0) (pp/again form 1) (pp/more (jump:skip form) 2))) "(def pp (form) (pp/main form 0) (pp/again form 1) (pp/more (jump:skip form) 2))") ("a 'def with a dotted argument list" (pp '(def afun (a b c . others) (afun a b c (a (car others) (b (cdr others)))))) "(def afun (a b c . others) (afun a b c (a (car others) (b (cdr others)))))") ("something with a plain string literal" (pp '(def yoohoo (it) (wrangle "foobar" it))) "(def yoohoo (it) (wrangle \"foobar\" it))") ("something with a nil and t literal" (pp '(def yoohoo (it) (wrangle nil t it))) "(def yoohoo (it) (wrangle nil t it))") ("a 'let form squished into one line" (pp '(let acc nil (rfnwith flattenize (x things) (if (pair? x) (eachr flattenize x) (push x acc))) acc)) "(let acc nil (rfnwith flattenize (x things) (if (pair? x) (eachr flattenize x) (push x acc))) acc)") ("a real-life example from utils with improper 'if formatting" (pp '(def flatten (things) (let acc nil (rfnwith flattenize (x things) (if (pair? x) (eachr flattenize x) (push x acc))) acc))) "(def flatten (things) (let acc nil (rfnwith flattenize (x things) (if (pair? x) (eachr flattenize x) (push x acc))) acc))") ("a real-life example from utils" (pp '(def list-slices (things slice-size) ; slice 'things into a list of lists each with maximum 'slice-size items (chapter pagination list-management) (if (< (len things) slice-size) (cons things nil) (cons (firstn slice-size things) (list-slices (nthcdr slice-size things) slice-size))))) "(def list-slices (things slice-size) ; slice 'things into a list of lists each with maximum 'slice-size items (chapter pagination list-management) (if (< (len things) slice-size) (cons things nil) (cons (firstn slice-size things) (list-slices (nthcdr slice-size things) slice-size))))") ("a real-life example from test-runner" (pp '(def run-all-tests (verbose) ; runs all tests that have been registered with 'register-test (with (passed 0 failed 0) (with (f-pass (fn nil (assign passed (+ 1 passed))) f-fail (fn nil (assign failed (+ 1 failed)))) (run-tests `(suite "all tests" ,@all-tests) f-pass f-fail verbose) (p "passed: " passed) (p "failed: " failed) (/ passed (+ passed failed)))))) "(def run-all-tests (verbose) ; runs all tests that have been registered with 'register-test (with (passed 0 failed 0) (with (f-pass (fn nil (assign passed (+ 1 passed))) f-fail (fn nil (assign failed (+ 1 failed)))) (run-tests `(suite \"all tests\" ,@all-tests) f-pass f-fail verbose) (p \"passed: \" passed) (p \"failed: \" failed) (/ passed (+ passed failed)))))") ("special syntax" (pp '(string-pieces "hello " (bang-syntax || (dot-syntax x y (ampersand-syntax foo bar))) " and welcome to " (prefix-list "%%" (a b c d)) " and friends!")) "\"hello ~~|!x.y.foo&bar| and welcome to ~~%%(a b c d) and friends!\"") ("percent-syntax" (pp '(percent-syntax || (dot-syntax x y))) "%x.y") ("percent-syntax with args" (pp '(%tr.klakla (%td:otherkla:joinstr ", " (map &firstname ppl)) (%td:otherkla:joinstr ", " (map &email ppl)))) "(%tr.klakla (%td:otherkla:joinstr \", \" (map &firstname ppl)) (%td:otherkla:joinstr \", \" (map &email ppl)))") ("brace list" (pp '(let hello {a 1 b "two" c 'three d ,four e (sub invocation) f {sub brace list here} })) "(let hello { a 1 b \"two\" c 'three d ,four e (sub invocation) f { sub brace list here } })"))