From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 959A47FAED for ; Mon, 24 Nov 2014 19:17:20 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.214.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.214.173 as permitted sender) identity=mailfrom; client-ip=209.85.214.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ob0-f173.google.com) identity=helo; client-ip=209.85.214.173; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-ob0-f173.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvIBAOh1c1TRVdatm2dsb2JhbABbhDwEgwLPAwKBFwcWAQEBAQERAQEBAQEGCwsJFC6EAwEBBBIRHQEbHQEDDAYFCw0CAiYCAiEBAREBBQEcBhMIGogJAQMSrg49MYs7gXKDEYlxChknDWiFXgEBAQEBBQEBAQEBFwEFDoEfjSGCPQeCeYFVBZxsghWBNItxgneCdIIPGCmFOEcwgksBAQE X-IPAS-Result: AvIBAOh1c1TRVdatm2dsb2JhbABbhDwEgwLPAwKBFwcWAQEBAQERAQEBAQEGCwsJFC6EAwEBBBIRHQEbHQEDDAYFCw0CAiYCAiEBAREBBQEcBhMIGogJAQMSrg49MYs7gXKDEYlxChknDWiFXgEBAQEBBQEBAQEBFwEFDoEfjSGCPQeCeYFVBZxsghWBNItxgneCdIIPGCmFOEcwgksBAQE X-IronPort-AV: E=Sophos;i="5.07,450,1413237600"; d="scan'208";a="90290889" Received: from mail-ob0-f173.google.com ([209.85.214.173]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 24 Nov 2014 19:16:17 +0100 Received: by mail-ob0-f173.google.com with SMTP id uy5so7580099obc.18 for ; Mon, 24 Nov 2014 10:16:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=RaSrKYzChmkeMJ2WL07tfitYsrzsYBhawc7orrNg8/0=; b=I/F/rFoHBMIRZrJUXZyYVjLicCanT3ExkifqDvhk1TC8m42HuCT5czVm0pmNAjGorm qBejnVpbOTanreV526mgQ9zLiwDa8zIErMrQyU6AwmH04g3OVaVTHQr8uBBqW5Oi5WTZ xqF1XCH8q5TLHM1/KOYm0ikZhzfezoX5OU7bQlNCUjIzJ4IjY65xx6A9vjaFtJ0qj0CK tyIAGn4sW2xyl7UxNhiRqpOHa8x8pjzyaDXI6d6W/0SxwcG4ycXss7QSc8GpSWKIgoZC Np7kmNQGFJENJQQ/DukDnK4DkGMJ/SK+Y0+J5RYj+9aSio4mRK+gVhkgNLdQhwIKa8VR 5V3w== X-Received: by 10.60.33.234 with SMTP id u10mr13742615oei.32.1416853007541; Mon, 24 Nov 2014 10:16:47 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.90.197 with HTTP; Mon, 24 Nov 2014 10:16:07 -0800 (PST) In-Reply-To: References: From: Gabriel Scherer Date: Mon, 24 Nov 2014 19:16:07 +0100 Message-ID: To: Kenneth Adam Miller Cc: caml users Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] complications with Arg.parse_argv Looking at the parse_argv documentation (man Arg), I see two possible reasons: - Arg expects the passed string array to start with the name of the program at index 0; does your custom_arguments array follow this convention? - parse_argv takes an (optional) integer reference ~current that tells it where to start parsing the argument array; by default, it points to a global mutable reference Arg.current (so that several calls in a row start on the next element); if your library has used Arg.parse itself before, Arg.current may be set too far. You should try passing ~current:(ref 0) to make sure you only use local state. On Mon, Nov 24, 2014 at 6:42 PM, Kenneth Adam Miller wrote: > So, I'm using a library that calls Arg.parse to build up it's inputs in > another data structure. I don't want to rewrite any code, and I'm consuming > the library in a different way than how the binary consumes it, which is > just to feed it input from the command line. > > Not wanting to replicate code in two locations, I chose to use > Arg.parse_argv, and supplied it with an array that would normally be on the > command line. For some reason, supplying the exact same speclist as what was > used in the original statement that works as a command line tool doesn't > result in the parameters being parsed. > > command line tool: > Arg.parse speclist anon usage; > get_program () (* consumes the mutable list that speclist modified *) > > (* speclist modifies a mutable list used to hold arguments *) > > my code that consumes speclist as a library: > > Arg.parse_argv custom_arguments speclist anon usage > get_program () (* exact same function as above, exact same variables to > Arg.parse* *) > > For some reason, Arg.parse_argv seems to complete, but when get_program > proceeds, it sees the mutable argument list as being empty. Why?