跳轉至內容

Lisp 程式設計/概述

來自華夏公益教科書,開放給開放世界的開放書籍

概述?好吧,趕緊看看了解基本情況;

(defun ! (x)          ; Defines a factorial function denoted by the exclamation mark symbol. 
  (if (> x 0)
      (* x (! (- x 1)))
      1))

尾遞迴... 建立階乘函式。

(setf this '(hello world opps goodbye))
(car this) => hello
(cdr this) => (world opps goodbye)
(cadr this) => world
(cdar this) => probably an error

列表,是 lisp 的名稱由來,以及瞭解 lisp 的幾個功能。

如必須的話,你也可以執行

(setf ... same...
(first this) => hello
...
(second this) => world

但是你不能組合它(例如做 car cdr 變為 cadr)

以及,宏...

(defmacro when (cond &body body)
   (if (cond)
      (progn ,@body)))

此時,我們已經開始深入瞭解它,但是,天哪!

(defun do-nothing (anargument :key akeywordargument :opt anoptionalargument :rest everythingelseinalist))

我無法想出一種方法,把所有四種函式引數都整合到一起(你不能這麼做,而將其中兩個以上結合起來通常是個餿主意。)

還有 CLOS(通用 lisp 物件系統)以及很多其他你可能應該瞭解的東西,但如果你真的想知道,你最好仔細學習一個好教程。

所以,嘿,這是 lisp 類似的大概的樣子。祝你 lisping 愉快!

華夏公益教科書