TUPLE: stock-spread stock spread timestamp ;
-CONSTRUCTOR: stock-spread ( stock spread -- stock-spread )
+CONSTRUCTOR: <stock-spread> stock-spread ( stock spread -- stock-spread )
now >>timestamp ;
SYMBOL: AAPL
TUPLE: ct3 < ct2 c ;
TUPLE: ct4 < ct3 d ;
-DEFAULT-CONSTRUCTOR: ct1 ( a -- obj )
+CONSTRUCTOR: <ct1> ct1 ( a -- obj ) ;
-DEFAULT-CONSTRUCTOR: ct2 ( a b -- obj )
+CONSTRUCTOR: <ct2> ct2 ( a b -- obj ) ;
-DEFAULT-CONSTRUCTOR: ct3 ( a b c -- obj )
+CONSTRUCTOR: <ct3> ct3 ( a b c -- obj ) ;
-DEFAULT-CONSTRUCTOR: ct4 ( a b c d -- obj )
+CONSTRUCTOR: <ct4> ct4 ( a b c d -- obj ) ;
[ 1000 ] [ 1000 <ct1> a>> ] unit-test
[ 0 ] [ 0 0 <ct2> a>> ] unit-test
[ 0 ] [ 0 0 0 <ct3> a>> ] unit-test
[ 0 ] [ 0 0 0 0 <ct4> a>> ] unit-test
-NAMED-CONSTRUCTOR: <ct1!> ct1 ( a -- obj )
-
-NAMED-CONSTRUCTOR: <ct2!> ct2 ( a b -- obj )
-
-NAMED-CONSTRUCTOR: <ct3!> ct3 ( a b c -- obj )
-
-NAMED-CONSTRUCTOR: <ct4!> ct4 ( a b c d -- obj )
-
-[ 1000 ] [ 1000 <ct1!> a>> ] unit-test
-[ 0 ] [ 0 0 <ct2!> a>> ] unit-test
-[ 0 ] [ 0 0 0 <ct3!> a>> ] unit-test
-[ 0 ] [ 0 0 0 0 <ct4!> a>> ] unit-test
TUPLE: monster
{ name string read-only } { hp integer } { max-hp integer read-only }
TUPLE: b-monster < monster ;
<<
-CONSTRUCTOR-SYNTAX: a-monster
+SLOT-CONSTRUCTOR: a-monster
>>
: <a-monster> ( name hp max-hp -- obj )
"""USE: constructors
IN: constructors.tests
TUPLE: foo a b ;
-DEFAULT-CONSTRUCTOR: foo ( a a -- obj )""" eval( -- )
+CONSTRUCTOR: <foo> foo ( a a -- obj )""" eval( -- )
] [
error>> repeated-constructor-parameters?
] must-fail-with
"""USE: constructors
IN: constructors.tests
TUPLE: foo a b ;
-DEFAULT-CONSTRUCTOR: foo ( a c -- obj )""" eval( -- )
+CONSTRUCTOR: <foo> foo ( a c -- obj )""" eval( -- )
] [
error>> unknown-constructor-parameters?
] must-fail-with
create-in dup reset-generic ;
: scan-constructor ( -- word class )
- scan-word [ name>> "<" ">" surround create-function ] keep ;
+ scan-new-word scan-class ;
: parse-constructor ( -- word class effect def )
scan-constructor scan-effect ensure-constructor-parameters
: scan-full-input-effect ( -- effect )
"(" expect scan-rest-input-effect ;
-SYNTAX: NAMED-CONSTRUCTOR:
- scan-new-word scan-word scan-effect define-constructor ;
-
-SYNTAX: DEFAULT-CONSTRUCTOR:
- scan-constructor scan-effect define-constructor ;
-
-SYNTAX: CONSTRUCTOR-SYNTAX:
- scan-word [ name>> "(" append create-reset ] keep
+SYNTAX: SLOT-CONSTRUCTOR:
+ scan-new-word [ name>> "(" append create-reset ] keep
'[ scan-rest-input-effect in>> _ '[ _ _ slots>boa ] append! ] define-syntax ;