だからここに私が使用したいいくつかの定義されたリストがあります:
(DEFINE list0 (LIST 'j 'k 'l 'm 'n 'o 'j) )
(DEFINE list1 (LIST 'a 'b 'c 'd 'e 'f 'g) )
(DEFINE list2 (LIST 's 't 'u 'v 'w 'x 'y 'z) )
(DEFINE list3 (LIST 'j 'k 'l 'm 'l 'k 'j) )
(DEFINE list4 (LIST 'n 'o 'p 'q 'q 'p 'o 'n) )
(DEFINE list5 '( (a b) c (d e d) c (a b) ) )
(DEFINE list6 '( (h i) (j k) l (m n) ) )
(DEFINE list7 (f (a b) c (d e d) (b a) f) )
私がやりたいのは、次のように実行する「endsmatch」関数の再帰関数を作成することです。
ENDSMATCH:
リストの最初の要素がリストの最後の要素と同じである場合は戻り、それ以外の場合は戻り
(endsmatch 1st)
ます。あれは、#t
#f
(endsmatch '(s t u v w x y z) )
戻る/戻る必要があります:
#f
(endsmatch (LIST 'j 'k 'l 'm 'n 'o 'j)
戻る/戻る必要があります:
#t
と
両方(endsmatch '())
と(endsmatch '(a))
戻る必要があり#t
ます、など。
また、関数は次のような複雑なリストを読み取ることができます。
(endsmatch '((a b) c (d e d) c (a b)) )
これにより、次が返されます
#t
。
(endsmatch '((a b) c (d e d) c (b a)) )
(endsmatch '((y z) y) )
両方が戻る必要があります#f
私はスキームに不慣れで、それがどのように見えるかを見るので、この関数はどのようにコーディングできますか、よろしくお願いします。