請問有關LISP的一些問題
感謝您這個論壇
讓我了解LISP的基礎指令與用法 不瞞您說,這是我的這次作業,LISP是我第一次觸碰
有些問題想請教您
這是題目的要求
Write the functions initialize, push, top, pop, and list-stack to maintain a global stack. These functions should behave:
>( initialize)
nil
>( push ‘foo)
foo
>( push ‘bar)
bar
>( list-stack)
(bar foo)
>( pop)
bar
>( list-stack)
(foo)
下面是我寫的
(defun initialize ()
(setq x nil)
)
(defun pus (n)
(push n x)
)
(defun po ()
(pop x )
)
(defun list-stack()
(list x )
)
有一些地方不是很了解~
1.如果依題目的意思 我該如何寫出,與指令PUSH與POP同名的function ??
(在定義時,不能使用一樣的名稱,所以我改成pus與po)
2.在執行後 我的括號,會多一圈 (直接使用push pop指令也是會出現)
>( initialize)
nil
>( pus ‘foo)
(foo)
>( pus ‘bar)
(bar)
>( list-stack)
((bar foo))
>( po)
(bar)
>( list-stack)
((foo))
Symbols(字符)
symbol 就是一串字元,不過這串字元裡面可以使用的字元跟起始的第一個字元是稍有限制的,
但是原則上只要你使用〝大小寫字母、數字、減號(連接符號)〞來混合產生 symbol,應該就不會有問題。
(如果你只有使用使用數字的,並且至多在拿減號當啟始字元,那將會被 Lisp 視為是數字,而不是 symbol 。)
是這個問題嗎?