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 UAA14201; Fri, 10 Jan 2003 20:14:12 +0100 (MET) 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 UAA14136 for ; Fri, 10 Jan 2003 20:14:10 +0100 (MET) Received: from c007.snv.cp.net (h000.c007.snv.cp.net [209.228.33.228]) by nez-perce.inria.fr (8.11.1/8.11.1) with SMTP id h0AJE9527521 for ; Fri, 10 Jan 2003 20:14:09 +0100 (MET) Received: (cpmta 28337 invoked from network); 10 Jan 2003 11:14:07 -0800 Received: from 65.187.194.217 (HELO localhost) by smtp.directvinternet.com (209.228.33.228) with SMTP; 10 Jan 2003 11:14:07 -0800 X-Sent: 10 Jan 2003 19:14:07 GMT Date: Fri, 10 Jan 2003 14:14:14 -0500 Mime-Version: 1.0 (Apple Message framework v482) Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: [Caml-list] camlp4: ONCE construct From: jehenrik To: caml-list@inria.fr Content-Transfer-Encoding: 7bit Message-Id: X-Mailer: Apple Mail (2.482) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hi, I would like to write a Camlp4 construct which causes its argument to only be evaluated once. Eg: ... ... ... ONCE Pcre.regexp "([0-9]+)" would be transformed to: let gensym000 = Pcre.regexp "([0-9]+)";; ... ... ... gensym000 but I don't see a way to get a nonlocal transformation like that. One way would be if the system had a way to side-effect out a new toplevel let while the expressions were transforming. I suspect that facility does not exist. Another way would be to have a second keyword (ONCEBLOCK or something?) that would go where the let bindings eventually would, which could take as an argument the entire expression tree containing ONCE declarations. Then after a complicated recursive parse on all the syntactic constructs, all the ONCEs could be located, enumerated, and removed. Note that I don't want to "memoize," or create a thunk which when evaluated the first time does something complicated and all subsequent times remembers what it did the first time. That still requires manually writing the let statements in a different code location. My goal is to improve readability by putting my regexps where they matter, not several screens up just so that they get cached at runtime. Thanks for any advice, Jeff Henrikson ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners