Download Developing Applications with ECLiPSe
Transcript
CHAPTER 5. PROGRAMMING CONCEPTS 32 first or the last clause, the compiler will just treat this as another predicate definition with the same name, but a different arity. Errors of this form are very hard to spot. Example :-mode interface_type(+,+,-). interface_type(_Node,local,local):!. interface_type(Node,_Interface,backbone_net):node(Node,net), !. interface_type(Node,Interface,backbone):backbone_line(Node,Interface,_,_), !. interface_type(Node,Interface,backbone):backbone_line(_,_,Node,Interface), !. interface_type(Node,Interface,interconnection):group(interconnection,_,Node,Interface), !. interface_type(_Node,_Interface,customer). Here we branch on information passed in the first two arguments, and return a result in the last argument. The last clause is a default rule, saying that the interface type is customer, if none of the other rules applied. Some programmers perfer to make the output unification explicit, like so: :-mode interface_type(+,+,-). interface_type(_Node,local,Result):!, Result = local. interface_type(Node,_Interface,Result):node(Node,net), !, Result = backbone_net. interface_type(Node,Interface,Result):backbone_line(Node,Interface,_,_), !, Result = backbone. interface_type(Node,Interface,Result):backbone_line(_,_,Node,Interface),