views:

785

answers:

3

How can I get the command line arguments in (specifically in GNU, if there are any differences) Common Lisp?

+5  A: 

http://cl-cookbook.sourceforge.net/os.html provides some insight

  (defun my-command-line ()
  (or 
   #+SBCL *posix-argv*  
   #+LISPWORKS system:*line-arguments-list*
   #+CMU extensions:*command-line-words*
   nil))

is what you are looking for, I think.

mog
(or FOO nil) is equivalent to FOO, is it not?
Luís Oliveira
Yes, but when you have your FOO conditionally read, it's, possibly, good to have a fall-back. But, then, the value of (or) is, not entirely surprising, NIL (just as the value of (and) is T).
Vatine
+2  A: 

I'm assuming that you are scripting with CLisp. As described here, you can create a file containing

#! /usr/local/bin/clisp
(format t "~&~S~&" *args*)

Make it executable by running

$ chmod 755 <filename>

Running it gives

$ ./<filename>
NIL
$ ./<filename> a b c
("a" "b" "c")
$ ./<filename> "a b c" 1 2 3
("a b c" "1" "2" "3")
anderstornvig
+3  A: 

Are you talking about Clisp or GCL? Seems like in GCL the command line arguments get passed in si::*command-args*.

js