CDE
This commit is contained in:
parent
518da4a923
commit
764da6cbbb
6144 changed files with 83610 additions and 11 deletions
14
Task/Constrained-genericity/E/constrained-genericity.e
Normal file
14
Task/Constrained-genericity/E/constrained-genericity.e
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
/** Guard accepting only objects with an 'eat' method */
|
||||
def Eatable {
|
||||
to coerce(specimen, ejector) {
|
||||
if (Ref.isNear(specimen) && specimen.__respondsTo("eat", 0)) {
|
||||
return specimen
|
||||
} else {
|
||||
throw.eject(ejector, `inedible: $specimen`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def makeFoodBox() {
|
||||
return [].diverge(Eatable) # A guard-constrained list
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue