Up: API  


1.1 (kracht prelude)

1.1.1 Macros

Macro: evaluate-thunks x

Given a list of functions that don’t take any inputs, run each one of those functions and return a list of what each function returned.

1.1.2 Procedures

Procedure: alist-from-url-encoded-body body

Parse a URL-encoded bytevector HTTP BODY into an association list of key-value strings.

Procedure: alist? obj

Return #t if OBJ is a valid association list (a list where every element is a pair), otherwise return #f.

Procedure: assoc-lens xs keys

Deeply look up a value within nested association lists XS by traversing the sequence of KEYS sequentially.

Procedure: assoc-ref-or-empty-str alist field

Look up FIELD in ALIST. Return the associated value if found, or an empty string "" if the field does not exist or matches #f.

Procedure: base64-decode s

Decode base64 encoded string S back into its raw string format by system execution. Trims trailing right whitespaces from output.

Procedure: base64-encode s

Encode string S into a base64 string without line wrapping by system execution.

Procedure: build-asset-library files

Asset library is an in-memory cache, a lookup dictionary that can be used for faster performance, memoization, etc. This version will read from a list of files specified with the FILES param.

To use it, you can simply call the function with a list of file paths.

Procedure: empty-string? s

Return #t if S is exactly the empty string "".

Procedure: flatten-list xs

Recursively flatten a nested list structure XS into a flat, one-dimensional list.

Procedure: fold kons knil list1

Apply PROC to the elements of LIST1 ... LISTN to build a result, and return that result. See the manual for details.

Procedure: fold-right kons knil clist1 . rest

Undocumented procedure.

Procedure: get-short-commit-sha

Retrieve the short Git commit SHA (7 characters) of the current repository state.

Procedure: get-string-all port

Undocumented procedure.

Procedure: getenv-or var KEY: #:default

Get env VAR or return a DEFAULT value.

Procedure: html-escape x

Replace special or non-ASCII characters in string X with their HTML entity equivalents.

Procedure: html-unescape x

Convert HTML entities inside string X back into their original character equivalents.

Procedure: non-empty-string? s

Return #t if S is a valid string and not equal to "", otherwise return #f.

Procedure: open-input-output-pipe command

Equivalent to open-pipe with mode OPEN_BOTH

Procedure: open-input-pipe command

Equivalent to open-pipe with mode OPEN_READ

Procedure: pair->sql-assignment a

Convert a key-value pair A into a SQL assignment clause string formatted as "column_name = value".

The key symbol is mapped via ‘symbol->sql-column‘. Booleans are converted to 1 or 0, numbers are unquoted, and all other types are single-quoted.

Procedure: shuffle-fy xs

Returns a randomly shuffled copy of XS. List shuffle which implements the modern Fisher-Yates shuffle algorithm. It converts the list to a vector for efficient O(1) random access and mutation, shuffles the vector in-place, and then converts it back to a list.

Procedure: sql-column->symbol x

Convert SQL column name string X into a Scheme symbol by replacing underscores with hyphens.

Procedure: sql-row->scheme-alist xs

Transform a SQL row representation XS into a Scheme-idiomatic association list. If XS is an alist, it converts its column keys into hyphenated Scheme symbols. If XS is not an alist, it returns XS unaltered.

Procedure: string->utf8 _

Undocumented procedure.

Procedure: string-drop-first-last s

Return a substring of S with its first and last characters removed. If the string length is 2 or less, returns S unaltered.

Procedure: string-drop-first-last-line s

Split string S by newlines, remove its first and last lines, and rejoin the remaining lines with newlines.

Procedure: string-drop-first-last-n s n

Return a substring of S with the first N characters and the final 1 character removed. If the string length is 2 or less, returns S unaltered.

Procedure: string-replace-substring str substring replacement

Return a new string where every instance of substring in string str has been replaced by replacement. For example:

(string-replace-substring "a ring of strings" "ring" "rut")
⇒ "a rut of struts"
Procedure: symbol->sql-column x

Convert Scheme symbol X into a SQL column name string by replacing hyphens with underscores.

Procedure: symbols->sql-columns-list xs

Convert a list of symbols XS into a single string of comma-separated SQL column names.

Procedure: syscall cmd

Execute system shell command CMD via an input pipe and return the captured standard output as a string.

Procedure: uri-decode str KEY: #:encoding #:decode-plus-to-space?

Percent-decode the given STR, according to ENCODING, which should be the name of a character encoding.

Note that this function should not generally be applied to a full URI string. For paths, use ‘split-and-decode-uri-path’ instead. For query strings, split the query on ‘&’ and ‘=’ boundaries, and decode the components separately.

Note also that percent-encoded strings encode _bytes_, not characters. There is no guarantee that a given byte sequence is a valid string encoding. Therefore this routine may signal an error if the decoded bytes are not valid for the given encoding. Pass ‘#f’ for ENCODING if you want decoded bytes as a bytevector directly. ‘set-port-encoding!’, for more information on character encodings.

If DECODE-PLUS-TO-SPACE? is true, which is the default, also replace instances of the plus character (+) with a space character. This is needed when parsing application/x-www-form-urlencoded data.

Returns a string of the decoded characters, or a bytevector if ENCODING was ‘#f’.

Procedure: uri-encode str KEY: #:encoding #:unescaped-chars

Percent-encode any character not in the character set, UNESCAPED-CHARS.

The default character set includes alphanumerics from ASCII, as well as the special characters ‘-’, ‘.’, ‘_’, and ‘~’. Any other character will be percent-encoded, by writing out the character to a bytevector within the given ENCODING, then encoding each byte as ‘%HH’, where HH is the uppercase hexadecimal representation of the byte.

Procedure: utf8->string _

Undocumented procedure.

Procedure: value->sql-literal a

Convert a Scheme value A into its raw SQL literal string representation. Numbers are kept raw, booleans are mapped to "1" or "0", and other types are wrapped in single quotes. You should escape single quotes if needed yourself.

Procedure: with-output-to-file file thunk KEY: #:binary #:encoding

THUNK must be a procedure of no arguments, and FILE must be a string naming a file. The effect is unspecified if the file already exists. The file is opened for output, an output port connected to it is made the default value returned by ‘current-output-port’, and the THUNK is called with no arguments. When the THUNK returns, the port is closed and the previous default is restored. Returns the values yielded by THUNK. If an escape procedure is used to escape from the continuation of these procedures, their behavior is implementation dependent.

Procedure: with-output-to-port port thunk

Undocumented procedure.

Procedure: with-output-to-string thunk

Calls THUNK and returns its output as a string.


Up: API