From c1347699c407ea0eb8310a414c5cd44694dddcc2 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 30 Jan 2009 14:56:44 -0600 Subject: [PATCH] Clean up CONSTRUCTOR: with Dan's idea: introduce set-slots and construct macros --- extra/constructors/constructors.factor | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/extra/constructors/constructors.factor b/extra/constructors/constructors.factor index 6968fd7eda..30d286eb96 100644 --- a/extra/constructors/constructors.factor +++ b/extra/constructors/constructors.factor @@ -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 ) - [ [ setter-word '[ swap _ execute ] ] map [ ] join ] dip - '[ _ new @ @ ] ; +MACRO: set-slots ( slots -- quot ) + [ 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: