• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
      • Theories
      • Rule-classes
      • Proof-builder
      • Recursion-and-induction
      • Hons-and-memoization
      • Events
      • Parallelism
      • History
      • Programming
      • Operational-semantics
      • Real
      • Start-here
      • Debugging
      • Miscellaneous
      • Output-controls
      • Macros
      • Interfacing-tools
        • Io
        • Defttag
        • Sys-call
        • Save-exec
        • Quicklisp
        • Std/io
        • Oslib
          • File-types
          • Argv
            • Copy
            • Catpath
            • Ls
            • Universal-time
            • Tempfile
            • Basename
            • Dirname
            • Copy!
            • Ls-files
            • Mkdir
            • Rmtree
            • Lisp-version
            • Lisp-type
            • Ls-subdirs
            • Date
            • Getpid
            • Dirnames
            • Basenames
            • Basename!
            • Ls-subdirs!
            • Ls-files!
            • Dirname!
            • Ls!
            • Catpaths
            • Mkdir!
            • Rmtree!
            • Remove-nonstrings
          • Bridge
          • Clex
          • Tshell
          • Unsound-eval
          • Hacker
          • ACL2s-interface
          • Startup-banner
          • Command-line
      • Interfacing-tools
        • Io
        • Defttag
        • Sys-call
        • Save-exec
        • Quicklisp
        • Std/io
        • Oslib
          • File-types
          • Argv
            • Copy
            • Catpath
            • Ls
            • Universal-time
            • Tempfile
            • Basename
            • Dirname
            • Copy!
            • Ls-files
            • Mkdir
            • Rmtree
            • Lisp-version
            • Lisp-type
            • Ls-subdirs
            • Date
            • Getpid
            • Dirnames
            • Basenames
            • Basename!
            • Ls-subdirs!
            • Ls-files!
            • Dirname!
            • Ls!
            • Catpaths
            • Mkdir!
            • Rmtree!
            • Remove-nonstrings
          • Bridge
          • Clex
          • Tshell
          • Unsound-eval
          • Hacker
          • ACL2s-interface
          • Startup-banner
          • Command-line
        • Hardware-verification
        • Software-verification
        • Math
        • Testing-utilities
      • Oslib
      • Command-line

      Argv

      Get the "application level" command line arguments passed to ACL2.

      Signature
      (argv &optional (state 'state)) → (mv arguments state)
      Returns
      arguments — Type (string-listp arguments).
      state — Type (state-p1 state), given (force (state-p1 state)).

      Typically, (argv) is useful for writing command-line programs atop ACL2, e.g., using save-exec.

      In the logic, this function reads from the ACL2 oracle and coerces whatever it finds into a string-listp. In the execution, we use whatever mechanism the host Lisp provides for reading the command line arguments that were given to ACL2.

      Dead simple, right? Well, not really.

      Usually ACL2 itself, or any custom program you build atop ACL2 using save-exec, is really just an image that is executed by the runtime for the host Lisp. For instance, when you build ACL2 on CCL, you get:

      • An ACL2 image named saved_acl2.lx86cl64 or similar
      • A script named saved_acl2 that is something like this:
        #!/bin/sh
        export CCL_DEFAULT_DIRECTORY=/path/to/ccl
        exec /path/to/ccl/lx86cl64 
          -I /path/to/saved_acl2.lx86cl64 
          -K ISO-8859-1 
          -e "(acl2::acl2-default-restart)"
          -- "$@"

      So this script is invoking the Lisp runtime, named lx86cl64, and telling it to execute the ACL2 image, saved_acl2.lx86cl64.

      The important thing to note here is that command-line options like -I, -K, and -e, are arguments to the runtime, not to ACL2. These runtime options vary wildly from Lisp to Lisp. So for argv to be portable and make any sense at all, we really want to exclude these Lisp-runtime options, and only give you the "real", application-level options for this invocation of your program.

      Fortunately, most Lisps have a special mechanism to separate their runtime options from the application options. In Allegro, CCL, CLISP, and CMUCL, this is done with a special -- option. SBCL uses a slightly more elaborate syntax but it's the same basic idea.

      So on these Lisps, as long as you are running ACL2 or your save-image using a "proper" shell script, (argv) will work perfectly and give you exactly the arguments to your program, no matter what options you are using, and no matter whether the host Lisp runtime takes options with the same names. For details about what a "proper" script means, see the comments for your particular Lisp in oslib/argv-raw.lsp.

      Unfortunately, GCL and LispWorks do not have such an option, so on these Lisps we do something very half-assed:

      • We still expect that a "proper" shell script will put in a -- option to separate the runtime options from the program options.
      • (argv) just excludes will everything before the --.

      So even though the Lisp doesn't know about -- in this case, we can at least keep the Lisp specific options out of your program.

      But this isn't perfect. Since the Lisp doesn't know to stop processing options when it sees --, there is a possibility of conflict if your program happens to use the same options as the Lisp. I don't know how to do any better, so that's just how it is.

      Definitions and Theorems

      Function: argv-fn

      (defun argv-fn (state)
        (declare (xargs :stobjs (state)))
        (declare (xargs :guard t))
        (let ((__function__ 'argv))
          (declare (ignorable __function__))
          (b* ((- (raise "Raw Lisp definition not installed?"))
               ((mv err val state)
                (read-acl2-oracle state)))
            (if (and (not err) (string-listp val))
                (mv val state)
              (mv nil state)))))

      Theorem: string-listp-of-argv.arguments

      (defthm string-listp-of-argv.arguments
        (b* (((mv ?arguments acl2::?state)
              (argv-fn state)))
          (string-listp arguments))
        :rule-classes :rewrite)

      Theorem: state-p1-of-argv.state

      (defthm state-p1-of-argv.state
        (implies (force (state-p1 state))
                 (b* (((mv ?arguments acl2::?state)
                       (argv-fn state)))
                   (state-p1 state)))
        :rule-classes :rewrite)

      Theorem: true-listp-of-argv

      (defthm true-listp-of-argv
        (true-listp (mv-nth 0 (argv)))
        :rule-classes :type-prescription)