next up previous
Next: 13.8 Problem solving with Up: 13 The Blackboard Previous: 13.6 Overriding

13.7 Language enhancements based on linear implication

Linear implication can be used to quickly add some language enhancements to a Prolog system. For instance, to add a switch tex2html_wrap_inline14789 case statement one can write simply:

switch(Selector,Body):-
  case(Selector)-:Body.

test(X):-
  switch(X, (
     case(1)->write(one) ;
     case(2)->write(two) ;
     otherwise->write(unexpected(X))
  ))
 ,nl.

% ?-test(2),test(13).

Clearly, this is a very compact way, useful at least as a specification. Note that this can be done as well with macro expansion, possibly more efficiently, but also with much more work.



next up previous
Next: 13.8 Problem solving with Up: 13 The Blackboard Previous: 13.6 Overriding



Paul Tarau
Thu Apr 3 10:26:39 AST 1997