Anybody got any experience with command line parsing for CL? We are making our first command line deliverable and would like to use a library for this. We're trying to keep our code portable between Allegro, Lispworks, SBCL and CCL.
-a
-a
Discuss and learn Lisp programming of all dialects
This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.
5 posts · 3732 views
;; Read command line arguments
(defun command-line ()
"Get `groomed' command line arguments. These should just be the
arguments left to your program."
#+sbcl (cdr sb-ext:*posix-argv*)
#+lispworks system:*line-arguments*
#+cmu extensions:*command-line-words*
#+clisp ext:*args*
#-(or sbcl lispworks cmu clisp)
(error "Don't know how to get command line arguments in this Lisp.") )
(defun raw-command-line ()
"Get the raw command line. Not very useful as it may contain all
sorts of implementation dependent stuff. See COMMAND-LINE for
something a bit more useful."
#+sbcl sb-ext:*posix-argv*
#+clisp (ext:argv)
;; I don't have these imps
#+(or lispworks allegro)
(command-line)
;; Seems that command-line is the best I can do
#+(or cmu)
(command-line)
#-(or sbcl clisp lispworks allegro cmu)
(error "Don't know how to get command line arguments in this Lisp.") )
You'll have to add some more. The package ACL-compat actually has some code that covers the Lisps you want to support for this purpose (in package acl-compat.sys), so maybe use that instead of half rolling your own like I did.smithzv wrote:I assume you have already found some of the libraries out there for doing this. Getopt and CL-cli-parser are available in Quicklisp.Ayup! Do you have any impression if any of these are actively maintained? Getopt looks particularly mysterious since I can only find a tarball. Cl-cli-parser too doesn't have much activity around it. There is also something called Clon.
smithzv wrote:Coincidentally, this morning I ended up using Getopt for a small script. Your previous post must have planted a seed because I haven't written a Lisp program invokable from the shell for a very long time. It seemed to work well and was simple to get working.I'll try to use getopt too, mostly because it's the only one I could get to work
smithzv wrote: I'm not sure whether Getopt or cl-cli-parse are actively maintained. However, I doubt there is much activity on the GNU Getopt front either. It is a pretty simple functionality and is basically, dare I say, done. Lisp libraries in general are a testament to the idea that if something works, is compliant to a stable standard, and people don't fiddle with it, it will still work perpetually.Lets be honest here, there is probably more bugs and missing functionality (help generation f.ex.) in this lisp code than gnu getopt. My main concern is being able to push improvements back to the maintainer if we need any. Not that I expect much of it though.
smithzv wrote: Another thing to keep in mind since you are "hiding the Lispness." Since you are probably going to be dumping a core, some lisps, like SBCL I believe, have options to control what arguments are passed to the executable core with it is run. There might be something similar to this in the other Lisps. Take a look at save-lisp-and-die and its equivalent in the other Lisps to be sure nothing funny will happen.Thanks for the heads up, I'll remember to take a look at this. We'll release this to users soon and we'll want them to see a familiar (unix style) interface.
smithzv wrote: P.S. Never used CLON. In fact I was about to say you were confused and that CLON is a prototype based object oriented programming framework, but then I saw that there are several Lisp libraries named CLON. It actually might be something to really look at. It actually has a manual (big plus in my book), seems widely ported, and contains several of the features like typed option values and programmatically generated option help. It might be overkill for something that is a pretty simple problem.CLON has #+ clauses than I ever seen anywhere else