RosettaCodeData/Task/Call-a-function/Ecstasy/call-a-function-8.ecstasy

17 lines
513 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
// Ecstasy does not have any built-in functions. However, there are two keywords
// ("is" and "as") that use a function-like syntax:
module IsAndAs {
Int|String foo() {
return "hello";
}
void run() {
@Inject Console console;
Object o = foo();
if (o.is(String)) { // <- looks like a function call
String s = o.as(String); // <- looks like a function call
console.print($"foo returned the string: {s.quoted()}");
}
}
}