common lisp - Hunchentoot handler changes the definition of another function -
i wrote code manage postgresql database, , working on console. wish put on internal network via hunchentoot.
i use clsql , packaged database code as:
(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 db. parameters 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))))
i imported my-database package, , when use handler:
(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"))))
it displays html fine. handler:
(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"))))
throws error:
incorrect keyword arguments in ("frank sinatra" "male" "150" "55")
i noticed when type (my-database:new-patient )
@ repl, emacs command minibuffer shows (my-database:new-patient &key name gender height weight)
. &key
part looked suspicious me. therefore switched my-database file, did slime-eval-last-expression-in-repl, corrected emacs command minibuffer display.
but time, got following error:
too few arguments in call #<compiled-function my-database:new-patient #x15870d76>: 0 arguments provided, @ least 4 required.
and re-evaluating hunchentoot handler caused emacs command minibuffer show &key again. lastly, changed handler code (my-database:new-patient :name name :gender gender :height height :weight weight)
, throws error:
8 arguments provided, @ 4 accepted current global definition of new-patient
what may reason?
the reason semantics of define-easy-handler
:
the resulting handler lisp function name name , keyword parameters named var symbols.
(according hunchentoot documentation: http://weitz.de/hunchentoot/), should use different name handler, instance:
(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"))))
Comments
Post a Comment