lisp - 报告 LISP 中的错误

标签 lisp common-lisp

我有这个函数可以把一个数字转换成某个基数,如果我引入的基数大于9小于2但我不知道,我想报错。你能帮帮我吗?

(defun zecb (number base)
  (write-to-string number :base base))

最佳答案

CL-USER 99 > (defun test (n)
               (check-type n (integer 2 9))
               n)
TEST

CL-USER 100 > (test 2)
2

CL-USER 101 > (test 9)
9

CL-USER 102 > (test 10)

Error: The value 10 of N is not of type (INTEGER 2 9).

关于lisp - 报告 LISP 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33843740/

相关文章:

lisp - LISP 中的深层嵌套列表为我的列表的一部分返回 #

lisp - 我可以在没有 Emacs 的情况下轻松使用 Lisp 吗?

c++ - 将子字符串传递给函数

lisp - 在 Common Lisp 中确定函数参数列表

common-lisp - 在 Common Lisp (SBCL) 中,有没有办法检查原子的各个部分?

inheritance - CLOS:如何调用一个不太具体的方法?

lisp - 符号处理 : cannot compare for identity

functional-programming - Lisp 中的选项类型编码/稳健性

lambda - 列表应该是一个 lambda 表达式

hash - 在 Common Lisp 中使用字符串对象作为哈希键