函数定义

  1. (defun function-name (parameter-list)
  2. "comment"
  3. (body-list))

例:

  1. (defun hi()
  2. "say hello"
  3. (format t "hello")
  4. (format t "world"))

函数参数

rest 剩余参数

  1. (defun our-funcall (fn &rest args)
  2. (apply fn args))

可选参数

  • 默认值为nil

    1. (defun philosoph (thing &optional property)
    2. (list thing 'is property))
    3. > (philosoph 'death)
    4. (DEATH IS NIL)
  • 设置默认值

    1. (defun philosoph (thing &optional (property 'fun))
    2. (list thing 'is property))
    3. > (philosoph 'death)
    4. (DEATH IS FUN)

函数引用

  1. #'hi
  2. (function hi)

函数调用

funcall

  1. (funcall #'hi)

apply

  1. (apply #'hi nil)
文档更新时间: 2019-07-02 10:09   作者:admin