]> gitweb.factorcode.org Git - factor.git/blob - extra/display-stack/display-stack.factor
8da252f294576dca2b0cbfd1dbb8c5e51789d5ae
[factor.git] / extra / display-stack / display-stack.factor
1
2 USING: kernel namespaces sequences math
3        listener io prettyprint sequences.lib fry ;
4
5 IN: display-stack
6
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8
9 SYMBOL: watched-variables
10
11 : watch-var ( sym -- ) watched-variables get push ;
12
13 : watch-vars ( seq -- ) watched-variables get [ push ] curry each ;
14
15 : unwatch-var ( sym -- ) watched-variables get delete ;
16
17 : unwatch-vars ( seq -- ) watched-variables get [ delete ] curry each ;
18
19 : print-watched-variables ( -- )
20   watched-variables get length 0 >
21     [
22       "----------" print
23       watched-variables get
24         watched-variables get [ unparse ] map longest length 2 +
25         '[ [ unparse ": " append , 32 pad-right write ] [ get . ] bi ]
26       each
27
28     ]
29   when ;
30
31 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
32
33 : display-stack ( -- )
34   V{ } clone watched-variables set
35     [
36       print-watched-variables
37       "----------" print
38       datastack [ . ] each
39       "----------" print
40       retainstack reverse [ . ] each
41     ]
42   listener-hook set ;
43