]> gitweb.factorcode.org Git - factor.git/blob - extra/namespaces/lib/lib.factor
851f60d126ebd039c8130e27a58ab9803a582d84
[factor.git] / extra / namespaces / lib / lib.factor
1
2 ! USING: kernel quotations namespaces sequences assocs.lib ;
3
4 USING: kernel namespaces namespaces.private quotations sequences
5        assocs.lib math.parser math sequences.lib locals mirrors ;
6
7 IN: namespaces.lib
8
9 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10
11 : save-namestack ( quot -- ) namestack >r call r> set-namestack ;
12
13 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14
15 : make* ( seq -- seq ) [ dup quotation? [ call ] [ ] if ] map ;
16
17 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
18
19 : set* ( val var -- ) namestack* set-assoc-stack ;
20
21 SYMBOL: building-seq 
22 : get-building-seq ( n -- seq )
23     building-seq get nth ;
24
25 : n, get-building-seq push ;
26 : n% get-building-seq push-all ;
27 : n# >r number>string r> n% ;
28
29 : 0, 0 n, ;
30 : 0% 0 n% ;
31 : 0# 0 n# ;
32 : 1, 1 n, ;
33 : 1% 1 n% ;
34 : 1# 1 n# ;
35 : 2, 2 n, ;
36 : 2% 2 n% ;
37 : 2# 2 n# ;
38 : 3, 3 n, ;
39 : 3% 3 n% ;
40 : 3# 3 n# ;
41 : 4, 4 n, ;
42 : 4% 4 n% ;
43 : 4# 4 n# ;
44
45 MACRO:: nmake ( quot exemplars -- )
46     [let | n [ exemplars length ] |
47         [
48             [
49                 exemplars
50                 [ 0 swap new-resizable ] map
51                 building-seq set
52
53                 quot call
54
55                 building-seq get
56                 exemplars [ like ] 2map
57                 n firstn
58             ] with-scope
59         ]
60     ] ;
61
62 : make-object ( quot class -- object )
63     new [ <mirror> swap bind ] keep ; inline
64
65 : with-object ( object quot -- )
66     [ <mirror> ] dip bind ; inline