1 USING: help.syntax help.markup ;
5 { $values { "quot" "a quotation" } { "undo" "the inverse of the quotation" } }
6 { $description "Creates the inverse of the given quotation" }
10 { $values { "quot" "a quotation" } }
11 { $description "Executes the inverse of the given quotation" }
12 { $see-also [undo] } ;
15 { $values { "word" "a word" } { "quot" "the inverse" } }
16 { $description "Defines the inverse of a given word, taking no arguments from the quotation, only the stack." }
17 { $see-also define-dual define-involution define-pop-inverse } ;
20 { $values { "word1" "a word" } { "word2" "a word" } }
21 { $description "Defines the inverse of each word as being the other one." }
22 { $see-also define-inverse define-involution } ;
24 HELP: define-involution
25 { $values { "word" "a word" } }
26 { $description "Defines a word as being its own inverse." }
27 { $see-also define-dual define-inverse } ;
29 HELP: define-pop-inverse
30 { $values { "word" "a word" } { "n" "number of arguments to be taken from the inverted quotation" } { "quot" "a quotation" } }
31 { $description "Defines the inverse of the given word, taking the given number of arguments from the inverted quotation. The quotation given should generate an inverse quotation." }
32 { $see-also define-inverse } ;
35 { $values { "quot" "a quotation" } { "?" "a boolean" } }
36 { $description "Tests if the stack can match the given quotation. The quotation is inverted, and if the inverse can run without a unification failure, then t is returned. Else f is returned. If a different error is encountered (such as stack underflow), this will be propagated." } ;
39 { $values { "quot-alist" "an alist from inverse quots to quots" } }
40 { $description "The equivalent of a case expression in a programming language with buitlin pattern matchining. It attempts to match the stack with each of the patterns, in order, by treating them as inverse quotations. Failure causes the next pattern to be tested." }
42 "TUPLE: cons car cdr ;"
44 ": sum ( list -- sum )"
46 " { [ <cons> ] [ sum + ] }"
51 ARTICLE: { "inverse" "intro" } "Invertible quotations"
52 "The inverse vocab defines a way to 'undo' quotations, and builds a pattern matching framework on that basis. A quotation can be inverted by reversing it and inverting each word. To define the inverse for particular word, use"
53 { $subsection define-inverse }
54 { $subsection define-pop-inverse }
55 "To build an inverse quotation"
56 { $subsection [undo] }
57 "To use the inverse quotation for pattern matching"
59 { $subsection matches? }
60 { $subsection switch } ;
63 ABOUT: { "inverse" "intro" }