关于commonlisp:如何在CommonLisp中解析命令行参数
clingonclingon 是一个 Common Lisp 的命令行选项的解析器,它能够轻松地解析具备简单格局的命令行选项。例如,上面的代码能够打印给定次数的打招呼信息 #!/bin/sh#|-*- mode:lisp -*-|##|exec ros -Q -- $0 "$@"|#(progn ;;init forms (ros:ensure-asdf) #+quicklisp(ql:quickload '(clingon) :silent t) )(defpackage :ros.script.hello.3868869124 (:use :cl :clingon))(in-package :ros.script.hello.3868869124)(defun top-level/handler (cmd) (check-type cmd clingon:command) (let ((count (clingon:getopt cmd :count)) (name (first (clingon:command-arguments cmd)))) (dotimes (_ count) (declare (ignorable _)) (format t "Hello ~A!~%" name))))(defun main (&rest argv) (let ((app (clingon:make-command :handler #'top-level/handler :name "hello" :options (list (clingon:make-option :integer :description "number of greetings" :initial-value 1 :key :count :long-name "count"))))) (clingon:run app argv)));;; vim: set ft=lisp lisp:略微做一些解释。首先执行命令ros init hello生成下面的代码的雏形——加载依赖、包定义,以及空的函数main。为了加载 clingon,将其作为函数ql:quickload的参数。而后别离定义一个command、handler,以及option。 ...