From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA10414; Tue, 22 May 2001 18:33:45 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA10409 for ; Tue, 22 May 2001 18:33:44 +0200 (MET DST) Received: from www.invert.com (invert.com [209.164.21.15]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f4MGXhH08851 for ; Tue, 22 May 2001 18:33:43 +0200 (MET DST) Received: (from miles@localhost) by www.invert.com (8.10.1/8.10.1AA) id f4MGXf097538 for caml-list@inria.fr; Tue, 22 May 2001 09:33:41 -0700 (PDT) (envelope-from miles) Date: Tue, 22 May 2001 09:33:41 -0700 From: Miles Egan To: caml-list@inria.fr Subject: [Caml-list] lisp -> ocaml Message-ID: <20010522093341.A97425@caddr.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk For my own edification I've been translating some of the code from Norvig's PAIP AI text to get an idea of what this kind of code looks like in OCaml and I've come up against two small problems. First, I have two mutually recursive function definitions: let apply_op op = if (Stateset.for_all achieve op.op_preconds) then begin print_endline ("executing " ^ op.op_action); global_state := Stateset.diff !global_state op.op_dellist; global_state := Stateset.union !global_state op.op_addlist; true end else false let achieve goal ops = Stateset.mem goal global_state or List.exists apply_op (List.filter (appropriate_p goal) ops) Which fails to compile, for obvious reasons. Is the solution to refactor the code into a nonrecursive form? In the absence of forward declarations, I'm not sure what else to do. Second, the PAIP code makes fairly heavy use of Lisp's symbolic features and uses symbols as a kind of type tag but also as printable strings. I've been using variants, both traditional and polymorphic, as a substitute, but they're not really quite equivalent. For example, one of the first programs is a simple implementation of the old GPS (general problem solver), which manipulates sets of states. Lisp provides set operations on lists and allows printing of symbols, which makes it possible to both manipulate "state" lists and print them with very little code. I can't use variants with the same flexibility because I have to provide an explicit ordering if I want to use them as set members and I can't print them because there doesn't seem to be a way to print something like: type t = ONE | TWO | THREE as "ONE", "TWO", "THREE". I'm using strings in the meantime but this isn't very satisfying. -- miles ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr