]> gitweb.factorcode.org Git - factor.git/blob - core/memoize/memoize-docs.factor
Update actions, because Node.js 16 actions are deprecated, to Node.js 20
[factor.git] / core / memoize / memoize-docs.factor
1 ! Copyright (C) 2007, 2009 Slava Pestov, Daniel Ehrenberg.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: help.syntax help.markup words quotations effects ;
4 IN: memoize
5
6 ARTICLE: "memoize" "Memoization"
7 "The " { $vocab-link "memoize" } " vocabulary implements a simple form of memoization, which is when a word caches results for every unique set of inputs that is supplied. Calling a memoized word with the same inputs more than once does not recalculate anything."
8 $nl
9 "Memoization is useful in situations where the set of possible inputs is small, but the results are expensive to compute and should be cached. Memoized words should not have any side effects."
10 $nl
11 "Defining a memoized word at parse time:"
12 { $subsections POSTPONE: MEMO: }
13 "Defining a memoized word at run time:"
14 { $subsections define-memoized }
15 "Clearing memoized results:"
16 { $subsections reset-memoized } ;
17
18 ABOUT: "memoize"
19
20 HELP: define-memoized
21 { $values { "word" word } { "quot" quotation } { "effect" effect } }
22 { $description "Defines the given word at run time as one which memoizes its outputs given a particular input." } ;
23
24 HELP: MEMO:
25 { $syntax "MEMO: word ( stack -- effect ) definition... ;" }
26 { $values { "word" "a new word to define" } { "definition" "a word definition" } }
27 { $description "Defines the given word at parse time as one which memoizes its output given a particular input. The stack effect is mandatory." } ;
28
29 { define-memoized POSTPONE: MEMO: } related-words