]> gitweb.factorcode.org Git - factor.git/blob - basis/macros/macros.factor
Create basis vocab root
[factor.git] / basis / macros / macros.factor
1 ! Copyright (C) 2007, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: parser kernel sequences words effects
4 inference.transforms combinators assocs definitions quotations
5 namespaces memoize ;
6 IN: macros
7
8 : real-macro-effect ( word -- effect' )
9     "declared-effect" word-prop effect-in 1 <effect> ;
10
11 : define-macro ( word definition -- )
12     over "declared-effect" word-prop effect-in length >r
13     2dup "macro" set-word-prop
14     2dup over real-macro-effect memoize-quot [ call ] append define
15     r> define-transform ;
16
17 : MACRO:
18     (:) define-macro ; parsing
19
20 PREDICATE: macro < word "macro" word-prop >boolean ;
21
22 M: macro definer drop \ MACRO: \ ; ;
23
24 M: macro definition "macro" word-prop ;
25
26 M: macro reset-word
27     [ call-next-method ] [ f "macro" set-word-prop ] bi ;
28
29 : macro-expand ( ... word -- quot ) "macro" word-prop call ;
30
31 : n*quot ( n seq -- seq' ) <repetition> concat >quotation ;
32
33 : saver ( n -- quot ) \ >r <repetition> >quotation ;
34
35 : restorer ( n -- quot ) \ r> <repetition> >quotation ;