This unit contains a collection of useful utility definitions.
(chop '(1 2 3 4 5 6) 2) ==> ((1 2) (3 4) (5 6)) (chop '(a b c d) 3) ==> ((a b c) (d))
(define nums '(99 100 110 401 1234)) (compress (map odd? nums) nums) ==> (99 401)
(join '((a b) (c d) (e)) '(x y)) ==> (a b x y c d x y e) (join '((p q) () (r (s) t)) '(-)) ==> (p q - - r (s) t)
join could be implemented as follows:
(define (join lstoflsts . lst) (apply append (intersperse lstoflists (:optional lst '()))) )
~% | write newline character |
~S | write the next argument |
~A | display the next argument |
~n | skip all whitespace in the format-string until the next non-whitespace character |
~B | write the next argument as a binary number |
~O | write the next argument as an octal number |
~X | write the next argument as a hexadecimal number |
~C | write the next argument as a character |
~~ | display ' ' |
~! | flush all pending output |
~? | invoke formatted output routine recursively with the next two arguments as format-string and list of parameters |
For more powerful output formatting, see the section about the format unit.
(string-intersperse '("one" "two") "three")
is equivalent to
(apply string-append (intersperse '("one" "two") "three"))
(string-split "one two three") ==> ("one" "two" "three") (string-split "foo:bar::baz:" ":" #t) ==> ("foo" "bar" "" "baz" "")
(string-translate* "<h1>this is a \"string\"</h1>" '(("<" . "<:") (">" . ">") ("\"" . """)) ) ==> "<h1>this is a "string"</ht>"
(constantly X) <=> (lambda args X)
(complement PROC) <=> (lambda (x) (not (PROC x)))
(compose F G) <=> (lambda args (call-with-values (lambda () (apply G args)) F))
((conjoin odd? positive?) 33) ==> #t ((conjoin odd? positive?) -33) ==> #f
((disjoin odd? positive?) 32) ==> #t ((disjoin odd? positive?) -32) ==> #f
(flip PROC) <=> (lambda (x y) (PROC y x))
((list-of even?) '(1 2 3)) ==> #f ((list-of number?) '(1 2 3)) ==> #t