Macros common lisp在宏中展开列表
我正在尝试为hunchentoot服务器用common lisp编写类似ruby on rails的routes文件,即Macros common lisp在宏中展开列表,macros,common-lisp,hunchentoot,Macros,Common Lisp,Hunchentoot,我正在尝试为hunchentoot服务器用common lisp编写类似ruby on rails的routes文件,即 (route "/home" :controller home :action index) 示例控制器文件如下所示: ;;; controller file (defun index () ;; do something ) (defun add (x) ;; do something ) 这样做的原因是将控制器与视图分离 因此,我有以下功能: (d
(route "/home" :controller home :action index)
示例控制器文件如下所示:
;;; controller file
(defun index ()
;; do something
)
(defun add (x)
;; do something
)
这样做的原因是将控制器与视图分离
因此,我有以下功能:
(defun build-handler (controller action)
(intern (concatenate 'string (symbol-name controller) "-" (symbol-name action))))
(defun format-view-file (controller params)
(let ((fstring (read-from-view-file))) ; the view file must be named after the controller. the details are not shown here
(format nil fstring params)))
(defun get-action-arguments (f)
;; read the controller file
;; and find the action function
;; return a list of its arguments
;; something like this, in case f was "(defun bar (x) (1+ x))"
(car (cdr (cdr f))))
宏观方面:
(defmacro route (uri &key controller action)
(let ((var (build-handler controller action))
(params (get-action-arguments action)))
`(hunchentoot:define-easy-handler (,var :uri ,uri) ,params
(setf (hunchentoot:content-type*) "text/plain")
(format-view-file ,params))))
我的问题是我不能正确地传递参数。参数应该如何位于route宏中
或者,是否有更好的方法来实现这一点,或者是否有一个在hunchentoot之上工作的库(我找到了一些,但不知道选择哪一个,所以我开始编写自己的库)
提前非常感谢 只有几个指针,还有更多: 有一个很好的服务器抽象层,名为lack: 有了它,您可以非常简单地构建自己的路由机制,或者使用现有的ningle或caveman 还有,它直接建立在Hunchentoot之上
至于你的想法:我强烈建议不要为语言机制加载文件/破坏文件名。您应该能够通过简单地加载顶级表单来表达任何内容,这样您就可以在系统定义中布局整个应用程序结构,最重要的是,保持简单的基于映像的开发周期。您的代码应该不需要知道它存储在文件中。只有几个指针,还有更多: 有一个很好的服务器抽象层,名为lack: 有了它,您可以非常简单地构建自己的路由机制,或者使用现有的ningle或caveman 还有,它直接建立在Hunchentoot之上
至于你的想法:我强烈建议不要为语言机制加载文件/破坏文件名。您应该能够通过简单地加载顶级表单来表达任何内容,这样您就可以在系统定义中布局整个应用程序结构,最重要的是,保持简单的基于映像的开发周期。您的代码不需要知道它存储在文件中。谢谢您的回复。我之所以开始尝试自己写,是因为我无法为这份工作选择合适的工具。如果我在hunchentoot、cl who(或其他模板系统)和parenscript没有框架的情况下继续工作,我是做错了吗?不,你完全可以在hunchentoot上构建自己的路由(在lack出现之前,我已经做过几次这样的实验)。谢谢你的回复。我之所以开始尝试自己写,是因为我无法为这份工作选择合适的工具。如果我和hunchentoot、cl who(或其他模板系统)以及没有框架的parenscript呆在一起,我是做错了吗?不,你完全可以在hunchentoot之上构建自己的路由(在缺乏框架之前,我已经做过几次这样的实验)。