Paste: Working with macros
Author: | Jim Mack |
Mode: | factor |
Date: | Mon, 18 Jan 2010 21:37:53 |
Plain Text |
USING: accessors arrays kernel locals present classes.tuple io
sequences prettyprint fry macros nested-comments combinators ;
IN: learn
: package ( content id name class -- html ) 4array ;
: .<> ( seq -- ) . ;
: id-for-html ( tpl -- id ) id>> present "." prepend ;
TUPLE: testing id firstname lastname age ;
: <testing> ( id fn ln age -- tpl ) testing boa ;
: testdata ( -- tpl ) 1 "jim" "mack" 46 <testing> ;
: testing-schema ( -- seq )
{ { "First Name" [ firstname>> ] }
{ "Last Name" [ lastname>> ] }
{ "Age" [ age>> ] } } ; inline
: manual-row ( tpl -- seq )
V{ } clone swap {
[ [ firstname>> ] [ id-for-html ] bi "firstname" dup package suffix ]
[ [ lastname>> ] [ id-for-html ] bi "lastname" dup package suffix ]
[ [ age>> ] [ id-for-html ] bi "age" dup package suffix ]
} cleave ;
testdata manual-row .
: t1 ( -- ) testdata manual-row . ;
MACRO: manual-row2 ( tpl -- seq )
[
V{ } clone swap {
[ [ firstname>> ] [ id-for-html ] bi "firstname" dup package suffix ]
[ [ lastname>> ] [ id-for-html ] bi "lastname" dup package suffix ]
[ [ age>> ] [ id-for-html ] bi "age" dup package suffix ]
} cleave
] ; inline
testdata manual-row2 .
: t2 ( -- ) testdata manual-row2 . ;
Author: | Jim Mack |
Mode: | factor |
Date: | Mon, 18 Jan 2010 21:50:25 |
Plain Text |
USING: accessors arrays kernel locals present classes.tuple io
sequences prettyprint fry macros nested-comments combinators ;
IN: learn
: package ( content id name class -- html ) 4array ;
: .<> ( seq -- ) . ;
: id-for-html ( tpl -- id ) id>> present "." prepend ;
TUPLE: testing id firstname lastname age ;
: <testing> ( id fn ln age -- tpl ) testing boa ;
: testdata ( -- tpl ) 1 "jim" "mack" 46 <testing> ;
: testing-schema ( -- seq )
{ { "First Name" [ firstname>> ] }
{ "Last Name" [ lastname>> ] }
{ "Age" [ age>> ] } } ; inline
: manual-row ( tpl -- seq )
V{ } clone swap {
[ [ firstname>> ] [ id-for-html ] bi "firstname" dup package suffix ]
[ [ lastname>> ] [ id-for-html ] bi "lastname" dup package suffix ]
[ [ age>> ] [ id-for-html ] bi "age" dup package suffix ]
} cleave ;
testdata manual-row .
: t1 ( -- ) testdata manual-row . ;
MACRO: manual-row2 ( -- )
[
V{ } clone swap {
[ [ firstname>> ] [ id-for-html ] bi "firstname" dup package suffix ]
[ [ lastname>> ] [ id-for-html ] bi "lastname" dup package suffix ]
[ [ age>> ] [ id-for-html ] bi "age" dup package suffix ]
} cleave
] ; inline
testdata manual-row2 .
: t2 ( -- ) testdata manual-row2 . ;
New Annotation