caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] load modules by name
@ 2003-01-28 13:42 rich
  2003-01-28 15:56 ` Yann Régis-Gianas
  2003-01-28 17:47 ` Nicolas Cannasse
  0 siblings, 2 replies; 5+ messages in thread
From: rich @ 2003-01-28 13:42 UTC (permalink / raw)
  To: caml-list

It's possible I'm missing something here, but am I right in thinking
there's no way to do introspection on a module? eg. find out what
functions / classes it contains?

Rich.

-- 
Richard Jones
http://www.annexia.org/ Freshmeat projects: http://freshmeat.net/users/rwmj
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] load modules by name
  2003-01-28 13:42 [Caml-list] load modules by name rich
@ 2003-01-28 15:56 ` Yann Régis-Gianas
  2003-01-28 17:47 ` Nicolas Cannasse
  1 sibling, 0 replies; 5+ messages in thread
From: Yann Régis-Gianas @ 2003-01-28 15:56 UTC (permalink / raw)
  To: rich; +Cc: caml-list

Le Mardi 28 Janvier 2003 14:42, rich@annexia.org a écrit :
> It's possible I'm missing something here, but am I right in thinking
> there's no way to do introspection on a module? eg. find out what
> functions / classes it contains?

	Without its code, I think you cannot. If you have its code, use CamlP4.

-- 
Yann
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] load modules by name
  2003-01-28 13:42 [Caml-list] load modules by name rich
  2003-01-28 15:56 ` Yann Régis-Gianas
@ 2003-01-28 17:47 ` Nicolas Cannasse
  1 sibling, 0 replies; 5+ messages in thread
From: Nicolas Cannasse @ 2003-01-28 17:47 UTC (permalink / raw)
  To: rich, caml-list

> It's possible I'm missing something here, but am I right in thinking
> there's no way to do introspection on a module? eg. find out what
> functions / classes it contains?

You can also look into the CMI data to get informations from it (if
present)... but that won't help much since you can't dynamicly call
functions by their name.

Nicolas Cannasse

-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] load modules by name
  2003-01-21  7:22 Pietro Abate
@ 2003-01-21 10:48 ` Stefano Zacchiroli
  0 siblings, 0 replies; 5+ messages in thread
From: Stefano Zacchiroli @ 2003-01-21 10:48 UTC (permalink / raw)
  To: caml-list; +Cc: Pietro Abate

On Tue, Jan 21, 2003 at 06:22:28PM +1100, Pietro Abate wrote:
> is it possible ?

Yes, just use the Dynlink module.

You can find a great usage example in the O'Reilly book [1] (debian
package available in debian/unstable ocaml-book-{en,fr}).

Anyway, returning to your example you should have an association list
ref, say "algos", and you should use it as

  let algo =
    try
      List.assoc "command_line_option" !algos
   with Not_found -> failwith "Module not loaded"

Then you should have a set of .cmos that you should load using
'Dynlink.loadfile', each module should update the 'algos' association
list adding itself to it.

Hope this helps,
Cheers.

[1] http://caml.inria.fr/oreilly-book/html/

-- 
Stefano Zacchiroli  -  Undergraduate Student of CS @ Uni. Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it}  -  http://www.bononia.it/zack/
"  I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant!  " -- G.Romney
-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Caml-list] load modules by name
@ 2003-01-21  7:22 Pietro Abate
  2003-01-21 10:48 ` Stefano Zacchiroli
  0 siblings, 1 reply; 5+ messages in thread
From: Pietro Abate @ 2003-01-21  7:22 UTC (permalink / raw)
  To: caml-list

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.

What I'd like to do is reading all .cmo files (or .ml files and compile
them on the fly) in a directory and build a kind of assoc list with 
(name,module) and at runtime select the right module.

let's say that now I have

let algo = 
match command_line_option with
| "mod1" -> Module1.algo
| "mod2" -> Module2.algo
...
| _ -> failwith "module not defined"
in ...

but I'd rather have something like

let algo =
	try
		List.assoc "command_line_option" assoclist
	with Not_found -> failwith "Module not defined"
in ...

That would not require any recompilation of my application.

It would also nice to compile on the fly these modules...
I'm thinking of something like eval in perl...

is it possible ?

p

-------------------
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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-01-28 16:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-28 13:42 [Caml-list] load modules by name rich
2003-01-28 15:56 ` Yann Régis-Gianas
2003-01-28 17:47 ` Nicolas Cannasse
  -- strict thread matches above, loose matches on Subject: below --
2003-01-21  7:22 Pietro Abate
2003-01-21 10:48 ` Stefano Zacchiroli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).