0
我在這裏要做的是首先弄平任何給定的列表,然後將該列表傳遞給我的加密函數。雖然這不起作用,我不知道爲什麼。 這裏是我到目前爲止,(通常lisp)展平和通過名單
(defun flatten (l)
(cond ((null l) l)
((atom l) (list l))
(t (loop for a in l appending (flatten a))))
)
(defun encrypt(enctext)
(flatten enctext)
(if(eq 'A (first enctext)) ;If the first charcater equals 'A'...
(progn ;To allow multiple statements in an if statement
(prinC#\B) ; First statement, print this character
(encrypt(rest enctext)))) ;Second statement, run function again passing the rest of the characters
(if(eq 'B (first enctext))
(progn
(prinC#\C)
(encrypt(rest enctext))))
)
這是如何我調用加密功能
(encrypt '((A)(B))
我應該叫我「加密」功能的「扁平化」的功能?或者在遞歸調用之後在「扁平化」函數中調用「加密」? 我該如何正確地通過展平名單?
謝謝!我試圖將一切都納入一個功能,但我甚至不知道你是否可以做到這一點。 – Jcan1995
@JoshuaCantero我添加了另一個例子,它不會變扁。 – jkiiski
是的,我注意到,它有很大的幫助。 – Jcan1995