README.md (2659B)
1 [](https://travis-ci.org/jsmaniac/remember) 2 [](https://codecov.io/gh/jsmaniac/remember) 3 [](http://jsmaniac.github.io/travis-stats/#jsmaniac/remember) 4 [](http://docs.racket-lang.org/remember/) 5 [](https://github.com/jsmaniac/remember/issues) 6 [](https://creativecommons.org/publicdomain/zero/1.0/) 7 8 remember 9 ======== 10 11 This Racket library provides a compile-time memoize feature. It allows 12 remembering a value with `(remember-write! 'category 'value)`. In subsequent 13 compilations, `(get-remembered 'category)` will return a set of all 14 previously-remembered values. 15 16 Installation 17 ============ 18 19 raco pkg install remember 20 21 Example use case: the `phc-adt` library 22 ======================================= 23 24 This library is used to implement "interned" structure and constructor types 25 in the [`phc-adt`](https://github.com/jsmaniac/phc-adt) library. The `phc-adt` 26 library needs to know the set of all structure and constructor types used in 27 the program, and uses `remember` to automatically memoize structure 28 descriptors and constructor names. 29 30 When the `structure` macro defined in 31 [`structure.hl.rkt`](https://github.com/jsmaniac/phc-adt/blob/refactor/structure.hl.rkt) 32 encounters an unknown list of field names, it uses the `remember` library to 33 append the tuple of field names to a user-specified file. That file is loaded 34 in subsequent compilations, so that the tuple of fields is known to `phc-adt`. 35 36 The memoized descriptors are used to know all possible structs that can 37 contain a field with the desired name when accessing it with `(get instance 38 field-name)`. The `get` macro can then retrieve the field's value using the 39 right accessor (for example `(struct123-fieldname instance)`). Knowing all 40 existing structures allows `get` to perform some kind of dynamic dispatch to 41 obtain the appropriate accessor, for example using a `cond` which tests for 42 all possible types. 43 44 The `constructor` macro defined in 45 [`constructor.hl.rkt`](https://github.com/jsmaniac/phc-adt/blob/refactor/constructor.hl.rkt) 46 works in the same way, but remembers the name of the constructor's tag instead 47 of field names. The memoization feature is used so that all uses of a 48 constructor with a given name are equivalent, across all files. 49