# Core functions

Functions not in any module

Printing:

- `printf`
- `sprintf`
- `eprintf`

Messages to the caller

- `print-warning`
- `print-info`
- `print-trace`

Regular expressions

- `regexp`
- `regexp?`
- `regexp-match-positions`
- `regexp-match-positions/multi`
- `regexp-match`
- `regexp-match/multi`
- `regexp-match?`

Information:

- `(*beastie* 'key)` : return information about beastie. The `key` can be:

  - `version-string` : show the beastie version, as a string.

  - `version-integers` : show the beastie version, as a list of integers.
  - `date` : the beastie release date.
  - `revision` : repository revision.
  - `s7-version` : the version of s7 this is built on.
  - `build-platform` : the platform beastie was built on, as a string.
  - `run-platform` : the platform which the program is running on, as a string.
  - `icu-version` : if ICU is compiled in, this is a list containing the ICU major, minor and patchlevel version numbers; else `#f`.
  - `icu-version-string` : if ICU is compiled in, this is a major.minor.patch version string; else `#f`.
  - `unicode-version` : the version of the Unicode Character Database which is built in (and used either with ICU or internal support).

- `*command-line*` : the arguments given to the program, as a list of strings, not including the program name.

## Functions

Index:

- eprintf
- print-info
- print-trace
- print-warning
- printf
- regexp
- regexp-match
- regexp-match-positions
- regexp-match-positions/multi
- regexp-match/multi
- regexp-match?
- regexp?
- sprintf

### eprintf

`(eprintf fmt arg...)` : like `printf`, except printing to stderr

### print-info

`(print-info fmt ...)` : print an informational message to stderr (visible at hightened verbosity)

### print-trace

`(print-trace fmt ...)` : print an informational message to stderr (visible at debug verbosity)

### print-warning

`(print-warning fmt args...)` : print a warning to stderr (visible at normal verbosity).

With a string `fmt`, this prints the warning and returns the assembled message.

This function has a few variants, intended to be useful for manipulating a stream of warnings:

- `(print-warning 'get-count)` : returns the number of warnings so far.
- `(print-warning 'get-list)` : returns the most recent few of the collection of warnings so far, and resets the list.
- `(print-warning 'push <port>)` : sends warnings to a new output-port?, which can be `#f` to discard them.
- `(print-warning 'pop)` : pops the output stack and return the previous top-of-stack.

The warning is generated and stored at all verbosity levels, even quiet, but is not printed when we are being quiet.

### printf

`(printf fmt arg...)` : format and print to stdout.

The format string argument can include a list of escapes, to indicate where the following arguments should be placed. These escapes can be:

- `~a` to print an argument in the most natural way.
- `~s` to print it in an unambiguous way (eg, strings will format as `"str"` rather than plain `str`).
- `~%` output a newline.
- `~~` output a tilde.

### regexp

`(regexp "pattern" [flag ...])` : compile the pattern (extended RE syntax).

Flags:

- `'ignore-case` : the pattern is compiled so that it ignores case when matching.
- `'no-substitute` : the pattern is compiled so that the matching functions will report only success/fail, and not record subexpressions (a mild optimisation, where appropriate).
- `'newline` : use alternate newline processing, as described for the `REG_NEWLINE` flag in regcomp(3).

### regexp-match

Like `regexp-match-positions`, except that the returned list contains substrings taken from `s`, rather than their offsets.

### regexp-match-positions

`(regexp-match-positions re s (start 0))` : match the regular expression `re` once against the string `s`, returning a list of pairs, or `#f` if there is no match. The regexp can also be passed as a string, which will be compiled to a regexp on the fly.

The match found is that closest to the start of the string, but it is not anchored to the start (unless the pattern starts with `"^"`).

The resulting list is a list of `(start . end)` pairs, where the `start` integer is the index, within `s`, of the start of the match, and `end` is the index of the character position one after the match. The first pair in the list is the match of the whole regexp; subsequent ones are the positions of any parenthesized subexpressions in the regexp. If a subexpression did not participate in the match, then the corresponding element in the list is returned as `#f`.

If `start` is given, it is the index at which to start matching. The offsets in the result are from the start of S, not from this start index.

If `start` is beyond the end of the string, then the match fails.

### regexp-match-positions/multi

Like `regexp-match-positions`, except that the result is a list of non-overlapping position pairs indicating a sequence of matches of the regexp RE within S.

The `:match-select` keyword argument selects which of the possibly multiple results is passed on. If the RE contains submatches, then (as described in `regexp-match-positions`) the result will be a sequence of ranges. The default value of this keyword argument is `car`, which selects the first pair, indicating the whole matched string, but `cadr`, for example, will select the content of the first submatch, and `values`, as the identity function, will select the full set of matches.

Empty matches are handled like other matches, returning a zero-length range string, but the pattern is restricted from matching an empty sequence immediately after an empty match.

If `start` is beyond the end of the string, then the match fails, returning `#f`.

Examples:

    > (regexp-match-positions/multi (regexp "x.") "12x4x6")
    '((2 . 4) (4 . 6))      ; ie, '("x4" "x6")
    > (regexp-match-positions/multi (regexp "x*") "12x4x6")
    '((0 . 0) (1 . 1) (2 . 3) (3 . 3) (4 . 5) (5 . 5) (6 . 6)) ;ie, '("" "" "x" "" "x" "" "")

### regexp-match/multi

This bears the same relationship to `regexp-match` as `regexp-match-positions/multi` bears to `regexp-match-positions`.

### regexp-match?

`(regexp-match? re s (start 0))` : match the regexp `re` against the string `s`, returning `#t` if it matches and `#f` if not.

The match is done between position `start` and the end of the string.

The regexp can be a regexp compiled with `regexp`, or a string.

### regexp?

`(regexp? x)` : return `#t` if X is a regular expression

### sprintf

`(sprintf fmt arg...)` : like `printf`, except returning a string

Norman
2026 August 02