Paste: Not getting MACRO:

Author: Jim Mack
Mode: factor
Date: Fri, 15 Jan 2010 07:44:49
Plain Text |
USING: accessors arrays kernel locals present select8.html classes.tuple
sequences prettyprint fry macros nested-comments combinators ;

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>> ] } } ;
        
: non-macro-way ( tpl -- ) 
        {
        [ "First Name " write  firstname>> print ]
        [ "Last Name " write lastname>> print ]
        [ "Age " write  age>> present print ]
        } cleave ;

testdata non-macro-way

! using fry
  
testdata { } clone
 testing-schema [ first2 '[ _ write  @ present print ] suffix ] each 
  cleave 

MACRO: easier ( alist -- ) { } clone swap
    [ first2 '[ _ write  @ present print ] suffix ] each cleave ;           
   
: fancyprint ( tpl -- )
        testing-schema easier  ; inline

testdata fancyprint   ! stack underflow


   

New Annotation

Summary:
Author:
Mode:
Body: