https://github.com/suzannesoy/remember
Compile-time memoization for Racket.
https://github.com/suzannesoy/remember
macros memoization racket-library
Last synced: 6 months ago
JSON representation
Compile-time memoization for Racket.
- Host: GitHub
- URL: https://github.com/suzannesoy/remember
- Owner: SuzanneSoy
- License: cc0-1.0
- Created: 2016-05-28T22:38:32.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2021-04-04T14:29:00.000Z (about 5 years ago)
- Last Synced: 2025-01-30T11:42:09.723Z (over 1 year ago)
- Topics: macros, memoization, racket-library
- Language: Racket
- Homepage: http://docs.racket-lang.org/remember/
- Size: 19.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-more.md
Awesome Lists containing this project
README
[](https://travis-ci.org/jsmaniac/remember)
[](https://codecov.io/gh/jsmaniac/remember)
[](http://jsmaniac.github.io/travis-stats/#jsmaniac/remember)
[](http://docs.racket-lang.org/remember/)
[](https://github.com/jsmaniac/remember/issues)
[](https://creativecommons.org/publicdomain/zero/1.0/)
remember
========
This Racket library provides a compile-time memoize feature. It allows
remembering a value with `(remember-write! 'category 'value)`. In subsequent
compilations, `(get-remembered 'category)` will return a set of all
previously-remembered values.
Installation
============
raco pkg install remember
Example use case: the `phc-adt` library
=======================================
This library is used to implement "interned" structure and constructor types
in the [`phc-adt`](https://github.com/jsmaniac/phc-adt) library. The `phc-adt`
library needs to know the set of all structure and constructor types used in
the program, and uses `remember` to automatically memoize structure
descriptors and constructor names.
When the `structure` macro defined in
[`structure.hl.rkt`](https://github.com/jsmaniac/phc-adt/blob/refactor/structure.hl.rkt)
encounters an unknown list of field names, it uses the `remember` library to
append the tuple of field names to a user-specified file. That file is loaded
in subsequent compilations, so that the tuple of fields is known to `phc-adt`.
The memoized descriptors are used to know all possible structs that can
contain a field with the desired name when accessing it with `(get instance
field-name)`. The `get` macro can then retrieve the field's value using the
right accessor (for example `(struct123-fieldname instance)`). Knowing all
existing structures allows `get` to perform some kind of dynamic dispatch to
obtain the appropriate accessor, for example using a `cond` which tests for
all possible types.
The `constructor` macro defined in
[`constructor.hl.rkt`](https://github.com/jsmaniac/phc-adt/blob/refactor/constructor.hl.rkt)
works in the same way, but remembers the name of the constructor's tag instead
of field names. The memoization feature is used so that all uses of a
constructor with a given name are equivalent, across all files.