Common lisp Hunchentoot处理程序更改另一个函数的定义

Common lisp Hunchentoot处理程序更改另一个函数的定义,common-lisp,hunchentoot,Common Lisp,Hunchentoot,我编写了一些代码来管理postgresql数据库,它正在控制台上运行。现在我希望通过hunchentoot将其放到我的内部网络上 我使用clsql并将数据库代码打包为: (defpackage :my-database (:use :common-lisp) (:documentation "several lines...") (:export almost-all-functions...)) (in-package #:my-database) (defun new-pat

我编写了一些代码来管理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"))))
(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"))))
它可以很好地显示html。但是这个处理程序:

(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"))))
(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")
我注意到,当我在REPL上键入
(我的数据库:new patient)
时,emacs命令minibuffer显示
(我的数据库:new patient&key name性别身高体重)
&key
部件在我看来可疑。因此,我切换到我的数据库文件,在repl中执行slime eval last expression,它更正了emacs命令minibuffer的显示

但这一次,我得到了以下错误:

Too few arguments in call to #<Compiled-function MY-DATABASE:NEW-PATIENT #x15870D76>:
0 arguments provided, at least 4 required.

原因可能是什么?

原因是
定义简易处理程序的语义:

结果处理程序将是一个Lisp函数,其名称和关键字参数由var符号命名

(根据hunchentoot文档:),因此您应该为处理程序使用不同的名称,例如:

(define-easy-handler (do-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"))))

请注意,在
let
表单中不需要
progn