From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 6F740BC3F for ; Thu, 28 Oct 2004 00:13:18 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9RMDHfa013422 for ; Thu, 28 Oct 2004 00:13:18 +0200 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 AAA01973 for ; Thu, 28 Oct 2004 00:13:17 +0200 (MET DST) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.200]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id i9RMDGvS013417 for ; Thu, 28 Oct 2004 00:13:17 +0200 Received: by wproxy.gmail.com with SMTP id 64so397180wri for ; Wed, 27 Oct 2004 15:13:16 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=kjegdHs4Uag///bXe/fTe+bHvAP6FaWm8JtPlRn34HNrUVqNWdVXg81726+r86tln9a/7YTTEOJwyff6HDazEfsxSEoEJFPAJh9GRGkUiwNuElm7bo03lw93+U/FT/al0vMU+Llgm775PAjGPJGMDA/o0LSRvTbrzq7JEYF7dys= Received: by 10.38.163.52 with SMTP id l52mr1472808rne; Wed, 27 Oct 2004 15:13:16 -0700 (PDT) Received: by 10.38.14.54 with HTTP; Wed, 27 Oct 2004 15:13:15 -0700 (PDT) Message-ID: Date: Wed, 27 Oct 2004 18:13:15 -0400 From: John Prevost Reply-To: John Prevost To: caml-list@inria.fr, Thomas Fischbacher Subject: Re: [Caml-list] Arg parsing In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <20041026201338.GA29858@force.stwing.upenn.edu> X-Miltered: at nez-perce with ID 41801D7D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41801D7C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; prevost:01 prevost:01 caml-list:01 parsing:01 wrote:01 ocaml:01 toplevel:01 parses:01 ocaml:01 usr:01 argv:01 printf:01 printf:01 argv:01 -unsafe:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_BY_IP autolearn=disabled version=3.0.0 X-Spam-Level: On Wed, 27 Oct 2004 20:17:05 +0200 (CEST), Thomas Fischbacher wrote: > That's not what I mean. I want to be able to start "ocaml" in such a way > that I get the toplevel, but can #use code which parses the args that were > given originally to ocaml. The following works just fine for me: ---------- #!/usr/bin/env ocaml let _ = begin let arg_count = Array.length Sys.argv in Printf.printf "%s: received %d arguments\n" Sys.argv.(0) (arg_count - 1); for i = 1 to arg_count - 1 do Printf.printf "%2d: %s\n" i Sys.argv.(i) done end ---------- $ ocaml test.ml a b c test.ml: received 3 arguments 1: a 2: b 3: c $ ./test.ml a b c d e f g h ./test.ml: received 8 arguments 1: a 2: b 3: c 4: d 5: e 6: f 7: g 8: h The above works as long as you don't also want to give arguments to ocaml itself. If you want to do that, you may need a hack like the following: ------------ #!/bin/sh #labels true;; (* exec ocaml -dparsetree $0 $* # *) let _ = begin let arg_count = Array.length Sys.argv in Printf.printf "%s: received %d arguments\n" Sys.argv.(0) (arg_count - 1); for i = 1 to arg_count - 1 do Printf.printf "%2d: %s\n" i Sys.argv.(i) done end ------------ I'm not sure why you'd want to do that, though. The only useful argument that can't be duplicated with a #blah directive is "-unsafe". John.