1 USING: generic help.markup help.syntax sequences math
6 { $values { "object" "an object" } { "generic" "a generic word" } }
7 { $description "Throws a " { $link no-method } " error." }
8 { $error-description "Thrown by the " { $snippet "generic" } " word to indicate it does not have a method for the class of " { $snippet "object" } "." } ;
10 HELP: standard-combination
12 "Performs standard method combination."
14 "Generic words using the standard method combination dispatch on the class of the object at the given stack position, where 0 is the top of the stack, 1 is the object underneath, and 2 is the next one under that. A " { $link no-method } " error is thrown if no suitable method is defined on the class."
17 "A generic word for append strings and characters to a sequence, dispatching on the object underneath the top of the stack:"
19 "GENERIC# build-string 1 ( elt str -- )"
20 "M: string build-string swap push-all ;"
21 "M: integer build-string push ;"
25 HELP: hook-combination
27 "Performs hook method combination . See " { $link POSTPONE: HOOK: } "."
30 HELP: define-simple-generic
31 { $values { "word" "a word" } }
32 { $description "Defines a generic word with the " { $link standard-combination } " method combination and a dispatch position of 0." } ;
34 { standard-combination hook-combination } related-words
36 HELP: inconsistent-next-method
37 { $error-description "Thrown by " { $link POSTPONE: call-next-method } " if the values on the stack are not compatible with the current method." }
39 "The following code throws this error:"
41 "GENERIC: error-test ( object -- )"
43 "M: string error-test print ;"
45 "M: integer error-test number>string call-next-method ;"
49 "This results in the method on " { $link integer } " being called, which then passes a string to " { $link POSTPONE: call-next-method } ". However, this fails because the string is not compatible with the current method."
51 "This usually indicates programmer error; if the intention above was to call the string method on the result of " { $link number>string } ", the code should be rewritten as follows:"
52 { $code "M: integer error-test number>string error-test ;" }