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.
 | 
					! 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:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue