- 基本構成要素
- 原子(ATOM)
- 符號
- 數值
- 整數
- 浮點數
- 串列(LIST) :(a b c),(a (b c)d)、空串列
- 函式呼叫:
(函式名稱 參數)
>'(setg a 3)
>(setg a 3)(解答)
常用操作符號:
- Quote
- Atom
- Eq
- Car
- Cdr
- Cons
- Cond
EX:
(Car list)
(Car '((a) b))
> (a)
---------------------------
(Cdr list)
(Cdr '(a(b c))
>((b c))
---------------------------
(Cons s-expression list)
(Cons '(a) '(b c))
>((a) b c)
---------------------------
(ATOM s-exp) 檢查是否為原子
(ATOM '(a b)) 表
>nil
---------------------------
(Null s-exp)
(Null a)
>Nil
---------------------------
(Quote s-exp)
(Quote (a b c)) = '(a b c)
>(a b c)
---------------------------
(Setq var value)
(Setq x 3)
>x=3
---------------------------
(LIST s-exp1 s-exp2)
(LIST 'A '(B C))
>(A (B C))
---------------------------
(APPEND List1 List2)
(APPEND '(A B) '(C D))
>(A B C D)
---------------------------
(EQ s-exp1 s-exp2) 判斷兩參數是否皆為原子且值相同
(EQ 'A 'A)
>T
---------------------------
(EQUAL s-exp1 s-exp2) 判斷兩參數值是否相同
(EQUAL 'A 'A )
>T
---------------------------
(COND (條件1 運算式1) (條件2 運算式2))
(COND ((ATOM '(a b))(setq a 1))((ATOM 'b)(setq b 3))(T (setq c 4)))
(Car list)
(Car '((a) b))
> (a)
---------------------------
(Cdr list)
(Cdr '(a(b c))
>((b c))
---------------------------
(Cons s-expression list)
(Cons '(a) '(b c))
>((a) b c)
---------------------------
(ATOM s-exp) 檢查是否為原子
(ATOM '(a b)) 表
>nil
---------------------------
(Null s-exp)
(Null a)
>Nil
---------------------------
(Quote s-exp)
(Quote (a b c)) = '(a b c)
>(a b c)
---------------------------
(Setq var value)
(Setq x 3)
>x=3
---------------------------
(LIST s-exp1 s-exp2)
(LIST 'A '(B C))
>(A (B C))
---------------------------
(APPEND List1 List2)
(APPEND '(A B) '(C D))
>(A B C D)
---------------------------
(EQ s-exp1 s-exp2) 判斷兩參數是否皆為原子且值相同
(EQ 'A 'A)
>T
---------------------------
(EQUAL s-exp1 s-exp2) 判斷兩參數值是否相同
(EQUAL 'A 'A )
>T
---------------------------
(COND (條件1 運算式1) (條件2 運算式2))
(COND ((ATOM '(a b))(setq a 1))((ATOM 'b)(setq b 3))(T (setq c 4)))
沒有留言:
張貼留言