This is the fresnel Reference Manual, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 08 18:06:00 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
fresnel
Bidirectional translation with lenses
GrammaTech
MIT
fare-quasiquote-extras
(system).
trivial-package-local-nicknames
(system).
fresnel/fresnel
(system).
fresnel/fresnel
GrammaTech
MIT
gt/full
(system).
trivial-package-local-nicknames
(system).
fresnel/lens
(system).
Files are sorted by type and then listed depth-first from the systems components trees.
fresnel/fresnel/file-type.lisp
fresnel/fresnel
(system).
alist-lens
(function).
gensym-lens
(function).
gensym?
(function).
keyword-lens
(function).
print-read-lens
(function).
read-print-lens
(generic function).
build-read-print-lens
(function).
fresnel/lens/file-type.lisp
fresnel/lens
(system).
acond
(function).
after
(function).
alist-mapping
(function).
backward
(function).
before
(function).
bij
(function).
bij
(class).
canonize
(function).
canonize-after
(function).
canonize-before
(function).
canonizer
(function).
canonizer
(class).
car
(function).
cdr
(function).
check
(function).
check-laws
(function).
check-subtype
(function).
check-type
(function).
choose
(function).
combine
(function).
compose
(function).
compose*
(function).
cons
(function).
constantly
(function).
convert
(method).
convert
(method).
convert
(method).
create
(function).
default
(function).
discern
(macro).
discern-values
(macro).
forward
(function).
fset-mapping
(function).
get
(function).
guard
(function).
hash-table-alist
(function).
hash-table-mapping
(function).
identity
(function).
identity!
(function).
initialize-instance
(method).
lazy
(function).
lazy-list
(macro).
lazy-list*
(macro).
lens
(function).
lens
(class).
lens-error-lens
(reader method).
list
(function).
list*
(function).
lquot
(function).
lquot*
(function).
make-lens
(function).
map
(macro).
mapcar
(function).
mapping
(function).
match
(macro).
match-constructors
(macro).
match-list
(macro).
match-list*
(macro).
nilable
(function).
of-type
(function).
opp
(function).
optional
(function).
or
(function).
or!
(function).
path
(function).
print-object
(method).
print-object
(method).
put
(function).
qlens
(function).
qlens
(class).
rguard
(function).
rquot
(function).
rquot*
(function).
satisfies
(function).
seq
(macro).
some
(function).
trace
(function).
untrace
(function).
with-component-lenses
(macro).
with-create-lenses
(macro).
with-get-lenses
(macro).
with-put-lenses
(macro).
%concrete-defaults
(symbol macro).
*depth*
(special variable).
*trace*
(special variable).
+identity-lens+
(symbol macro).
+storage-for-deflex-var-+unbound++
(constant).
+unbound+
(symbol macro).
canonize-fn
(reader method).
choose-fn
(reader method).
create-fn
(reader method).
discern-values*
(function).
extract-defaults
(function).
get-fn
(reader method).
lens-error
(condition).
lensify
(function).
lookup-default
(function).
match-two
(macro).
maybe-trace
(function).
morally-unbound?
(function).
put-fn
(reader method).
split-bindings
(function).
with-morally-unbound-variables
(macro).
Packages are listed by definition order.
fresnel/lens.impl
Internal package where lenses are actually
implemented. (Working in the lens package is inconvenient as it
shadows many common functions).
gt/full
.
trivial-package-local-nicknames
.
%concrete-defaults
(symbol macro).
*depth*
(special variable).
*trace*
(special variable).
+identity-lens+
(symbol macro).
+storage-for-deflex-var-+unbound++
(constant).
+unbound+
(symbol macro).
canonize-fn
(generic reader).
choose-fn
(generic reader).
create-fn
(generic reader).
discern-values*
(function).
extract-defaults
(function).
get-fn
(generic reader).
lens-error
(condition).
lensify
(function).
lookup-default
(function).
match-two
(macro).
maybe-trace
(function).
morally-unbound?
(function).
put-fn
(generic reader).
split-bindings
(function).
with-morally-unbound-variables
(macro).
fresnel/fresnel
Very high-level lenses; nothing language-specific.
gt/full
.
trivial-package-local-nicknames
.
alist-lens
(function).
gensym-lens
(function).
gensym?
(function).
keyword-lens
(function).
print-read-lens
(function).
read-print-lens
(generic function).
build-read-print-lens
(function).
fresnel/lens
Lenses for bidirectional transformations.
As defined by Foster et al., 2007; Foster et al., 2008; Bohannon et
al., 2008; and Foster et al., 2009.
It is not recommended to :USE this package; use a package-local
nickname:
(:local-nicknames (:l :fresnel/lens))
The convention is for lens constructors to be functions, even if they
take no arguments (such as IDENTITY). This is to be consistent with
other, parametric lens constructors. For example, CAR can be called
with either zero or one argument rather than having a function that
takes one argument and a non-function for the zero-argument case.
The DISCERN and MATCH macros, and the CHECK, NILABLE, PATTERN, and OR
functions, deal with discerning lenses. A discerning lens is a quotient
lens that partitions its set of concrete structures (and similarly,
its set of abstract structures) into two subsets: a set of
"well-formed" values and a set of "ill-formed" values. While the
set of well-formed values can be equipped with any equivalence
relation as usual, all ill-formed values are considered equivalent to
each other.
For each of the three functions of a discerning lens, the following must be true iff the (first) argument to the function was ill-formed:
- The first of the VALUES returned by the function is ill-formed.
- The last of the VALUES returned by the function is NIL.
By these conventions, for instance, the IDENTITY lens is discerning with NIL as its only ill-formed value, but the CAR lens is not discerning. The DISCERN macro can be wrapped around a usage of a discerning lens in order to get both the primary return value and the well-formedness together, as a single value (a cons).
acond
(function).
after
(function).
alist-mapping
(function).
backward
(function).
before
(function).
bij
(function).
bij
(class).
canonize
(function).
canonize-after
(function).
canonize-before
(function).
canonizer
(function).
canonizer
(class).
car
(function).
cdr
(function).
check
(function).
check-laws
(function).
check-subtype
(function).
check-type
(function).
choose
(function).
combine
(function).
compose
(function).
compose*
(function).
cons
(function).
constantly
(function).
create
(function).
default
(function).
discern
(macro).
discern-values
(macro).
forward
(function).
fset-mapping
(function).
get
(function).
guard
(function).
hash-table-alist
(function).
hash-table-mapping
(function).
identity
(function).
identity!
(function).
lazy
(function).
lazy-list
(macro).
lazy-list*
(macro).
lens
(function).
lens
(class).
list
(function).
list*
(function).
lquot
(function).
lquot*
(function).
make-lens
(function).
map
(macro).
mapcar
(function).
mapping
(function).
match
(macro).
match-constructors
(macro).
match-list
(macro).
match-list*
(macro).
nilable
(function).
of-type
(function).
opp
(function).
optional
(function).
or
(function).
or!
(function).
path
(function).
put
(function).
qlens
(function).
qlens
(class).
rguard
(function).
rquot
(function).
rquot*
(function).
satisfies
(function).
seq
(macro).
some
(function).
trace
(function).
untrace
(function).
with-component-lenses
(macro).
with-create-lenses
(macro).
with-get-lenses
(macro).
with-put-lenses
(macro).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Return a cons cell of the primary value and well-formedness from FORM.
The FORM must evaluate to the result of calling one of the functions of a discerning lens. The car of the cons cell returned by this macro is the primary value returned by FORM, and the cdr is a boolean indicating whether that value is well-formed.
Return two values: the primary value of FORM, and its well-formedness.
FORM must evaluate to the result of calling one of the functions of a discerning lens. The first value returned by this macro is the primary value returned by FORM, and the second is a boolean indicating whether that value is well-formed.
Like ‘l:list’, but does not evaluate LENSES until the lens is called. Note LENSES may be evaluated more than once!
Like ‘l:list*’, but does not evaluate LENSES until the lens is called. Note LENSES may be evaluated more than once!
Same as ‘fset:map’.
Return a discerning lens using BINDINGS to translate between PATTERNS.
PATTERNS is a list where every two elements, a concrete form and an
abstract form, defines one lens.
Each multiple of two patterns is compiled into a separate lens, and
the lens are implicitly combined with ‘l:or’.
If there is only one pattern, it is repeated. (This is an abbreviation
for when the concrete and abstract forms are the same.)
If any pattern is of the form ‘($ PAT)’, then PAT is macroexpanded and
the expansion is treated as the real pattern.
The BINDINGS are similar to those of a LET: each one is a list whose
first element is a symbol and whose second element is a form that
evaluates to a discerning lens. There may also be a third element,
which is used a default in the ‘create’ direction.
The concrete form is a Trivia pattern (using the symbols from
BINDINGS) that would evaluate to some concrete structure when given
appropriate values for each of the symbols in BINDINGS.
Likewise the abstract form is a Trivia pattern, using the symbols from
BINDINGS, that would evaluate to some abstract structure when given
appropriate values.
Note that the symbols used by the concrete form/pattern and the
symbols used by the abstract form/pattern do not need to be the same;
the only requirement is that they both be subsets of the variables
bound in BINDINGS.
If the concrete form/pattern omits variables, they are always
defaulted with the provided defaults.
If the abstract pattern omits variables, the way the concrete form
evaluates differs between ‘create’ and ‘put’.
If the concrete form is being evaluated in the ‘create’ direction,
then missing symbols are filled in from provided defaults in the
bindings of the ‘l:match’ form.
If the concrete form is being evaluated in the ‘put’ direction, then
missing symbols are filled in from the provided member of the concrete
domain (by matching it against the concrete pattern with ‘get’).
The GET direction first attempts to find values for the symbols in BINDINGS that would make the concrete pattern match the input. If no such values can be found, NIL is returned. Otherwise, those values are each sent through their respective lenses defined by BINDINGS, and if each of those lenses produced well-formed values, their outputs are used to construct the final output via the abstract form. The CREATE direction is analogous.
Like ‘l:match’ for translating from list to list.
If each list has the same length, and that length is the same as the
length of the bindings, there is no need to spell it out.
Like ‘l:match-list’, but the last binding is applied to the tail, instead of per-element.
Same as ‘fset:seq’.
A helper macro for ‘l:match’.
The BINDINGS are similar to those of a LET: each one is a list whose
first element is a symbol and whose second element is a form that
evaluates to a discerning lens.
FN should be one of ‘l:get’, ‘l:create’, or ‘l:put’. (If you are using
‘l:put’ directly you many want to establish component-wise defaults
using ‘l:with-defaults’).
Within BODY, the variables in BINDINGS are rebound to the result of
calling the requested lens on the existing value of that binding,
using FN.
If any lens is ill-formed (returns nil as its last value) then BODY is not evaluated and the entire form returns nil.
Same as ‘l:with-component-lenses’ with ‘l:create’ as its function.
Same as ‘l:with-component-lenses’ with ‘l:get’ as its function.
Same as ‘l:with-component-lenses’ with ‘l:put’ as its function.
Return a lens that applies L1 or L2 depending on whether C1 or A1 hold.
The domains of L1 and L2 must be disjoint, as must be the codomains of L1 and
L2. In the forward direction, applies the C1 predicate, then uses L1 if true or
L2 if false. In the reverse direction, applies the A1 predicate, then uses L1 if
true or L2 if false. Uses CREATE instead of PUT if C1 and A1 disagree in the
reverse direction.
Same as "acond" from Foster et al., 2007.
Right quotient each lens in LENSES with the next lens. That is, all but the first lens should be canonizers.
Wrap an association list as a bijective lens.
GET on the lens becomes assoc, and CREATE on the lens becomes rassoc.
Lens that maps L over the values of an alist. TEST is the equality predicate on keys.
Left quotient each lens in LENSES with the previous lens. That is, all but the last lens should be canonizers.
Return a bijective lens from the given GET function and its inverse, CREATE.
Similar to "bij" from Hoffmann et al., 2010, except that BIJ takes both directions of the bijection instead of just the forward direction.
Call the canonize function from CANONIZER on VALUE.
Build a canonizer from two functions, CANONIZE and CHOOSE. CANONIZE and CHOOSE are treated as discerning, with special behavior: if they fail then the original values are passed through unchanged. This makes writing canonizers easier, as you don’t have to remember to explicitly pass through irrelevant values.
Return a lens to extract the car of a cons cell.
If D is given, uses it as a default cdr value for CREATE.
Similar to "hd" from Foster et al., 2007, except that CAR makes D optional and simply omits the "create" function if D is not provided.
Return a lens to extract the cdr of a cons cell.
If D is given, uses it as a default car value for CREATE.
Similar to "tl" from Foster et al., 2007, except that CDR makes D optional and simply omits the "create" function if D is not provided.
Return a discerning identity lens whose well-formed values all satisfy PRED.
Check that LENS obeys the lens laws for C, a concrete value, and A,
an abstract value, using TEST as the equivalence relation.
Returns four boolean values:
1. Whether all the laws were respected.
2. Whether GetPut was respected.
3. Whether PutGet was respected.
4. Whether CreateGet was respected.
Return a discering identity lens whose well-formed values are subtypes of TYPE.
Return a discering identity lens whose well-formed values are of TYPE.
Call the choose function from CANONIZER on VALUE.
Convert a bijection into a lens.
Return a lens that, in the PUT direction, uses COMBINER, a function,
to augment the value constructed by LENS with the old value.
Converts a bijection into a lens by using COMBINER to "patch" the result of ‘create’ with the old concrete value.
Return a lens that abstracts through the LENSES in order.
Similar to the semicolon combinator from Foster et al., 2007, except that
COMPOSE acts like ALEXANDRIA:COMPOSE in that (in the forward direction) lenses
are applied from back to front rather than from front to back. That is, l;k is
the same as (compose k l).
Allows the composition of zero lenses, equivalent to the identity
lens.
Like ‘l:compose’, but discerning.
Return a lens that applies L1 to the car, and L2 to cdr, of a cons cell.
Inspired by "xfork" from Foster et al., 2007.
Return a lens that always returns V.
If D is given, uses it as a default value for CREATE.
Similar to "const" from Foster et al., 2007, except that CONSTANTLY makes D optional and simply omits the "create" function if D is not provided.
Return a concrete value from the abstract view A through the lens L.
As a function, identity.
As a Trivia pattern, matches anything.
Lens that maps L over the values of an FSet map.
Lens to convert between a concrete string to an abstract gensym.
Is X a symbol without a package?
Return an abstract view of C through the lens L.
Not analogous to CL:GET.
Return a discerning lens whose well-formed concrete values all satisfy PRED.
Lens that translates between hash tables and alists.
In the PUT direction, the hash table test is taken from the old hash
table; otherwise TEST is used.
Lens that maps L over the values of a hash table. See ‘l:mapping’ for the details.
Return the identity lens.
Same as "id" from Foster et al., 2007.
Like l:identity, but returns T as its second value. This allows it to work even on null values.
Lens to convert between a concrete string and an abstract keyword.
Return a lens that acts like the lens returned by F.
Doesn’t call F until necessary, but also doesn’t cache the result of F. To get caching, compose this function with something like SERAPEUM:ONCE.
Create a lens from GET, PUT, and CREATE functions.
If CREATE is not provided, it is treated as PUT with a concrete
argument of nil.
Return a lens that matches a sequence of lenses.
That is, it matches values that are sequences of the same length as
LENSES, if every lens in LENSES matches the element at the same
position in the value.
Like ‘l:list’, but the last lens matches a tail of unspecified length.
Coarsen the (concrete) domain of QLENS using CANONIZER.
Return a new q-lens.
Composes the get function of QLENS with the canonizer of Q and
composes the chooser of Q with the put/create function of QLENS.
When using ‘lquot’, only concrete values are changed. The canonizer is called directly on the concrete arguments to GET and PUT, while the chooser is called on the concrete result of CREATE and PUT (if they succeed).
Reduce lenses with ‘l:lquot’, from the end.
Return a lens that applies L to every element of a list.
Similar to "list_map" from Foster et al., 2007.
This is a discerning lens: L is assumed to be discerning, and if it fails for any element, then the entire lens fails.
Low-level lens that maps LENS over some kind of key-value mapping (table).
If you are writing lenses for translation, you probably want to use
‘alist-mapping’, ‘hash-table-mapping’, or ‘fset-mapping’. This
function is lower-level, for supporting new tabular data structures in
a consistent way.
In the GET direction, the new lens returns an abstract table where the
keys are the same as the concrete table, but the values are the result
of passing each value through LENS.
In the CREATE direction, the new lens returns a concrete table with
the same keys (domain) as the abstract table, and values derived by
passing the values through LENS.
In the PUT direction, the new lens also returns a concrete table with
the same keys as the abstract table, but the values depend on which
keys are also present in the concrete table. If the same key is
present in both tables, then the new concrete value is computed using
PUT with the abstract value and the old concrete value; otherwise
CREATE is used.
Note that it is always the case (by design) that keys that are present
in the concrete table but not the abstract table are lost.
Takes four callbacks:
1. MAKER is a function of one argument that creates a new, empty
mapping that is "like" its argument (e.g. a hash table having
the same test.)
2. GETTER takes a table and a key and returns two values (like
‘gethash’, but the table comes before the key).
3. SETTER takes a table, a key, and a value, and returns a table
updated with the new key and value. It is fine if the table is
mutated, but the return value has to be the table.
4. WALKER takes a table and a binary function and maps it over the entries in the table (like ‘maphash’).
Return a discerning lens that acts like L but has no ill-formed values.
Return a discering identity lens whose well-formed values are of TYPE.
Return a bijective lens that acts like L in reverse.
Completely discards all PUT behavior of L, making use only of GET and CREATE.
Similar to "op" from Hoffmann et al., 2010, except that OPP is not involutory because the lenses defined in this package are not symmetric.
Return a lens that matches whatever X matches, or nil. X must not match nil itself.
Return a lens that tries LENSES in order until one succeeds. A lens succeeds if the last value it returns is not ‘nil’.
Like ‘l:or’, but strict.
If more than one lens in LENSES matches, that’s an error.
Return a lens to access the subtree of an FSet structure at PATH.
Like ‘read-print-lens’, but translates between concrete values and abstract strings.
Return an updated version of C using the abstract view A through the lens L.
Return a discerning lens whose well-formed abstract values all satisfy PRED.
Coarsen the (abstract) codomain of QLENS using CANONIZER.
Return a new q-lens.
Composes the choose function of CANONIZER with the get function of
QLENS, and composes the put/create function of QLENS with the
canonizer function of CANONIZER.
When using ‘rquot’, only abstract values are changed. The canonizer is called directly on the abstract arguments to PUT and CREATE, while the chooser is called on the abstract result of GET (if it succeeds).
Reduce lenses with ‘l:rquot’, from the end.
Like l:mapcar, but as soon as one result matches, use that.
Trace (successful) lens matching.
Stop tracing lens matching.
Construct a lens to translate between concrete
strings and abstract values of type TYPE, using the appropriate Lisp
reader/parser and printer.
(eql integer)
) &key) ¶(eql number)
) &key) ¶(eql float)
) &key format) ¶(eql double-float)
) &key) ¶(eql single-float)
) &key) ¶(eql symbol)
) &key package) ¶lens-error
)) ¶keyword
.
lens
.
Every bijection is also a lens, using a put function that ignores its second arg.
lens
.
A canonizer is a kind of bijection.
A lens is "quotiented" with a canonizer, resulting in a quotient lens.
The canonize function of the canonizer is called on arguments to the lens; the choose function of the canonizer is called on the values the lens returns.
A basic lens.
Lenses are a kind of bidirectional transformation.
Lenses generalize bijections by allowing the transformation in the
forward direction (get) to be non-injective. (Put is still injective,
however.)
Lenses must satisfy the following laws:
- GetPut: (put l (get l c) c) = c for all c from C
- PutGet: (get l (put l a c)) = a for all (a, c) from A × C
- CreateGet: (get l (create l a)) = a for all a from A
Of course, the CreateGet law need not hold for a lens that does not have a CREATE function.
bij
.
Quotient lenses generalize lenses so that the lens laws are
respected up to some equivalence relation.
Lenses may be "quotiented" arbitrarily with canonizers (a kind of
bijective lens) on the left (concrete) or right (abstract) side. This
allows a style where canonicalization is pervasive and interleaved
rather than being done in one step at the edges.
Practically they treat certain data as ignorable.
Distinguished value that makes a binding morally unbound.
Depth of lens matching.
Are we tracing?
Actually construct a lens from a pair of concrete and abstract forms.
Bind VARS around BODY in such a way that they are morally unbound.
Construct a bijection between a concrete string and an abstract value of TYPE using a function PARSER and a function UNPARSER.
The lens only matches if the value returned by PARSER is of TYPE. Errors of type ‘parse-error’ from PARSER are also considered failures.
Helper function for ‘discern-values’.
Like ‘fset:lookup’, but return DEFAULT if KEY was not present. The second value is T if the key was present, NIL otherwise.
If tracing, print the results of successful lens matching.
Return non-nil if SYM is (morally) unbound in ENV.
Split a two-element list into a list of the first elements and a list of the second elements.
Jump to: | A B C D E F G H I K L M N O P Q R S T U W |
---|
Jump to: | A B C D E F G H I K L M N O P Q R S T U W |
---|
Jump to: | %
*
+
C G L P S |
---|
Jump to: | %
*
+
C G L P S |
---|
Jump to: | B C F L P Q S |
---|
Jump to: | B C F L P Q S |
---|