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 LAA08630; Thu, 23 Jan 2003 11:27:22 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA08673 for caml-list@pauillac.inria.fr; Thu, 23 Jan 2003 11:27:22 +0100 (MET) 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 RAA20096 for ; Wed, 22 Jan 2003 17:35:16 +0100 (MET) Received: from main.gmane.org (main.gmane.org [80.91.224.249]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id h0MGZFv05925 for ; Wed, 22 Jan 2003 17:35:15 +0100 (MET) Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18bNoq-0001Ma-00 for ; Wed, 22 Jan 2003 17:33:40 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr Received: from news by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 18bNom-0001M8-00 for ; Wed, 22 Jan 2003 17:33:36 +0100 From: michael-grunewald@wanadoo.fr (=?iso-8859-15?q?Micha=EBl_Gr=FCnewald?=) Subject: [Caml-list] Re: load modules by name Date: 22 Jan 2003 17:41:35 +0100 Organization: (none) Message-ID: <87y95duog0.fsf@ketanu.dyndns.org> References: <20030121072228.GA6481@anu.edu.au> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@main.gmane.org User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Pietro Abate writes: > hi list, > > I'm trying to figure out how I can build a kind of associative list > to load a specific module at runtime. I've reread few old messages about > first-class modules and other oddities, but I've the sensation my > problem is easier. > > I have a library (compiled), an application (compiled) and a bunch of > user defined modules (that are compiled as well, but these may be vary > in number). At the moment the application select the rigth module > statically regarding a command line argument. However this way I must > recompile my application everytime I add a new module. Why don't you build a little bunch of software that maintain a 'record book' of given modules/files? Thus the client software find easily a list in the 'record book', while you just need to update this book each time you add a new algorithm into your collection (or remove one). In the main code part, you may have a module module Algo = struct type t = int -> int list (* e.g. *) type id = int let assoc = ref [] (* (id * algo) list -- assoc *) let subscribe a b = assoc := (a,b) :: !assoc let get i = List.assoc i !assoc end each module dynamically loaded has a registration part that says let _ = Algo.subscription my_id my_algo where my_id is an unique identification key known in the record book, thus you can get back the algorithm with the Algo.get function, while you keep away from your code any reference to hardwired module name. -- Michaël Grünewald ------------------- 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