明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2091|回复: 3

[求助]关于IF函数用法的问题

[复制链接]
发表于 2006-11-4 19:11:00 | 显示全部楼层 |阅读模式
关于IF函数用法的问题:
我在autolisp使用过程中发现,如果 if 函数不能执行两个表达式,即便是再一个括号里。
比如:
(defun test()
    (setq n  1)
    (if (= n 1)
          (
              (setq a 1)
              (princ)
          )
     )
)
这样程序就会提示:错误:函数错误。

这是怎么回事?
编程中经常出现判断后执行两个操作,如果autolisp不支持,如何解决,请高手指点。
发表于 2006-11-4 20:08:00 | 显示全部楼层

progn Function

Evaluates each expression sequentially and returns the value of the last expression

(progn [expr]...)

You can use progn to evaluate several expressions where only one expression is expected.

Arguments

expr

One or more AutoLISP expressions.

Return Values

The result of the last evaluated expression.

Examples

The if function normally evaluates one then expression
if the test expression evaluates to anything but nil.
The following example uses progn to evaluate two expressions following if:

(if (= a b)
  (progn
    (princ "\nA = B ")
    (setq a (+ a 10) b (- b 10))
  )
)

发表于 2006-11-4 20:45:00 | 显示全部楼层
(defun test()
    (setq n  1)
    (if (= n 1)
          (progn
              (setq a 1)
              (princ)
          )
     )
)
 楼主| 发表于 2006-11-4 21:18:00 | 显示全部楼层

多谢楼上二位指教,完全正确!送上鲜花一朵!

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-6-21 04:06 , Processed in 0.119617 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表