2017-08-27

(sph one)

example implementations of various procedures

part of sph-lib

bindings

import name

(sph one)

exports

begin-first

syntax

signature

result expression ...

call-at-approximated-interval

procedure

signature

proc min-interval max-interval [change-factor-slower change-factor-faster] state ... ->

{states ... -> integer} microseconds microseconds rational rational any ... ->

description

like call-at-interval-w-state but without a continue procedure, automatically adjusting interval after each application of proc

depending on the result of proc: -1 increases the interval, 1 decreases it and 0 does not change it.

call-at-interval

procedure

signature

proc interval ->

procedure:{current-interval procedure:continue:{next-interval -> any} -> any} microseconds -> unspecified

description

call proc after interval of length interval. proc receives the current interval and a procedure to

continue, with the option to change the interval

call-at-interval-w-state

procedure

signature

proc interval init ... ->

description

procedure:{current-interval continue any ...} microseconds any ...

like call-at-interval but accepting unlimited number of additional parameters

that are passed to proc and the continue procedure.

cli-option

procedure

signature

name [value] ->

description

creates a string for one generic command-line option in the gnu format -{single-character} or --{word} or --{word}=.

optionally with values.

"name"can be a:

character: short option

string: long option

value can be anything, non-strings will be converted to strings in "display" format

cli-option-join

procedure

signature

options ->

((name value ...)/string ...) -> (string ...)

(("a" 3)) -> -a 3

(("abc" 3)) -> --abc 3

description

creates a command-line options string, automatically appending - or -- to option names.

- pairs with prefixes that are characters or single char strings become single char options

- pairs with prefixes that are multi char strings become multi char options

- the tail of pairs is string-joined with spaces and used as the value for the option

- strings become keyless arguments

each-integer

procedure

signature

count proc ->

integer procedure:{integer ->} ->

description

call proc "count" times

guile-exception->key

procedure

signature

proc ->

procedure -> procedure

description

guard catches guile exceptions, but it seems impossible to get the key

ignore

procedure

signature

a ... ->

any ... -> unspecified

description

ignores all arguments and returns unspecified

pass

procedure

signature

proc obj ->

procedure any -> any

description

apply proc with obj, return obj.

example

(+ 2 (pass write (+ 1 3)))

writes 4 to standard output

results in 6

procedure->cached-procedure

procedure

signature

proc ->

procedure -> procedure procedure

description

returns a new procedure with the same signature that calculates each result only once.

calling the procedure again with the same arguments will lead to the cached result to be returned.

the second returned procedure takes no arguments and clears the cache when called.

example 1:

(define my-calculate-cached (procedure->cached-procedure my-calculate))

example 2:

(let-values (((my-calculate-cached my-calculate-cached-reset) (procedure->cached-procedure my-calculate)))

(my-calculate-cached-reset))

procedure->temporarily-cached-procedure

procedure

signature

cache-duration proc ->

integer:seconds procedure -> procedure

like procedure ->

description

cached-procedure but the cache is emptied after cache-duration the next time the procedure is called

procedure-append

procedure

signature

proc ... ->

procedure ... -> procedure:{any ... -> (any ...)}

description

creates a new procedure that applies each appended procedure with given arguments

and returns the results of each call in a list

procedure-append*

procedure

signature

proc ... ->

procedure ... -> procedure:{any ... -> unspecified}

description

like procedure-append but procedure call results must be lists

which are appended

procedure-append-ignore-result

procedure

signature

proc ... ->

procedure ... -> procedure:{any ... -> unspecified}

description

like procedure-append but does not collect results and returns unspecified

procedure-cond

syntax

signature

a (predicate handler) ... else

program-name

procedure

signature

->

-> string

description

return the file-name of the currently executed program file. uses the first argument of (program-arguments)

program-path

procedure

signature

->

-> string

description

return the full-path of the currently executed program file. uses the first argument of (program-arguments)

remove-keyword-associations

procedure

signature

a ->

list -> list

description

removes keyword associations from an argument list passed for example to lamdba*

(3 #:a 1 2 #:b 4) -> (3 2)

rnrs-exception->key

procedure

signature

proc [return-object?] ->

procedure [boolean] -> symbol

description

wraps the given procedure so that when called and an exception occurs in it,

the exception is catched and if the exception object passed to raise is a symbol or list

with a symbol as the first argument, the symbol is returned. otherwise the exception

is re-raised or the object returned, depending on the boolean value of the second argument "return-object?"

rnrs-exception->object

procedure

signature

proc ->

procedure -> procedure

description

wraps the given procedure so that when called and an exception occurs in it,

the exception is catched and the object passed to raise is returned

search-env-path

procedure

signature

a ->

(string ...) -> (string ...)

description

search for any match of paths "a" in the directories in the PATH environment variable and result in the full path.

similar to guiles %search-load-path but does not consider filename extensions

search-env-path-one

procedure

signature

a ->

socket-bind

procedure

signature

a b [c] d ... ->

sph-one-description

variable

values->list

syntax

signature

producer


tags: programming guile documentation library scheme sph-lib sph-one