From f1823b2e26078df70254dca41b2f1e5af4443809 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 27 Apr 2017 22:42:43 +0200 Subject: [PATCH] More list exercise functions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- exercices/lists.lsp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/exercices/lists.lsp b/exercices/lists.lsp index 39114ad..25360bc 100755 --- a/exercices/lists.lsp +++ b/exercices/lists.lsp @@ -161,4 +161,39 @@ (println "list>=") (println (list>= 5 C)) +;(trace true) + +(define (qsort L) + (cond + ((null? L) '()) + ((append + ;the pivot is the first element of the list + (qsort (list< (first L) (rest L))) + (cons (first L) '()) + (qsort (list>= (first L) (rest L))))))) +(println "qsort") +(println (qsort C)) + +;(trace nil) + +;we suppose both lists are flat +(setq L1 '(A ? ? B C D ?)) +(setq L2 '(? A B ? C ? ? D)) + +(define (removeC c L) + (cond + ((null? L) '()) + ((= c (first L))) (removeC c (rest L)) + (((cons (first L) (removeC c (rest L))))))) +(println (removeC A L1)) + +(define (filtre L1 L2 C) + (cond + ((and (null? L1) (null? L2)) true) + ((and (not (null? L1)) (null? L2)) nil) + ((and (null? L1) (not (null? L2))) nil) + ((and (inclu L1 L2) (inclu L2 L1) true)))) +;(println "filtre") +;(println (filtre L1 L2 ?)) + (exit) -- 2.34.1