* (defun maxnum(x y) (if (> x y) x y)) STYLE-WARNING: redefining COMMON-LISP-USER::MAXNUM in DEFUN MAXNUM * (maxnum 9 8) 9 * (maxnum 8 9) 9 * (maxnum 112 990) 990
使用了progn,progn将其它语句 插入到某语句中 ,即只返回最后一个语句的执行结果
* (minofnums *mylist*) -263 * (maxofnums *mylist*) 126 *
下面是代码
[deep@deep ~]$ sbcl --load /home/deep/pro/test2.lisp
(defvar *mylist* `(23 126 29 -23 23 2 44 -23 0 -263) ) (defvar *mymax* (car *mylist*)) (defvar *mymin* (car *mylist*)) (defun maxofnums(mlist) (if mlist (progn (setf *mymax* (if (> *mymax* (car mlist)) *mymax* (car mlist))) (maxofnums (cdr mlist))) *mymax* ) ) (defun minofnums(mlist) (if mlist (progn (setf *mymin* (if (< *mymin* (car mlist)) *mymin* (car mlist))) (minofnums (cdr mlist))) *mymin* ) )
相关推荐
AutoLISP是一种基于LISP语言的编程环境,专为AutoCAD设计软件提供扩展功能和自定义解决方案。在深入学习AutoLISP语言时,了解其数据类型是至关重要的基础。本教程将带你探索AutoLISP中的核心数据类型,帮助你更好地...
- **列表与对**:列表是Lisp中最基础的数据结构,通过对(cons)构成,可以用来构建复杂的数据结构。 ##### 2.4 数组与哈希表 - **数组**:提供了一种快速访问数据的方式,支持多维数组。 - **向量**:一种特殊的...
除了基本的数值操作,Common Lisp还包括了动态作用域(`let`表达式)和条件语句(`if`函数)等控制结构。例如,`(let ((a 6)) a)`在局部范围内设置`a`的值,当离开`let`的范围,`a`恢复原来的值。 在Lisp中,还有...
AutoLISP 是一种专门为 AutoCAD 设计的脚本语言,用于扩展 AutoCAD 的功能和自动化工作流程。AutoCAD 支持 AutoLISP,但不支持许多 Visual LISP 函数或 Microsoft ActiveX Automation 接口。本文档将介绍 AutoLISP ...
1. **条件语句**: 使用`if`语句进行条件判断。 ```haskell max' :: Int -> Int -> Int max' x y = if x > y then x else y ``` 2. **模式匹配与`case`表达式**: 可以用来替代传统的`switch-case`结构。 ```...