lisp - GNU CLISP 中的 if 条件

标签 lisp common-lisp

我需要一些帮助,当我自己在解释器中输入值时,我的代码没有返回好的答案。这是我的代码:

(defun compromis() 
  (flet ((prompt (string)
           (format t "~&~a: " string)
           (read nil 'eof nil)))
    (print "Enter values :")
    (let ((E (prompt "tddv_estime"))
          (W (prompt "tddv_worst"))
          (C (prompt "gisement_courant"))
          (M (prompt "gisement_max"))
          (m (prompt "gisement_min")))
      (if (> E W)
          (if (> C m)
              (print "Decrement")
              (print "Error")))
      (if (< E W)
          (if (< C M)
              (print "Increment")
              (print "Nothing"))))))

当我应该用 E=8W=16C=2 读取“增量”时Max=8Min=1,我的 "Nothing" 显示了两次...

最佳答案

您会看到“Nothing”两次,因为 print打印并且 返回它的参数,并且,因为它是函数中的最后一种形式 compromis,它返回print返回的值。 由于您正在评估 REPL 中的代码(Read-Eval-Print 循环), 您会看到打印输出返回值。

PS。请注意,lispers 通过缩进读取代码,而不是通过括号计数。我编辑了你的函数以符合通用的编码标准(实际上,Emacs 为我做了这件事)。

关于lisp - GNU CLISP 中的 if 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50350007/

相关文章:

macros - Common Lisp 宏对调用内表单的执行进行计时

string - Lisp - 显示要列出的字符串

list - 喜欢 first 和 rest 而不是 car 和 cdr 的 lisp 如何接近像 cdaddr 这样的组合?

macros - 带有 defclass 的 defmacro

lisp - 为什么我们需要 Lisp 中的 funcall?

common-lisp - 通用 Lisp : A good way to represent grammar rules?

lisp - 普通的口齿不清。德芬的条件

lisp - 给定函数的参数过多

optimization - 如何优化我的递归 Lisp 函数

loops - Lisp:在循环中收集多个列表