-
Notifications
You must be signed in to change notification settings - Fork 0
Sketchbook: Penknife standard library
The Penknife standard library will build upon the basic features of Penknife with a few extra DSLs and frameworks for basic data manipulation.
None of the features described here actually exist yet.
Binding patterns: The pattern applies to a single value, and it may bind any number of local variables. This will be used by let
.
List tail binding patterns: The pattern has access to a sub-pattern that applies "next." It operates on a single value and may bind any number of local variables. For most patterns, the argument is assumed to be a list, and the pattern consumes some values from the list before passing the tail to the sub-pattern. This feature will be used for the argument lists of utilities like fn
.
Every definition of a binding pattern also defines a list tail binding pattern.
Assignment patterns: In a place
block, this pattern returns a pair of a getter and an optional setter. The put
block uses it for assignment.
Lens patterns: In a lens
block, this pattern returns either a getter thunk (like the type (() !-> b)
) or a lens implementation (like the type (a -> (b * (b -> a)))
), where the types are interpreted as follows:
-
(_ * _)
is a type representing Penknife's(cons _ _)
values. -
(_ -> _)
is a type representing Penknife's functions whose input is a one-element list and whose yoke input is pure. -
(() !-> _)
is a type representing Penknife's functions whose input is a zero-element list and whose yoke input is impure.
Every definition of a lens pattern also defines a binding pattern, a list tail binding pattern, an assignment pattern, and a lens object. The lens object is callable (like the type (a -> b)
).
Every definition of a structure type also defines a lens pattern, a binding pattern, a list tail binding pattern, an assignment pattern, and a type object.
Some of the standard library's utilities expect their yoke object to implement the following method:
(yoke-get-mbox-env yoke)
: Gets a default environment for mutable boxes. Furthermore, the standard library usually deals with mutable box objects that carry their own environment token for more convenient manipulation.
Penknife's standard library tools are a big mess of weak typing and surprise behaviors. Don't worry about it!TM
Weak typing: Most tools that process lists will also treat natural numbers as lists of (nil)
. Most tools that process natural numbers will also treat lists as numbers based on their length.
Comparison: compare
lt
lte
is
Lists and maps: foldl
foldr
map
mappend
keep
rem
any
all
each
rev
keys
cut
call
: On a list or map, looks up an element by key.
find
: Takes a list and a predicate and returns (nil)
or (list key elem)
where elem
satisfies the predicate.
kvs
: Takes a list or map and returns a list of two-element lists containing the keys and values.