Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Common lisp =of(NIL 1)参数中的错误应为NUMBER类型。通用口齿不清_Common Lisp - Fatal编程技术网

Common lisp =of(NIL 1)参数中的错误应为NUMBER类型。通用口齿不清

Common lisp =of(NIL 1)参数中的错误应为NUMBER类型。通用口齿不清,common-lisp,Common Lisp,我有一个菜单,它是在选项功能中创建的,它的功能是让用户输入一个数字(1或2或3),以便用所选方法(DFS、BFS、BESTFS)解决问题。这个方法应该返回用户在这一行代码中选择的内容(SearchProblem'(0 0 2 6 4)'(0 0 0 0)(选项))。问题是,当我编译这个问题时,它会显示这个错误:“In=of(NIL 1)参数应该是NUMBER类型。”。我怎样才能解决这个问题 ;----------Otptions menu-----------------------------

我有一个菜单,它是在选项功能中创建的,它的功能是让用户输入一个数字(1或2或3),以便用所选方法(DFS、BFS、BESTFS)解决问题。这个方法应该返回用户在这一行代码中选择的内容(SearchProblem'(0 0 2 6 4)'(0 0 0 0)(选项))。问题是,当我编译这个问题时,它会显示这个错误:“In=of(NIL 1)参数应该是NUMBER类型。”。我怎样才能解决这个问题

;----------Otptions menu------------------------------------------------------ 
(defun Options ()
  ( print "Searching methods." )
  ( print "For DFS method press 1." )
  ( print "For BFS method press 2." )
  ( print "For BESTFS method press 3." )
  ( print "Choose searching method" )
  ( let (opt (read))
      (cond 
        ( ( = opt 1 )  'DFS )
        ( ( = opt 2 )  'BFS )
        ( ( = opt 3 )  'BESTFS ) 
      ) 
  )
)

有很多事情你需要改进:

(defun Options ()                        ; Lisp does not use uppercase
  ( print "Searching methods." )         ; don't add whitespace around parentheses
                                         ; don't use print,
                                         ;   since it prints string quotes
  ( print "For DFS method press 1." )    ; users don't 'press', they 'enter'
  ( print "For BFS method press 2." )
  ( print "For BESTFS method press 3." )
  ( print "Choose searching method" )
                                         ; after print you READ
                                         ;  but you have to deliver the ouput first,
                                         ;  in case it is buffered
  ( let (opt                             ; you define two variables OPT and READ
         (read))                         ; both are set to NIL            
      (cond 
        ( ( = opt 1 )  'DFS )            ; if OPT is NIL -> ERROR. Use EQL
        ( ( = opt 2 )  'BFS )
        ( ( = opt 3 )  'BESTFS ) 
      )                                  ; no dangling parentheses in Lisp,
                                         ; this is not C
  )
)
让我为您修复此代码:

(defun options ()
  (write-string              ; we write a multiline string
"
Searching methods.
For DFS method enter 1.
For BFS method enter 2.
For BESTFS method enter 3.

Choose searching method:
")
  (finish-output)            ; deliver all output
  (let ((opt (read)))        ; define a variable OPT
    (case opt                ; CASE uses EQL
      (1  'DFS)
      (2  'BFS)
      (3  'BESTFS))))


有很多事情你需要改进:

(defun Options ()                        ; Lisp does not use uppercase
  ( print "Searching methods." )         ; don't add whitespace around parentheses
                                         ; don't use print,
                                         ;   since it prints string quotes
  ( print "For DFS method press 1." )    ; users don't 'press', they 'enter'
  ( print "For BFS method press 2." )
  ( print "For BESTFS method press 3." )
  ( print "Choose searching method" )
                                         ; after print you READ
                                         ;  but you have to deliver the ouput first,
                                         ;  in case it is buffered
  ( let (opt                             ; you define two variables OPT and READ
         (read))                         ; both are set to NIL            
      (cond 
        ( ( = opt 1 )  'DFS )            ; if OPT is NIL -> ERROR. Use EQL
        ( ( = opt 2 )  'BFS )
        ( ( = opt 3 )  'BESTFS ) 
      )                                  ; no dangling parentheses in Lisp,
                                         ; this is not C
  )
)
让我为您修复此代码:

(defun options ()
  (write-string              ; we write a multiline string
"
Searching methods.
For DFS method enter 1.
For BFS method enter 2.
For BESTFS method enter 3.

Choose searching method:
")
  (finish-output)            ; deliver all output
  (let ((opt (read)))        ; define a variable OPT
    (case opt                ; CASE uses EQL
      (1  'DFS)
      (2  'BFS)
      (3  'BESTFS))))


您可能会受到支持这种可怕的括号用法的各种CAD lisp示例的影响。本样式指南可能会有所帮助。您可能会受到支持这种可怕的括号用法的各种CAD lisp示例的影响。本样式指南可能会有所帮助。“用户不‘按’,他们‘输入’”-这是我从长xD以来看到的最好的样式更正“用户不‘按’,他们‘输入’”-这是我从长xD以来看到的最好的样式更正