【问题标题】:What is the function to exit the complete program in common lisp?common lisp中退出完整程序的功能是什么?
【发布时间】:2012-04-01 19:52:31
【问题描述】:

我有一些带有循环的函数,每次迭代它读取输入,在“0”上它调用函数“exit-and-save”,在那个函数中它保存一些数据库,然后我需要它退出程序?那命令是什么?如果我使用 return-from... 它只是从函数返回,如果我使用 return - 错误,如果我使用 quit,它会与粘液断开连接。我是普通 lisp 的新手...

【问题讨论】:

  • 当您在运行在 Slime 的 Lisp 系统中调用 quit 时,您期望会发生什么?
  • 查看您正在尝试做的事情的示例可能会有所帮助。听起来,粗略地说,好像你的程序设计有问题,你很难“检测到结束”条件。这种“退出并保存”功能似乎不太可能正常工作……

标签: common-lisp


【解决方案1】:
(loop for i from 0 to 10
    do (progn (format t "~&cycle ~d" i)
          (when (> i 5)
            (return nil))))

【讨论】:

    【解决方案2】:

    首先,我无法验证 slime 是否使用(退出)断开连接,至少在 Ubuntu 上没有使用 sbcl。

    CL-USER> (quit)
    ; Evaluation aborted on NIL.
    CL-USER> 
    "still able to input here"
    

    但是如果你有一些奇怪的粘液版本,你可以利用条件系统:

    (define-condition end-program-condition (simple-error) ())
    
    (defun some-func ()
           (error 'end-program-condition))
    
    (defun main-function ()
      (handler-case (some-func)
         (end-program-condition () "THE END")))
    
    
    CL-USER> (main-function)
    "THE END"
    CL-USER> "still can input here"
    "still can input here"
    

    【讨论】:

      猜你喜欢
      • 2015-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      • 2019-01-18
      • 1970-01-01
      相关资源
      最近更新 更多