From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id CAA00596 for caml-redistribution; Fri, 2 Jul 1999 02:22:55 +0200 (MET DST) 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 AAA22398 for ; Fri, 2 Jul 1999 00:35:52 +0200 (MET DST) Received: from miss.wu-wien.ac.at (miss.wu-wien.ac.at [137.208.107.17]) by nez-perce.inria.fr (8.8.7/8.8.7) with ESMTP id AAA25339; Fri, 2 Jul 1999 00:35:49 +0200 (MET DST) Received: (from mottl@localhost) by miss.wu-wien.ac.at (8.9.0/8.9.0) id AAA05846; Fri, 2 Jul 1999 00:35:44 +0200 (MET DST) From: Markus Mottl Message-Id: <199907012235.AAA05846@miss.wu-wien.ac.at> Subject: Re: Sys.argv with interpreter and compiler To: Xavier.Leroy@inria.fr (Xavier Leroy) Date: Fri, 2 Jul 1999 00:35:44 +0100 (MET DST) Cc: caml-list@inria.fr (OCAML) In-Reply-To: <19990701193222.56286@pauillac.inria.fr> from "Xavier Leroy" at Jul 1, 99 07:32:22 pm X-Mailer: ELM [version 2.4 PL21] MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Sender: weis > > Wouldn't it be logically more consistent to pass the truncated array > > of arguments to the script under the interpreter so that the program > > always gets its name on index 0 - no matter whether it is compiled > > or interpreted? > > Yes, it would be more consistent, but that's exactly what it does > currently. At least, that's what a quick test under Linux shows. > > > - With the current version it gets the name of the > > interpreter on this position. > > That's surprising. On which operating system do you see this > behavior? The treatment of argv[0] in C w.r.t. #! scripts differs > between various versions of Unix, but we tried to compensate for this > in the OCaml bytecode interpreter. My explanation may probably be misconceived - maybe "interpreted" means "interpreted by the byte code interpreter" to you whereas I use "compiled" for byte code and native code and "interpreted" if I call the interactive toplevel with a file argument. Anyhow, I have made a test on two systems (Intel/Linux and Alpha/Digital Unix) with ocaml-2.02-2. Both systems behaved exactly the same way, but I got three different outputs for the three ways to execute the program. The output of this program (bla.ml): print_endline Sys.argv.(0) yielded: interpreted: /home/mottl/mysys/bin/ocaml compiled to byte code: ./bla compiled to native code: bla The difference between the byte code and native code version is probably not so big a problem. But it would be useful for the development process if the "interpreted" version would pass the arguments at the same index in the argument vector. As far as I remember, making OCaml (at least under Unix) a "true" scripting-language (=with human-readable "#!"-scripts) is not so easy to achieve: only binaries may be used as interpreters of "#!"-scripts, which is not currently possible with the way the toplevel "ocaml" is designed - it needs to be a byte code file. Are there already any convenient ways around this problem? Using byte code for scripting is not so comfortable and I think that OCaml would give a wonderful language for "true" scripting... Best regards, Markus Mottl -- Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl