小编Min*_*Lim的帖子

Lisp:使用AND运算符的IF条件

我做这个功能.

(f 3 4) (sum = 7) 
(f 'a 'b) (not num!) 
Run Code Online (Sandbox Code Playgroud)

我的问题是如果条件使用和运算符我该怎么做.

我试试....

  1. (IF (and (typep a 'integer) (typep b 'integer)) (1) (0))

  2. (IF (and ((typep a 'integer)) ((typep b 'integer))) (1) (0))

  3. (IF ((and ((typep a 'integer)) ((typep b 'integer)))) (1) (0))

但它不起作用.(1)(0)我暂时设置它.

我可以获得一些lisp语法帮助吗?

lisp syntax common-lisp

1
推荐指数
1
解决办法
1030
查看次数

Lisp - if语句各种动作

这是我的lisp代码.

 (DEFUN F (A B)
              (SETF C (* 4 A))
              (SETF D (* 2 (EXPT B 3)))
              (SETF RES (+ C D))
              (IF (AND (TYPEP A 'INTEGER) (TYPEP B 'INTEGER))
                  (list 'Final 'value '= res)
                '(YOUR INPUTS ARE NOT NUMBERS)))
Run Code Online (Sandbox Code Playgroud)

例如,(f 5 9)效果很好.但(f 'w 'q)不能使用以下错误消息:

(ERROR TYPE-ERROR DATUM W预期类型编号格式控制〜@ < ~s' is not of the expected type〜s'〜:@>格式参数(W编号))错误:W' is not of the expected typeNUMBER'

我想制作如果A,B是整数计算4A + 2B ^ 3.

否则,如果至少有一个不是整数打印错误消息.

我尝试上面显示的代码.但是如何使用if语句进行此错误处理?

lisp

0
推荐指数
1
解决办法
193
查看次数

标签 统计

lisp ×2

common-lisp ×1

syntax ×1