Constrained genericity: Difference between revisions

(Nimrod -> Nim)
Line 1,007:
<lang swift>func foo<T: Eatable>(x: T) { }
// although in this case this is no more useful than just "func foo(x: Eatable)"</lang>
 
=={{header|zkl}}==
zkl isn't statically typed so the test is done at runtime.
 
This is a slightly different take on the task, keeping the editables and rejecting the garbage.
<lang zkl>class Eatable{ var v;
fcn eat{ println("munching ",self.topdog.name); }
}
class FoodBox{
fcn init(food1,food2,etc){
editable,garbage:=vm.arglist.filter22("isChildOf",Eatable);
var contents=editable;
if(garbage) println("Rejecting: ",garbage);
}
}</lang>
<lang zkl>class Apple(Eatable){} class Nuts(Eatable){} class Foo{}
FoodBox(Apple,"boogers",Nuts,Foo).contents.apply2("eat");</lang>
{{out}}
<pre>
Rejecting: L("boogers",Class(Foo))
munching Apple
munching Nuts
</pre>
 
<!-- Place omit from templates below here -->
Anonymous user