In Prolog, it is fairly easy to define your own control structures using meta-predicates (predicates that take targets or predicates as arguments).
For example, you can implement a switch design, for example
switch(X, [ a : writeln(case1), b : writeln(case2), c : writeln(case3) ])
defining
switch(X, [Val:Goal|Cases]) :- ( X=Val -> call(Goal) ; switch(X, Cases) ).
If necessary, this can be more efficient due to compilation time conversion supported by many Prolog systems ( inline / 2 in ECLiPSe, or target extension in several other systems).
And through operator declarations, you can customize the syntax for just about anything.
jschimpf
source share