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 SAA00083; Thu, 11 Sep 2003 18:28:13 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id SAA31423 for ; Thu, 11 Sep 2003 18:28:12 +0200 (MET DST) Received: from aomori.annexia.org (annexia.force9.co.uk [212.56.101.183]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id h8BGSBf26868 for ; Thu, 11 Sep 2003 18:28:11 +0200 (MET DST) Received: from rich by aomori.annexia.org with local (Exim 3.36 #1 (Debian)) id 19xUIk-0007A6-00 for ; Thu, 11 Sep 2003 17:28:10 +0100 Date: Thu, 11 Sep 2003 17:28:10 +0100 Cc: caml-list@inria.fr Subject: Re: [Caml-list] How to avoid compiling some code (like #ifdef in C) Message-ID: <20030911162810.GA27415@redhat.com> References: <87llswpnvn.fsf@linux-france.org> <20030911173056.A29749@pauillac.inria.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030911173056.A29749@pauillac.inria.fr> User-Agent: Mutt/1.5.4i From: Richard Jones X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 type-checked:01 type-checked:01 submenu:99 submenu:99 accel:01 callback:01 runtime:01 runtime:01 lablgtk:01 gmisc:01 lablgtk:01 gmisc:01 api:01 freshmeat:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thu, Sep 11, 2003 at 05:30:56PM +0200, Xavier Leroy wrote: > Whether this is a "better" approach is open to debate. With a > preprocessor, you can remove not just code for expressions, but also > other kind of code, e.g. code for the toplevel binding "let a() = ...". > So, you get more flexibility, but at the expense of less static > checking. In particular, code that is #ifdef-ed out is not > type-checked, while it is type-checked in your solution above. However one place where the cpp approach is very useful (and better) is code such as this: let simulation_menu = factory#add_submenu "Simulation" in #ifdef DEBUG let debug_menu = factory#add_submenu "Debug" in #endif let help_menu = factory#add_submenu "Help" in (*...*) #ifdef DEBUG let factory = new GMenu.factory debug_menu ~accel_group in factory#add_item "Single Step (1 Event)" ~key:GdkKeysyms._T ~callback:single_step_ev_sim; #endif I haven't found a satisfactory alternative to the above code which doesn't cause possible runtime errors. eg. One alternative is: let debug_menu = if debug then Some (...) else None in (*...*) match debug_menu with None -> () | Some menu -> (* code to populate the menu *) but this is not just tedious in real life, but also could have bugs only discovered at runtime. I'm open to a better way to do this ... Another important case in our program: #if LABLGTK_RELEASE let icon icon_type size = let icon = GMisc.image () in icon#set_stock icon_type ~size:size; icon #else (* LABLGTK from CVS: *) let icon icon_type size = let icon = GMisc.image () in icon#set_stock icon_type; icon#set_icon_size size; icon #endif These sorts of API changes are *really* hard to work around without a preprocessor, unless you have two separate modules and play tricks in the Makefile. Again, I'm open to suggestions as to how to do this better. Rich. -- Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you. MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles, RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/ ------------------- 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