]> gitweb.factorcode.org Git - factor.git/blob - basis/listener/listener-docs.factor
a35f43e8481214a0fcaef0e9aa5fb1769711fa4f
[factor.git] / basis / listener / listener-docs.factor
1 USING: help.markup help.syntax kernel io system prettyprint continuations quotations vocabs.loader vocabs.refresh parser ;
2 IN: listener
3
4 ARTICLE: "listener-watch" "Watching variables in the listener"
5 "The listener prints values of dynamic variables which are added to a watch list:"
6 { $subsections visible-vars }
7 "To add or remove a single variable:"
8 { $subsections
9     show-var
10     hide-var
11 }
12 "To add and remove multiple variables:"
13 { $subsections
14     show-vars
15     hide-vars
16 }
17 "Clearing the watch list:"
18 { $subsections hide-all-vars } ;
19
20 HELP: only-use-vocabs
21 { $values { "vocabs" "a sequence of vocabulary specifiers" } }
22 { $description "Replaces the current manifest's vocabulary search path with the given set of vocabularies." } ;
23
24 HELP: with-interactive-vocabs
25 { $values { "quot" quotation } }
26 { $description "Calls the quotation in a scope with an initial vocabulary search path consisting of all vocabularies from " { $link interactive-vocabs } ", and with the current vocabulary for new definitions set to " { $vocab-link "scratchpad" } "." }
27 { $notes "This is the same initial search path as used by the " { $link "listener" } " tool." } ;
28
29 HELP: show-var
30 { $values { "var" "a variable name" } }
31 { $description "Adds a variable to the watch list; its value will be printed by the listener after every expression." } ;
32
33 HELP: show-vars
34 { $values { "seq" "a sequence of variable names" } }
35 { $description "Adds a sequence of variables to the watch list; their values will be printed by the listener after every expression." } ;
36
37 HELP: hide-var
38 { $values { "var" "a variable name" } }
39 { $description "Removes a variable from the watch list." } ;
40
41 HELP: hide-vars
42 { $values { "seq" "a sequence of variable names" } }
43 { $description "Removes a sequence of variables from the watch list." } ;
44
45 HELP: hide-all-vars
46 { $description "Removes all variables from the watch list." } ;
47
48 ARTICLE: "listener" "The listener"
49 "The listener evaluates Factor expressions read from the input stream. Typically, you write Factor code in a text editor, load it from the listener by calling " { $link require } ", " { $link refresh-all } " or " { $link run-file } ", and then test it from interactively."
50 $nl
51 "The classical first program can be run in the listener:"
52 { $example "\"Hello, world\" print" "Hello, world" }
53 "New words can also be defined in the listener:"
54 { $example
55     "USE: math.functions"
56     ": twice ( word -- ) [ execute ] [ execute ] bi ; inline"
57     "81 \\ sqrt twice ."
58     "3"
59 }
60 "Multi-line expressions are supported:"
61 { $example "{ 1 2 3 } [\n    .\n] each" "1\n2\n3" }
62 "The listener will display the current contents of the datastack after every line of input."
63 $nl
64 "The listener can watch dynamic variables:"
65 { $subsections "listener-watch" }
66 "Nested listeners can be useful for testing code in other dynamic scopes. For example, when doing database maintanance using the " { $vocab-link "db.tuples" } " vocabulary, it can be useful to start a listener with a database connection:"
67 { $code
68     "USING: db db.sqlite listener ;"
69     "\"data.db\" <sqlite-db> [ listener ] with-db"
70 }
71 "Starting a nested listener:"
72 { $subsections listener }
73 "To exit a listener, invoke the " { $link return } " word."
74 $nl
75 "The listener's mechanism for reading multi-line expressions from the input stream can be called from user code:"
76 { $subsections read-quot } ;
77
78 ABOUT: "listener"
79
80 HELP: read-quot
81 { $values { "quot/f" "a parsed quotation, or " { $link f } " indicating end of file" } }
82 { $description "Reads a Factor expression which possibly spans more than one line from " { $link input-stream } ". Additional lines of input are read while the parser stack height is greater than one. Since structural parsing words push partial quotations on the stack, this will keep on reading input until all delimited parsing words are terminated." } ;
83
84 HELP: listener
85 { $description "Prompts for expressions on " { $link input-stream } " and evaluates them until end of file is reached." } ;