1 USING: arrays generic generic.single growable kernel math
2 namespaces sequences strings tools.test vectors words ;
6 HOOK: my-hook my-var ( -- x )
8 M: integer my-hook "an integer" ;
9 M: string my-hook "a string" ;
11 [ "an integer" ] [ 3 my-var set my-hook ] unit-test
12 [ "a string" ] [ my-hook my-var set my-hook ] unit-test
13 [ 1.0 my-var set my-hook ] [ T{ no-method f 1.0 my-hook } = ] must-fail-with
15 HOOK: call-next-hooker my-var ( -- x )
17 M: sequence call-next-hooker "sequence" ;
19 M: array call-next-hooker call-next-method "array " prepend ;
21 M: vector call-next-hooker call-next-method "vector " prepend ;
23 M: growable call-next-hooker call-next-method "growable " prepend ;
25 [ "vector growable sequence" ] [
26 V{ } my-var [ call-next-hooker ] with-variable
30 { } \ nth effective-method nip M\ sequence nth eq?
34 \ + \ nth effective-method nip dup \ nth "default-method" word-prop eq? and