Schemepunk
A batteries-included extended standard library for seven R7RS Scheme dialects.
Install / Use
/learn @ar-nelson/SchemepunkREADME
Schemepunk
A kitchen-sink utility library for several R7RS Scheme dialects.
This library is unfinished and under heavy development. It's optimized for the needs of a few related projects I'm working on, mostly programming language interpreters and compilers.
To use this library, drop this repository in a schemepunk directory in your
project, ideally as a Git submodule. The shell scripts in scripts can run unit
tests or Scheme applications in all of Schemepunk's supported Scheme dialects,
and they know how to find and include .sld library dependencies, even in
Schemes that don't natively support this.
Supported Schemes
- [Chibi][chibi]
- [Chicken][chicken]*
- [Gauche][gauche]
- [Gerbil][gerbil]
- [Kawa][kawa]
- [Larceny][larceny]
- [Sagittarius][sagittarius]
* Chicken requires these eggs: r7rs, utf8, box, srfi-41, srfi-69,
srfi-99, srfi-113, srfi-128, srfi-133, and ioctl. (ioctl is only
required on Unix-based OSes.)
Schemepunk can also be built as a Chicken egg. Just run chicken-install
(possibly with -sudo) in the repo's root directory.
Modules
(schemepunk box)- Boxes(schemepunk btree)- Persistent B-trees(schemepunk command)- Command-line argument parsing(schemepunk comparator)- Comparators(schemepunk datalog)- Logic programming (WIP)(schemepunk flexvector)- Flexvectors (dynamic arrays)(schemepunk function)- Functional programming utilities(schemepunk generator)- Generators and accumulators(schemepunk hash-table)- Hash tables(schemepunk hook)- Hooks(schemepunk json)- JSON(schemepunk list)- List utilities(schemepunk mapping)- Persistent mappings(schemepunk multimap)- Multimaps(schemepunk path)- File path utilities(schemepunk random)- Random number generation(schemepunk set)- Sets and bags(schemepunk show)- Monadic text formatting(schemepunk sort)- Sorting(schemepunk stream)- Streams(schemepunk string)- String utilities(schemepunk syntax)- Utility macros(schemepunk term-colors)- ANSI terminal colors(schemepunk test)- Unit test framework(schemepunk vector)- Vector library
(schemepunk box)
Polyfilled alias for [SRFI 111 (Boxes)][srfi111]. Exports one additional procedure:
(update-box! <box> <proc>)is equivalent to(set-box! <box> (<proc> (unbox <box>))).
(schemepunk btree)
An original implementation of persistent B-trees, used to implement (schemepunk mapping) on all Schemes except Gauche¹.
Schemepunk's B-tree mappings are frequently 2-3 times faster than the
red-black-tree reference implementation of SRFI 146, and significantly faster
when constructing large mappings. This library includes linear-update
!-suffixed mutation procedures, for yet another performance boost.
You usually want to use this module through (schemepunk mapping), but, if you
want to use the B-tree data structure directly, this module provides these
low-level procedures:
(btree <comparator> <max-size>)(btree? <btree>)(btree-key-comparator <btree>)(btree-empty? <btree>)(btree-copy <btree>)(btree-ref <key> <value> <failure-proc>)(failure-procis optional)(btree-set <btree> <key> <value>)(btree-set! <btree> <key> <value>)(btree-delete <btree> <key>)(btree-delete! <btree> <key>)(btree-pop <btree> <key>)(returns two values:(key . value)and modified btree)(btree-pop! <btree> <key>)(returns one value:(key . value))(btree-fold <fn> <seed> <btree>)(btree-fold-right <fn> <seed> <btree>)(alist->btree <alist> <comparator> <max-size>)(btree->alist <btree>)(btree-subset? <value-comparator> <btree1> <btree2>)(btree=? <value-comparator> <btree1> <btree2>)(btree<? <value-comparator> <btree1> <btree2>)(btree-hash <value-comparator> <btree>)(make-btree-comparator <value-comparator>)btree-comparator
¹ B-trees are faster than most Schemes' SRFI 146, but Gauche's <tree-map> is
usually even faster.
(schemepunk command)
A command-line argument parser, loosely based on Chibi Scheme's
[(chibi app)][chibi-app]. The parser procedures take app specifications,
which are nested alists. For example, the zoo demo from the (chibi app)
documentation can be written like this for (schemepunk command):
'((name "Zookeeper Application")
(doc "Example application from (chibi app) documentation, adapted for \
(schemepunk command).")
(copyright "Copyright (c) 2020")
(options
(animals
(type (list symbol))
(doc "list of animals to act on (default all)"))
(lions
(short #\l)
(doc "also apply the action to lions")))
(commands
(feed
(short-doc "feed the animals")
(doc-args <animals> ...))
(wash
(short-doc "wash the animals")
(doc-args <animals> ...)
(options (soap)))
(help
(short-doc "print help")))
(require-command #t))
(schemepunk command) supports both - short options and -- long options.
Short options can be grouped: -xyz = -x -y -z. Values after option names can
follow either a space or =. Git-style commands, with their own documentation
and option lists, are also supported.
Procedures
-
(run-application <spec> <command-line> <proc>)parses the list of command-line arguments<command-line>using the specification<spec>. The first element of<command-line>should be the executable name.If parsing is successful,
<proc>is tail-called with five arguments:options, an alist of the-or--options passed to the appargs, a list of all non-option and non-command arguments passed to the app, as stringscommand, the command name passed to the app, or#fif there is no commandcommand-options, an alist of all options that occurred after the command namecommand-args, a list of all non-option arguments that occurred after the command name, as strings
If parsing fails, a usage message is printed to
(current-error-port), and then Scheme is terminated with(exit 1). -
(parse-app <spec> <command-line>)parses the list of command-line arguments<command-line>using the specification<spec>, and returns five values, corresponding to the five arguments passed torun-application's<proc>. If parsing fails, it will raise an error object for whichcommand-error?is#t. -
(app-usage <spec> <command-line>)is a(schemepunk show)formatter that prints a usage message for the app specification<spec>. The executable name is taken from the first element of the list<command-line>. -
(command-usage <spec> <command> <command-line>)is a(schemepunk show)formatter that prints a usage message for the command<command>in the app specification<spec>. The executable name is taken from the first element of the list<command-line>. -
app-helpandcommand-helpare likeapp-usageandcommand-usage, but also includename,doc, andcopyrightif they are present in the specification.
-
(command-error? <datum>)is a type predicate for the error objects raised byparse-app.
App specification
All alist keys are optional; the empty specification '() is valid but has no
documentation and accepts no options.
name- name of the application, displayed at the start of the app's help textdoc- documentation paragraph, displayed at the start of the app's help textdoc-args- symbols or strings that describe the app's arguments in usage text; e.g.,<input-file> "[<output-file>]"copyright- copyright message displayed at bottom of help textoptions- alist of options for the app; each option's key is also its default long option namecommands- alist of commands for the app; each command's key is also its namerequire-command- if#t, app exits with an error if no command is provideddefault-help-option- if#t, an option is added with long name--helpand short name-hthat, if present, causesrun-applicationto print the app's help text and exitdefault-help-command- if#t, a command namedhelpis added that, if selected and passed a command name as its only argument, causesrun-applicationto display that command's help text and exit
Option
type- data type of the option's value, defaults toboolean; options areboolean,symbol,char,string,integer,real,sexp, and(list <type>)long- long option aliases for this option (symbols or strings)short- short option aliases for this option (chars)doc- description of this option, displayed in usage textdoc-value- name of the option's value, displayed in usage text, defaults to value oftype
Command
short-doc- documentation shown in the app's usage textdoc- longer documentation shown in the command's usage textdoc-args- symbols or strings that describe the command's arguments in usage text; e.g.,<input-file> "[<output-file>]"options- alist of opt
Related Skills
node-connect
337.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
337.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.1kCommit, push, and open a PR
