(html (head (title "sph-lib (sph other)") (link (@ (rel "stylesheet") (type "text/css") (href "/css/sph.css"))) (meta (@ (name "viewport") (content "width=device-width,initial-scale=1"))) #f) (body () (div (@ (class top)) (nav (a (@ (href "/")) "start") ", " (a (@ (href "/feed.xml")) "feed")) "") (div (@ (class "middle")) (div (@ (class mtime) (title "last modification time of the current page")) "2023-04-05") (section (h1 "(sph other)") (div (p "miscellaneous.") (p "part of " (a (@ (href "../../sph-lib.html")) "sph-lib")) ((section (@ (class "library-description")) (h1 "library description") (div (p "# syntax") (p "define-as") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "example: (define-as list 1 2 3)")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "example: (define-as (quasiquote list) 1 (unquote 3))")) (p "compose-s") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "(compose-s a (list 1 2)) -> (a (list 1 2))")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "(compose-s (a b) (list 1 2)) -> (a (b (list 1 2)))")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "it does not fail in the case (_ (quasiquote list) expr ...)")) (p "begin-first :: result expression ...") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "like begin but returns the result of the first expression instead of the last one")) (p "identity-if :: result-if-true else ...") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "give the result of result-if-true, otherwise execute else")) (p "procedure-cond :: a (predicate handler) ... else") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "similar to \"cond\" but with procedures for predicate and handler.")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "passes the result to predicate, and if it evaluates to true then it passes the result to handler and the result")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "will be the result of handler. if predicate evaluates to false, the next predicate is checked.")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "if no predicate matches, the result of procedure-cond is the result of the last expression")) (p "values->list :: producer") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "converts multiple values to a list.")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "example: (values->list (values 1 2 3)) -> (1 2 3)")) (p "if-pass") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "any procedure:{any -> any} -> any")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "call proc with \"a\" if \"a\" is a true value, otherwise return false or evaluate else.")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "also known as \"and=>\"")) (p "if-pass-apply") (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "list procedure:{any ... -> any} -> any")) (p (((*ENTITY* "nbsp") (*ENTITY* "nbsp")) "like if-pass but uses apply to use the contents of \"a\", which should be a list in the true case, as arguments to proc")))) (section (@ (class "library-name")) (h1 "module name") (p "(sph other)")) (section (@ (class "library-exports")) (h1 "exported bindings") (div (div (@ (class "doc-bindings")) (div (@ (id "doc-b-" "begin-first") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "begin-first") " " (span (@ (class "first-sig")) "result expression ...")) "" "") (div (@ (id "doc-b-" "boolean->integer") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "boolean->integer") " " (span (@ (class "first-sig")) "a ->")) "" "") (div (@ (id "doc-b-" "boolean-true?") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "boolean-true?") " " (span (@ (class "first-sig")) "a ...")) "" "") (div (@ (id "doc-b-" "call-at-approximated-interval") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "call-at-approximated-interval") " " (span (@ (class "first-sig")) "proc min-interval max-interval [change-factor-slower change-factor-faster] state ... ->")) (div (@ (class "rest-sig")) (div "{states ... -> integer} microseconds microseconds rational rational any ... ->")) (div (@ (class "description")) (("like call-at-interval-w-state but without a continue procedure, automatically adjusting interval after each application of proc" (br) "depending on the result of proc: -1 increases the interval, 1 decreases it and 0 does not change it.")))) (div (@ (id "doc-b-" "call-at-interval") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "call-at-interval") " " (span (@ (class "first-sig")) "proc interval ->")) (div (@ (class "rest-sig")) (div "procedure:{current-interval procedure:continue:{next-interval -> any} -> any} microseconds -> unspecified")) (div (@ (class "description")) (("call proc after interval of length interval. proc receives the current interval and a procedure to" (br) "continue, with the option to change the interval")))) (div (@ (id "doc-b-" "call-at-interval-w-state") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "call-at-interval-w-state") " " (span (@ (class "first-sig")) "proc interval init ... ->")) "" (div (@ (class "description")) (("procedure:{current-interval continue any ...} microseconds any ..." (br) "like call-at-interval but accepting unlimited number of additional parameters" (br) "that are passed to proc and the continue procedure.")))) (div (@ (id "doc-b-" "char-set->vector") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "char-set->vector") " " (span (@ (class "first-sig")) "a ->")) "" "") (div (@ (id "doc-b-" "cli-option") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "cli-option") " " (span (@ (class "first-sig")) "name [value] ->")) "" (div (@ (class "description")) (("creates a string for one generic command-line option in the gnu format -{single-character} or --{word} or --{word}=." (br) "optionally with values." (br) "\\\"name\\\"can be a:" (br) "character: short option" (br) "string: long option" (br) "value can be anything, non-strings will be converted to strings in \\\"display\\\" format")))) (div (@ (id "doc-b-" "cli-option-join") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "cli-option-join") " " (span (@ (class "first-sig")) "options ->")) (div (@ (class "rest-sig")) (div "((name value ...)/string ...) -> (string ...)") (div "((\"a\" 3)) -> -a 3") (div "((\"abc\" 3)) -> --abc 3")) (div (@ (class "description")) (("creates a command-line options string, automatically appending - or -- to option names." (br) "- pairs with prefixes that are characters or single char strings become single char options" (br) "- pairs with prefixes that are multi char strings become multi char options" (br) "- the tail of pairs is string-joined with spaces and used as the value for the option" (br) "- strings become keyless arguments")))) (div (@ (id "doc-b-" "each-integer") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "each-integer") " " (span (@ (class "first-sig")) "count proc [start] ->")) (div (@ (class "rest-sig")) (div "integer procedure:{integer ->} ->")) (div (@ (class "description")) (("call proc \\\"count\\\" times")))) (div (@ (id "doc-b-" "false-if") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "false-if") " " (span (@ (class "first-sig")) "test consequent")) "" (div (@ (class "description")) (("result in false if \\\"test\\\" is true, otherwise execute consequent")))) (div (@ (id "doc-b-" "false-if-not") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "false-if-not") " " (span (@ (class "first-sig")) "test consequent")) "" (div (@ (class "description")) (("execute consequent if \\\"test\\\" is true, otherwise result in false")))) (div (@ (id "doc-b-" "guile-exception->key") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "guile-exception->key") " " (span (@ (class "first-sig")) "proc ->")) (div (@ (class "rest-sig")) (div "procedure -> procedure")) (div (@ (class "description")) (("guard catches guile exceptions, but it seems impossible to get the key")))) (div (@ (id "doc-b-" "identity-if") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "identity-if") " " (span (@ (class "first-sig")) "result-if-true else ...")) "" "") (div (@ (id "doc-b-" "if-pass") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "if-pass") " " (span (@ (class "first-sig")) "a consequent alternative")) "" "") (div (@ (id "doc-b-" "if-pass-apply") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "if-pass-apply") " " (span (@ (class "first-sig")) "a consequent alternative")) "" "") (div (@ (id "doc-b-" "if-predicate-and") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "if-predicate-and") " " (span (@ (class "first-sig")) "(predicate ...) subject consequent alternative")) "" "") (div (@ (id "doc-b-" "if-predicate-or") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "if-predicate-or") " " (span (@ (class "first-sig")) "(predicate ...) subject consequent alternative")) "" "") (div (@ (id "doc-b-" "ignore") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "ignore") " " (span (@ (class "first-sig")) "a ... ->")) (div (@ (class "rest-sig")) (div "any ... -> unspecified")) (div (@ (class "description")) (("ignores all arguments and returns unspecified")))) (div (@ (id "doc-b-" "pass") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "pass") " " (span (@ (class "first-sig")) "proc obj ->")) (div (@ (class "rest-sig")) (div "procedure any -> any")) (div (@ (class "description")) (("apply proc with obj, return obj." (br) "example" (br) "(+ 2 (pass write (+ 1 3)))" (br) "writes 4 to standard output" (br) "results in 6")))) (div (@ (id "doc-b-" "pass-predicate-and-if") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "pass-predicate-and-if") " " (span (@ (class "first-sig")) "predicates subject consequent alternative ->")) "" (div (@ (class "description")) (("(procedure ...) any procedure:{any:subject -> any} procedure:{any:subject -> any}")))) (div (@ (id "doc-b-" "pass-predicate-or-if") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "pass-predicate-or-if") " " (span (@ (class "first-sig")) "predicates subject consequent alternative ->")) "" (div (@ (class "description")) (("any/(procedure:{any:subject -> any} ...) any procedure:{any:subject -> any} procedure:{any:subject -> any}")))) (div (@ (id "doc-b-" "predicate-and") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "predicate-and") " " (span (@ (class "first-sig")) "predicates subjects ... ->")) (div (@ (class "rest-sig")) (div "any/(procedure:{any:subject -> any} ...) any ... -> boolean")) (div (@ (class "description")) (("true if every predicate gives true for every subject, false otherwise")))) (div (@ (id "doc-b-" "predicate-or") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "predicate-or") " " (span (@ (class "first-sig")) "predicates subjects ... ->")) (div (@ (class "rest-sig")) (div "any/(procedure:{any:subject -> any} ...) any ... -> boolean")) (div (@ (class "description")) (("true if every predicate gives true for every subject, false otherwise")))) (div (@ (id "doc-b-" "procedure->cached-procedure") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "procedure->cached-procedure") " " (span (@ (class "first-sig")) "proc [key-f] ->")) (div (@ (class "rest-sig")) (div "procedure -> procedure procedure")) (div (@ (class "description")) (("returns a new procedure with the same signature that calculates each result only once." (br) "calling the procedure again with the same arguments will lead to the cached result to be returned." (br) "the second returned procedure takes no arguments and clears the cache when called." (br) "example 1:" (br) " (define my-calculate-cached (procedure->cached-procedure my-calculate))" (br) "example 2:" (br) " (let-values (((my-calculate-cached my-calculate-cached-reset) (procedure->cached-procedure my-calculate)))" (br) " (my-calculate-cached-reset))")))) (div (@ (id "doc-b-" "procedure->temporarily-cached-procedure") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "procedure->temporarily-cached-procedure") " " (span (@ (class "first-sig")) "cache-duration proc ->")) (div (@ (class "rest-sig")) (div "integer:seconds procedure -> procedure") (div "like procedure ->")) (div (@ (class "description")) (("cached-procedure but the cache is emptied after cache-duration the next time the procedure is called")))) (div (@ (id "doc-b-" "procedure-append") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "procedure-append") " " (span (@ (class "first-sig")) "proc ... ->")) (div (@ (class "rest-sig")) (div "procedure ... -> procedure:{any ... -> (any ...)}")) (div (@ (class "description")) (("creates a new procedure that applies each appended procedure with given arguments" (br) "and returns the results of each call in a list")))) (div (@ (id "doc-b-" "procedure-append*") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "procedure-append*") " " (span (@ (class "first-sig")) "proc ... ->")) (div (@ (class "rest-sig")) (div "procedure ... -> procedure:{any ... -> unspecified}")) (div (@ (class "description")) (("like procedure-append but procedure call results must be lists" (br) "which are appended")))) (div (@ (id "doc-b-" "procedure-append-ignore-result") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "procedure-append-ignore-result") " " (span (@ (class "first-sig")) "proc ... ->")) (div (@ (class "rest-sig")) (div "procedure ... -> procedure:{any ... -> unspecified}")) (div (@ (class "description")) (("like procedure-append but does not collect results and returns unspecified")))) (div (@ (id "doc-b-" "procedure-cond") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "procedure-cond") " " (span (@ (class "first-sig")) "a (predicate handler) ... else")) "" (div (@ (class "description")) (("should probably have an else keyword case instead of returning the last expression")))) (div (@ (id "doc-b-" "program-name") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "program-name") " " (span (@ (class "first-sig")) " ->")) (div (@ (class "rest-sig")) (div "-> string")) (div (@ (class "description")) (("return the file-name of the currently executed program file. uses the first argument of (program-arguments)")))) (div (@ (id "doc-b-" "program-path") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "program-path") " " (span (@ (class "first-sig")) " ->")) (div (@ (class "rest-sig")) (div "-> string")) (div (@ (class "description")) (("return the full-path of the currently executed program file. uses the first argument of (program-arguments)")))) (div (@ (id "doc-b-" "random-ascii-string") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "random-ascii-string") " " (span (@ (class "first-sig")) "len ->")) (div (@ (class "rest-sig")) (div "integer -> string")) (div (@ (class "description")) (("results in a string of randomly chosen ascii characters excluding control characters")))) (div (@ (id "doc-b-" "random-between") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "random-between") " " (span (@ (class "first-sig")) "min max ->")) "" "") (div (@ (id "doc-b-" "random-boolean") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "random-boolean") " " (span (@ (class "first-sig")) "[percentage] ->")) (div (@ (class "rest-sig")) (div "[integer] -> boolean")) (div (@ (class "description")) (("percentage gives the probability of true results")))) (div (@ (id "doc-b-" "random-bytevector") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "random-bytevector") " " (span (@ (class "first-sig")) "size ->")) (div (@ (class "rest-sig")) (div "integer -> bytevector")) "") (div (@ (id "doc-b-" "random-chars") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "random-chars") " " (span (@ (class "first-sig")) "list-length [char-set state] ->")) (div (@ (class "rest-sig")) (div "integer string/vector random-state -> (character ...)")) (div (@ (class "description")) (("creates a list of random chars from a set of characters." (br) "the default set of characters includes all the code points to which unicode has assigned a character or other meaning")))) (div (@ (id "doc-b-" "random-discrete-f") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "random-discrete-f") " " (span (@ (class "first-sig")) "probabilities [state] ->")) (div (@ (class "rest-sig")) (div "(real ...) [random-state] -> procedure:{ -> real}")) (div (@ (class "description")) (("return a function that when called returns an index of a" (br) "value in probabilities." (br) "each index will be returned with a probability given by the value at the index." (br) "each value is a fraction of the sum of probabilities." (br) "for example, if the values sum to 100, each entry in probabilities is a percentage." (br) "this allows for custom discrete random probability distributions." (br) "example usage:" (br) "(define random* (random-discrete-f (list 10 70 20)))" (br) "(define samples (list (random*) (random*)))")))) (div (@ (id "doc-b-" "random-string") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "random-string") " " (span (@ (class "first-sig")) "[len char-set state] ->")) (div (@ (class "rest-sig")) (div "[integer string/vector] -> string")) (div (@ (class "description")) (("the default set of characters includes all the code points to which unicode has assigned a character or other meaning")))) (div (@ (id "doc-b-" "remove-keyword-associations") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "remove-keyword-associations") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "list -> list")) (div (@ (class "description")) (("removes keyword associations from an argument list passed for example to lamdba*" (br) "(3 #:a 1 2 #:b 4) -> (3 2)")))) (div (@ (id "doc-b-" "repeat") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "repeat") " " (span (@ (class "first-sig")) "f repeat-count state ->")) (div (@ (class "rest-sig")) (div "procedure:{ -> any} integer false/repeat-state:(any:last-result integer:count) -> (any:result integer:count)")) (div (@ (class "description")) (("f is called without arguments and generates new values that are returned again on subsequent calls for repeat-count times." (br) "returned is a new repeat state which is a list with as the first element the value returned by f." (br) "if state is false then a new state object will be created and returned")))) (div (@ (id "doc-b-" "rnrs-exception->key") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "rnrs-exception->key") " " (span (@ (class "first-sig")) "proc [return-object?] ->")) (div (@ (class "rest-sig")) (div "procedure [boolean] -> symbol")) (div (@ (class "description")) (("wraps the given procedure so that when called and an exception occurs in it," (br) "the exception is catched and if the exception object passed to raise is a symbol or list" (br) "with a symbol as the first argument, the symbol is returned. otherwise the exception" (br) "is re-raised or the object returned, depending on the boolean value of the second argument \\\"return-object?\\\"")))) (div (@ (id "doc-b-" "rnrs-exception->object") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "rnrs-exception->object") " " (span (@ (class "first-sig")) "proc ->")) (div (@ (class "rest-sig")) (div "procedure -> procedure")) (div (@ (class "description")) (("wraps the given procedure so that when called and an exception occurs in it," (br) "the exception is catched and the object passed to raise is returned")))) (div (@ (id "doc-b-" "search-env-path") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "search-env-path") " " (span (@ (class "first-sig")) "a ->")) (div (@ (class "rest-sig")) (div "(string ...) -> (string ...)")) (div (@ (class "description")) (("search for any match of paths \\\"a\\\" in the directories in the PATH environment variable and result in the full path." (br) "similar to guiles %search-load-path but does not consider filename extensions")))) (div (@ (id "doc-b-" "search-env-path-one") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "search-env-path-one") " " (span (@ (class "first-sig")) "a ->")) "" "") (div (@ (id "doc-b-" "socket-bind") (class "doc-b")) (div (span (@ (class "type")) "procedure") ": " (span (@ (class "name")) "socket-bind") " " (span (@ (class "first-sig")) "a b [c] d ... ->")) "" "") (div (@ (id "doc-b-" "sph-other-description") (class "doc-b")) (div (span (@ (class "type")) "variable") ": " (span (@ (class "name")) "sph-other-description")) "" "") (div (@ (id "doc-b-" "values->list") (class "doc-b")) (div (span (@ (class "type")) "syntax") ": " (span (@ (class "name")) "values->list") " " (span (@ (class "first-sig")) "producer")) "" "")))))))) ()))