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 TAA25227; Thu, 28 Aug 2003 19:36:12 +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 TAA13825 for ; Thu, 28 Aug 2003 19:36:11 +0200 (MET DST) Received: from manzanita (63-217-154-71.greystoneapts.com [63.217.154.71]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h7SHa9T21495 for ; Thu, 28 Aug 2003 19:36:10 +0200 (MET DST) Received: from manzanita ([127.0.0.1] helo=ucdavis.edu) by manzanita with esmtp (Exim 3.36 #1 (Debian)) id 19sQei-0000VF-00 for ; Thu, 28 Aug 2003 10:33:56 -0700 Message-ID: <3F4E3D04.6040704@ucdavis.edu> Date: Thu, 28 Aug 2003 10:33:56 -0700 From: Issac Trotts Reply-To: ijtrotts@ucdavis.edu User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3) Gecko/20030319 Debian/1.3-3 X-Accept-Language: en MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] I need a C preprocessor References: <20030828160919.GA8257@redhat.com> In-Reply-To: <20030828160919.GA8257@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Loop: caml-list@inria.fr X-Spam: no; 0.00; issac:01 trotts:01 ijtrotts:01 caml-list:01 compile-time:01 submenu:99 accel:01 submenu:99 accel:01 ocamlc:01 prerr:01 endline:01 prerr:01 endline:01 camlp:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Richard Jones wrote: >Here is some code I've just written. CjsConfig.debug_menu is a >compile-time constant. > > let debug_menu = > if CjsConfig.debug_menu then > Some (factory#add_submenu "Debug") > else > None in > > (* ... *) > > let single_step_ev_item, single_step_res_item, step_to_item, > dump_hiertext_item = > match debug_menu with > None -> None, None, None, None > | Some debug_menu -> > let factory = new GMenu.factory debug_menu ~accel_group in > let single_step_ev_item = > factory#add_item "Single Step (1 Event)" > ~key:GdkKeysyms._T in > let single_step_res_item = > factory#add_item "Single Step (1 Result Period)" > ~key:GdkKeysyms._Z in > let step_to_item = factory#add_item "Step To ..." in > factory#add_separator (); > let dump_hiertext_item = > factory#add_item "Dump HierText To Console" > ~key:GdkKeysyms._H in > (Some single_step_ev_item, Some single_step_res_item, > Some step_to_item, Some dump_hiertext_item) > in > >Now in C I'd use the preprocessor: > >#ifdef DEBUG_MENU > factory#add_submenu "Debug" >#endif > >#ifdef DEBUG_MENU > let factory = new GMenu.factory debug_menu ~accel_group in > let single_step_ev_item = factory#add_item "Single Step (1 Event)" > (* etc. *) >#endif > >which results in briefer, faster and simpler to understand code. > >My question is what is the proper style for this sort of thing in >OCaml? > >Rich. > Here's one way, using the C preprocessor: (* gargle.ml ocamlc pp cpp -o gargle gargle.ml *) #define GARGLE #ifdef GARGLE let () = prerr_endline "gargle is defined!" #else let () = prerr_endline "gargle is not defined!" #endif Here's another way, using the camlp4 ifdef macro: (* gargle2.ml ocamlc -pp "camlp4o pa_o.cmo pa_ifdef.cmo pr_o.cmo" -o gargle2 gargle2.ml *) define GARGLE let () = ifdef GARGLE then prerr_endline "gargle is defined." else prerr_endline "gargle is not defined." Issac ------------------- 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