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