我写了一些代码来管理一个 postgresql 数据库,它正在控制台上运行。现在我希望通过 hunchentoot 把它放到我的内部网络上。
我使用 clsql 并将数据库代码打包为:
(defpackage :my-database
(:use :common-lisp)
(:documentation "several lines...")
(:export almost-all-functions...))
(in-package #:my-database)
(defun new-patient (name gender height weight)
"adds new patient to the db. all parameters are of type string."
(let* ((height (parse-integer height))
(weight (parse-integer weight))
(corrected-weight (calculate-corrected-weight height weight gender)))
(clsql:insert-records :into 'patients
:attributes '(height weight corrected-weight name gender patient-at-ward)
:values (list height weight corrected-weight name gender t))))
我导入了 my-database 包,当我使用这个处理程序时:
(define-easy-handler (debug :uri "/debug")
(name gender height weight)
(let ((ad (substitute #\space #\+ (string-trim " " ad))))
(progn (format nil "Name:~A, Gender:~A, Height:~A, Weight:~A" name gender height weight)
(redirect "/success"))))
它显示html就好了。但是这个处理程序:
(define-easy-handler (new-patient :uri "/new-patient")
(name gender height weight)
(let ((name (substitute #\space #\+ (string-trim " " name))))
(progn (my-database:new-patient name gender height weight)
(redirect "/success"))))
抛出错误:
Incorrect keyword arguments in ("Frank Sinatra" "male" "150" "55")
我注意到当我(my-database:new-patient )
在 REPL 上键入时,emacs 命令 minibuffer 显示(my-database:new-patient &key name gender height weight)
. 这&key
部分在我看来很可疑。因此我切换到 my-database 文件,做了 slime-eval-last-expression-in-repl,它更正了 emacs 命令 minibuffer 显示。
但是这一次,我得到了以下错误:
Too few arguments in call to #<Compiled-function MY-DATABASE:NEW-PATIENT #x15870D76>:
0 arguments provided, at least 4 required.
并且重新评估 hunchentoot 处理程序导致 emacs 命令 minibuffer 再次显示 & 键。最后,我将处理程序代码更改为(my-database:new-patient :name name :gender gender :height height :weight weight)
,这会引发此错误:
8 arguments were provided, but at most 4 are accepted by the current global
definition of NEW-PATIENT
可能是什么原因?