For a couple of weeks now I've been playing with some code to generate a cut point list for dovetail joints. Initially in Python, I quickly ported it to Java. Over Christmas I had a bit of fun and ported it to Ruby. No reason, just wanted to. This week I was browsing my bookshelf and spotted ANSI common lisp by Paul Graham. So I tried a Lisp port. Doing well, usual 'fighting the language' not the problem stumbles which I expected. Then I finished the function list and came to the cmd line interface. Ah. Well. Now that's different. Admitted it could be me. I simply could not find any code demonstrating processing command line options in Lisp. To be exact, I'm using sbcl flavour of Lisp. A guy on the #lisp irc channel agreed it's not documented. (I'd been looking for a function to process the list, the variable holding the list isn't even documented! I was miles out). For any others seeking a starting point, an input of
$ sbcl --load file.lisp -a val -b val
will result in a list containing
(sbcl -a val -b val)
I.e. a list of strings, the first (argv) being the program name. I guess it's pulled through from some C interface
I did find it odd, but needing it, I coded something up. Hardly in the style of Lisp, but it works for me.
An intriguing problem, since the input parameters are set by
the system as a list
*posix-argv*. What I want is a
variable number of outputs. Also wanted to recognise unrecognised
parameter names and let the user know about invalid selected
values. Usual sort of thing that Python getopts does. Even staid
old Java is pretty slick looping through the list using
I'm sure there are better solutions. Let me know if you're not into sneering and I'll improve it. This is the code. GPL'd.