Send an unknown method call: Difference between revisions
Content added Content deleted
(Add Factor example) |
|||
Line 152: | Line 152: | ||
foo(5) = 47 |
foo(5) = 47 |
||
</pre> |
</pre> |
||
=={{header|Factor}}== |
|||
Factor's object model is such that objects themselves don't contain methods — generic words do. So there is nothing different about invoking an unknown method than invoking an unknown word in general. |
|||
<lang factor>USING: accessors kernel math prettyprint sequences words ; |
|||
IN: rosetta-code.unknown-method-call |
|||
TUPLE: foo num ; |
|||
C: <foo> foo |
|||
GENERIC: add5 ( x -- y ) |
|||
M: foo add5 num>> 5 + ; |
|||
42 <foo> ! construct a foo |
|||
"add" "5" append ! construct a word name |
|||
! must specify vocab to look up a word |
|||
"rosetta-code.unknown-method-call" |
|||
lookup-word execute . ! 47</lang> |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |