Respond to an unknown method call: Difference between revisions

(→‎{{header|Tcl}}: Omit Purebasic)
Line 20:
<lang lisp>("Do something to 3."
"No method for #<STANDARD-GENERIC-FUNCTION DO-SOMETHING 214FC042> on (4).")</lang>
 
=={{header|D}}==
D v.2. code, from the Python version. D performs this statically.
<lang d>import std.stdio: write, writeln;
 
struct Example {
void foo() { writeln("this is foo"); }
void bar() { writeln("this is bar"); }
void opDispatch(string name, Types...)(Types args) {
write("tried to handle unknown method ", name);
if (Types.length) {
write(", it had arguments: ");
foreach (arg; args)
write(arg, " ");
}
writeln();
}
}
 
void main() {
Example example;
example.foo(); // this is foo
example.bar(); // this is bar
example.grill(); // tried to handle unknown method grill
example.ding("dong"); // tried to handle unknown method ding, it had arguments: dong
}</lang>
 
=={{header|E}}==
Anonymous user