英文:
I am getting compilation error while running this code in common lisp
问题
以下是我的代码,其中出现了错误。请有人帮忙查看一下,告诉我我的代码出了什么问题。
我在Common Lisp中编写了这段代码,但在编译时出现了上述问题。不确定是什么导致了错误。
如果有人可以告诉我我哪里错了?我尝试过找出问题,但没有成功。如果有人可以帮忙。
(defun validate-arn-data (tokens)
(declare (special *rule-loading*))
(when (typep tokens 'rel-errors)
(setq tokens (rel-errors-correct-tokens tokens)))
(if (and tokens (not *rule-loading*))
(let ((arn-num nil)
(rtn-msg nil)
(processed-rtn-msg nil)
(start nil)
(end nil)
(transaction-id nil)
(transac-id-length nil)
(pon-tokens nil)
(pon-value nil)
(pon-length nil)
(rtn nil)
(errors (make-rel-errors))
)
(dolist (to tokens)
(setq arn-num (so-token-value to))
(if (numeric-string? arn-num)
(when arn-num
(setq rtn-msg (call-dispatch-services arn-num))
(setq processed-rtn-msg (process-dispatch-services-reply rtn-msg))
(when processed-rtn-msg
(when (setq start (search "appointmentOrderId" rtn-msg))
(setq end (search "," (subseq rtn-msg start)))
(setq transaction-id (subseq rtn-msg (+ start 23) (+ start (- end 1))))
(setq rtn t)
(cond ((or (equal *so-entry-appl* " ")
(equal *so-entry-appl* "B")
(equal *so-entry-appl* "L")
(equal *so-entry-appl* "U")
(equal *so-entry-appl* "V"))
(setq transac-id-length (length transaction-id))
(setq pon-tokens (find-matching-tokens "PON"))
(cond ((not (equal pon-tokens nil))
(dolist (to-pon pon-tokens)
(setq pon-value (so-token-value to-pon))
(setq pon-length (length pon-value))
(if (<= (+ pon-length 1) (length transaction-id))
(unless (equal pon-value (subseq transaction-id 1 (+ pon-length 1)))
(if (>= transac-id-length 8)
(progn
(setq transaction-id (subseq transaction-id (- transac-id-length 8) transac-id-length))
(unless (equal transaction-id *so-order-number*)
(setq rtn nil)))
(setq rtn nil))
(unless rtn
(setq *more-long-error-msg* (concatenate 'simple-string
"ORDER ID MISMATCH ")))))))
(t nil))
((equal *so-entry-appl* "F")
(setq pon-tokens (find-matching-tokens "PON"))
(dolist (to-pon pon-tokens)
(setq pon-value (so-token-value to-pon))
(setq pon-length (length pon-value))
(if (<= (+ pon-length 1) (length transaction-id))
(unless (equal pon-value (subseq transaction-id 1 (+ pon-length 1)))
(setq rtn nil))
(setq rtn nil))
(unless rtn
(setq *more-long-error-msg* (concatenate 'simple-string
"ORDER ID MISMATCH ")))))
(t
(setq rtn t)))))
(if rtn
(push to (rel-errors-correct-tokens errors))
(push to (rel-errors-error-tokens errors))))
(push to (rel-errors-error-tokens errors))))
errors)
t)))
错误信息如下:
(load (compile-file "/home/raymond-arn.lisp"))
;;; Compiling file /home/ac86208/raymond-arn.lisp ...
;;; Safety = 3, Speed = 1, Space = 1, Float = 1, Interruptible = 1
;;; Compilation speed = 1, Debug = 2, Fixnum safety = 3
;;; Source level debugging is on
;;; Source file recording is on
;;; Cross referencing is on
; (TOP-LEVEL-FORM 0)
**++++ Error in VALIDATE-ARN-DATA:
Illegal car (EQUAL *SO-ENTRY-APPL* "F") in compound form ((EQUAL *SO-ENTRY-APPL* "F") (SETQ PON-TOKENS (FIND-MATCHING-TOKENS "PON")) (DOLIST (TO-PON PON-TOKENS) (SETQ PON-VALUE (SO-TOKEN-VALUE TO-PON)) (SETQ PON-LENGTH (LENGTH PON-VALUE)) (IF (< (+ PON-LENGTH 1) (LENGTH TRANSACTION-ID)) (UNLESS (EQUAL PON-VALUE (SUBSEQ TRANSACTION-ID 1 (+ PON-LENGTH 1))) (SETQ RTN NIL)) (SETQ RTN NIL)) (UNLESS RTN (SETQ *MORE-LONG-ERROR-MSG* (CONCATENATE 'SIMPLE-STRING "ORDER ID MISMATCH WITH FTS-ICADS ORDER ")))).
;; Processing Cross Reference Information
; *** 1 error detected, no fasl file produced.
!!!!!Wrote error log to /home/logs/LispWorks/lispworks-8-0-0-amd64-linux-log at 2023/06/05 08:29:37
Error: Argument NIL is not of type PATHNAME, STRING, or FILE-STREAM.
请注意,我只提供了代码和错误信息的翻译,没有提供任何其他内容。
英文:
Below is my code which is througing the error. Can somebody please look into this and let me know what is getting wrong in my code.
Wrote this code in common lisp but while compiling i am getting the error as mentioned in the question. Not sure what is giving me the error.
If somebody, can let me know where i am going wrong? I tried to figure, but was not able to do that. If, somebody can help.
(defun validate-arn-data (tokens)
(declare (special *rule-loading*))
(when (typep tokens 'rel-errors)
(setq tokens (rel-errors-correct-tokens tokens)))
(if (and tokens (not *rule-loading*))
(let ((arn-num nil)
(rtn-msg nil)
(processed-rtn-msg nil)
(start nil)
(end nil)
(transaction-id nil)
(transac-id-length nil)
(pon-tokens nil)
(pon-value nil)
(pon-length nil)
(rtn nil)
(errors (make-rel-errors))
)
(dolist (to tokens)
(setq arn-num (so-token-value to))
(if (numeric-string? arn-num)
(when arn-num
(setq rtn-msg (call-dispatch-services arn-num))
(setq processed-rtn-msg (process-dispatch-services-reply rtn-msg))
(when processed-rtn-msg
(when (setq start (search "appointmentOrderId" rtn-msg))
(setq end (search "," (subseq rtn-msg start)))
(setq transaction-id (subseq rtn-msg (+ start 23) (+ start (- end 1))))
(setq rtn t)
(cond ((or (equal *so-entry-appl* " ")
(equal *so-entry-appl* "B")
(equal *so-entry-appl* "L")
(equal *so-entry-appl* "U")
(equal *so-entry-appl* "V"))
(setq transac-id-length (length transaction-id))
(setq pon-tokens (find-matching-tokens "PON"))
(cond ((not (equal pon-tokens nil))
(dolist (to-pon pon-tokens)
(setq pon-value (so-token-value to-pon))
(setq pon-length (length pon-value))
(if (<= (+ pon-length 1) (length transaction-id))
(unless (equal pon-value (subseq transaction-id 1 (+ pon-length 1)))
(if (>= transac-id-length 8)
(progn
(setq transaction-id (subseq transaction-id (- transac-id-length 8) transac-id-length))
(unless (equal transaction-id *so-order-number*)
(setq rtn nil)))
(setq rtn nil))
(unless rtn
(setq *more-long-error-msg* (concatenate 'simple-string
"ORDER ID MISMATCH ")))))))
(t nil))
((equal *so-entry-appl* "F")
(setq pon-tokens (find-matching-tokens "PON"))
(dolist (to-pon pon-tokens)
(setq pon-value (so-token-value to-pon))
(setq pon-length (length pon-value))
(if (<= (+ pon-length 1) (length transaction-id))
(unless (equal pon-value (subseq transaction-id 1 (+ pon-length 1)))
(setq rtn nil))
(setq rtn nil))
(unless rtn
(setq *more-long-error-msg* (concatenate 'simple-string
"ORDER ID MISMATCH ")))))
(t
(setq rtn t)))))
(if rtn
(push to (rel-errors-correct-tokens errors))
(push to (rel-errors-error-tokens errors))))
(push to (rel-errors-error-tokens errors))))
errors)
t)))
The error is below:
(load (compile-file "/home/raymond-arn.lisp"))
;;; Compiling file /home/ac86208/raymond-arn.lisp ...
;;; Safety = 3, Speed = 1, Space = 1, Float = 1, Interruptible = 1
;;; Compilation speed = 1, Debug = 2, Fixnum safety = 3
;;; Source level debugging is on
;;; Source file recording is on
;;; Cross referencing is on
; (TOP-LEVEL-FORM 0)
**++++ Error in VALIDATE-ARN-DATA:
Illegal car (EQUAL *SO-ENTRY-APPL* "F") in compound form ((EQUAL *SO-ENTRY-APPL* "F") (SETQ PON-TOKENS (FIND-MATCHING-TOKENS "PON")) (DOLIST (TO-PON PON-TOKENS) (SETQ PON-VALUE (SO-TOKEN-VALUE TO-PON)) (SETQ PON-LENGTH (LENGTH PON-VALUE)) (IF (<= (+ PON-LENGTH 1) (LENGTH TRANSACTION-ID)) (UNLESS (EQUAL PON-VALUE (SUBSEQ TRANSACTION-ID 1 (+ PON-LENGTH 1))) (SETQ RTN NIL)) (SETQ RTN NIL)) (UNLESS RTN (SETQ *MORE-LONG-ERROR-MSG* (CONCATENATE (QUOTE SIMPLE-STRING) "ORDER ID MISMATCH WITH FTS-ICADS ORDER "))))).
;; Processing Cross Reference Information
; *** 1 error detected, no fasl file produced.
!!!!!Wrote error log to /home/logs/LispWorks/lispworks-8-0-0-amd64-linux-log at 2023/06/05 08:29:37
Error: Argument NIL is not of type PATHNAME, STRING, or FILE-STREAM.
</details>
# 答案1
**得分**: 0
你的 `cond` 嵌套了,也许你需要澄清哪个条件适用于哪个 `cond`。以下是修改后的版本:
```lisp
(defun validate-arn-data (tokens)
(declare (special *rule-loading*))
(when (typep tokens 'rel-errors)
(setq tokens (rel-errors-correct-tokens tokens)))
(if (and tokens (not *rule-loading*))
(let ((arn-num nil)
(rtn-msg nil)
(processed-rtn-msg nil)
(start nil)
(end nil)
(transaction-id nil)
(transac-id-length nil)
(pon-tokens nil)
(pon-value nil)
(pon-length nil)
(rtn nil)
(errors (make-rel-errors))
)
(dolist (to tokens)
(setq arn-num (so-token-value to))
(if (numeric-string? arn-num)
(when arn-num
(setq rtn-msg (call-dispatch-services arn-num))
(setq processed-rtn-msg (process-dispatch-services-reply rtn-msg))
(when processed-rtn-msg
(when (setq start (search "appointmentOrderId" rtn-msg))
(setq end (search "," (subseq rtn-msg start)))
(setq transaction-id (subseq rtn-msg (+ start 23) (+ start (- end 1))))
(setq rtn t)
(cond ((member *so-entry-appl* '(" " "B" "L" "U" "V"))
(setq transac-id-length (length transaction-id))
(setq pon-tokens (find-matching-tokens "PON"))
(cond ((not (equal pon-tokens nil))
(dolist (to-pon pon-tokens)
(setq pon-value (so-token-value to-pon))
(setq pon-length (length pon-value))
(if (<= (+ pon-length 1) (length transaction-id))
(unless (equal pon-value (subseq transaction-id 1 (+ pon-length 1)))
(if (>= transac-id-length 8)
(progn
(setq transaction-id (subseq transaction-id (- transac-id-length 8) transac-id-length))
(unless (equal transaction-id *so-order-number*)
(setq rtn nil)))
(setq rtn nil))
(unless rtn
(setq *more-long-error-msg* (concatenate 'simple-string "ORDER ID MISMATCH ")))))))
(t nil)))
((equal *so-entry-appl* "F")
(setq pon-tokens (find-matching-tokens "PON"))
(dolist (to-pon pon-tokens)
(setq pon-value (so-token-value to-pon))
(setq pon-length (length pon-value))
(if (<= (+ pon-length 1) (length transaction-id))
(unless (equal pon-value (subseq transaction-id 1 (+ pon-length 1)))
(setq rtn nil))
(setq rtn nil))
(unless rtn
(setq *more-long-error-msg* (concatenate 'simple-string "ORDER ID MISMATCH ")))))))
(t
(setq rtn t))))))
(if rtn
(push to (rel-errors-correct-tokens errors))
(push to (rel-errors-error-tokens errors))))))
errors)
t)))
为了简化你的代码并避免这些问题,你可以尝试将 `cond` 条件和 `cond` 形式封装到自己的函数中。
<details>
<summary>英文:</summary>
Your `cond`s are nested, maybe you have to clarify which condition apply to which cond. Here is a modified version:
(defun validate-arn-data (tokens)
(declare (special *rule-loading*))
(when (typep tokens 'rel-errors)
(setq tokens (rel-errors-correct-tokens tokens)))
(if (and tokens (not *rule-loading*))
(let ((arn-num nil)
(rtn-msg nil)
(processed-rtn-msg nil)
(start nil)
(end nil)
(transaction-id nil)
(transac-id-length nil)
(pon-tokens nil)
(pon-value nil)
(pon-length nil)
(rtn nil)
(errors (make-rel-errors))
)
(dolist (to tokens)
(setq arn-num (so-token-value to))
(if (numeric-string? arn-num)
(when arn-num
(setq rtn-msg (call-dispatch-services arn-num))
(setq processed-rtn-msg (process-dispatch-services-reply rtn-msg))
(when processed-rtn-msg
(when (setq start (search "appointmentOrderId" rtn-msg))
(setq end (search "," (subseq rtn-msg start)))
(setq transaction-id (subseq rtn-msg (+ start 23) (+ start (- end 1))))
(setq rtn t)
(cond ((or (equal *so-entry-appl* " ")
(equal *so-entry-appl* "B")
(equal *so-entry-appl* "L")
(equal *so-entry-appl* "U")
(equal *so-entry-appl* "V"))
(setq transac-id-length (length transaction-id))
(setq pon-tokens (find-matching-tokens "PON"))
(cond ((not (equal pon-tokens nil))
(dolist (to-pon pon-tokens)
(setq pon-value (so-token-value to-pon))
(setq pon-length (length pon-value))
(if (<= (+ pon-length 1) (length transaction-id))
(unless (equal pon-value (subseq transaction-id 1 (+ pon-length 1)))
(if (>= transac-id-length 8)
(progn
(setq transaction-id (subseq transaction-id (- transac-id-length 8) transac-id-length))
(unless (equal transaction-id *so-order-number*)
(setq rtn nil)))
(setq rtn nil))
(unless rtn
(setq *more-long-error-msg* (concatenate 'simple-string
"ORDER ID MISMATCH ")))))))
(t nil)))
((equal *so-entry-appl* "F")
(setq pon-tokens (find-matching-tokens "PON"))
(dolist (to-pon pon-tokens)
(setq pon-value (so-token-value to-pon))
(setq pon-length (length pon-value))
(if (<= (+ pon-length 1) (length transaction-id))
(unless (equal pon-value (subseq transaction-id 1 (+ pon-length 1)))
(setq rtn nil))
(setq rtn nil))
(unless rtn
(setq *more-long-error-msg* (concatenate 'simple-string
"ORDER ID MISMATCH ")))))
(t
(setq rtn t))))
(if rtn
(push to (rel-errors-correct-tokens errors))
(push to (rel-errors-error-tokens errors))))
(push to (rel-errors-error-tokens errors))))
errors)
t)))
To simplify your code and avoid those problems, you may try to encapsulate `cond` conditions and cond forms into their own function.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论