Clean up CONSTRUCTOR: with Dan's idea: introduce set-slots and construct macros
parent
fbc69718a7
commit
c1347699c4
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue