Hi,

I have the need to use some logical programming functionality within my
application. I would like to embed this into my Ocaml code as a domain
specific language. I am contemplating the use of Camlp4 for this. My
main concern is the effort this will require. I am not concerned so much
in the implementation effort of parsing and processing the logical part
of the code (cannot escape that) but in evaluating the work required to
use Camlp4.

Below I have some examples of what I am considering. Note that I use "|"
as a delimiting token to identify the embedded language. Within these
delimiters I aim to use menhir/ocamllex/ocamlyacc to generate compile
time data-structures and then output calls to the logical sub-system.
The calls will effectively perform the logical evaluation of horn
clauses.

My questions are:

1. Is this feasible?
2. Does it require much effort (any one venture an estimate)?
3. Is the syntax I show acceptable (any suggestions)?


I would appreciate any input.
TIA,
Hugo Ferreira.



--------------------------------------------
Examples
--------------------------------------------


(* Example of a query *)
let prog = |  f(a,b).
               f(b,c).

               g(X,Y):- f(X,Z), f(Z,Y) |        in
let result = prog:|  g(X,Y), g(X,X)   | (* conjunction, not a tuple *)
in
    result


(* Example of unification  *)
let    prog = | |                       in
let   inst1 = prog:|| h(a,X,Y,d) ||     in
let   inst2 = prog:|| h(X,b,c,Y) ||     in
let result1 = inst1 .= inst2                    (* [EMAIL PROTECTED], =:= *)
in
    result (* returns the unified instance and the mgu *)

(* Example of list of terms  *)
let    prog = | |                               in (* empty *)
let   inst1 = prog:|[ h(a,X,Y,d); i(X,b) ]|     in
let   inst2 = prog:|[ h(X,b,c,Y); i(a,X) ]|     in
                            (* tuples use "|(", arrays "|[|" *)
let rec loop l1 l2 r =
        match l with
        | h1::t1, h2::l2 -> loop ( h1 .= h2 )::r
        | r
in
    loop inst1 inst2 []


(* Instantiating terms  *)
let    prog = | |                               in
let   expr1 = || [h(a,X,Y,d), i(X,b)] ||        in
let   expr2 = || [h(X,b,c,Y), i(a,X)] ||        in
let   inst1 = prog:| expr1 |                    in
let   inst2 = prog:| expr2 |                    in
let  result = inst1 .= inst2
in
    result



(* Backtracking  *)
let      p0 = | |                       in
let   expr1 = || h(a,X,Y,d) ||          in
let   expr2 = || h(X,b,c,Y) ||          in
let   expr3 = || h(X,Y,c,d) ||          in
let (p0,i1) = p0:| expr1 |              in(* uses the result of previous 
processing *)
let (p1,i2) = p0:| expr2 |              in(* uses the result of previous 
processing *)
let  result = inst1 .= inst2            in
let  result = if .! result then (* try another option *)
                                 let inst1 = p0:| expr1 |       in
                                 let inst2 = p1:| expr1 |       in
                                in
                                   result




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html
-~----------~----~----~----~------~----~------~--~---

Reply via email to