Clean up CONSTRUCTOR: with Dan's idea: introduce set-slots and construct macros

db4
Slava Pestov 2009-01-30 14:56:44 -06:00
parent fbc69718a7
commit c1347699c4
1 changed files with 7 additions and 5 deletions

View File

@ -1,17 +1,19 @@
! Copyright (C) 2009 Slava Pestov. ! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: slots kernel sequences fry accessors parser lexer words USING: slots kernel sequences fry accessors parser lexer words
effects.parser ; effects.parser macros ;
IN: constructors IN: constructors
! An experiment ! An experiment
: constructor-quot ( class slot-names body -- quot ) MACRO: set-slots ( slots -- quot )
[ <reversed> [ setter-word '[ swap _ execute ] ] map [ ] join ] dip <reversed> [ setter-word '[ swap _ execute ] ] map [ ] join ;
'[ _ new @ @ ] ;
: construct ( ... class slots -- instance )
[ new ] dip set-slots ; inline
: define-constructor ( name class effect body -- ) : define-constructor ( name class effect body -- )
[ [ in>> ] dip constructor-quot ] [ drop ] 2bi [ [ in>> ] dip '[ _ _ construct @ ] ] [ drop ] 2bi
define-declared ; define-declared ;
: CONSTRUCTOR: : CONSTRUCTOR: