X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=exercices%2Flists.lsp;h=35590dada335ff070e4a9546859cdafbe8777b1c;hb=7c69bee537f3343712cfa6b35b6433c9f8cb3459;hp=e97d74796833b3869973bd155c33bb1b69a650d4;hpb=d4b2508d9663596624e7f44c701147c27c6cceb2;p=TD_LISP.git diff --git a/exercices/lists.lsp b/exercices/lists.lsp index e97d747..35590da 100755 --- a/exercices/lists.lsp +++ b/exercices/lists.lsp @@ -118,11 +118,11 @@ (define (aplatir L) (cond - ((null? L) nil) - ((atom? L) (list L)) ;FIXME: the "casting" is not working properly + ((null? L) '()) + ((atom? L) (list L)) ((append (aplatir (first L)) (aplatir (rest L)))))) (println "aplatir/flat") -;(println (aplatir T)) +(println (aplatir T)) (println (flat T)) ;(trace nil) @@ -169,7 +169,7 @@ ((append ;the pivot is the first element of the list (qsort (list< (first L) (rest L))) - (cons (first L) '()) + (list (first L)) (qsort (list>= (first L) (rest L))))))) (println "qsort") (println (qsort C)) @@ -202,5 +202,24 @@ ((and (inclu L1 L2) (inclu L2 L1) true)))) (println "filtre") (println (filtre L1 L2 ?)) +(println (filtre L M ?)) + +;algorithm written on the board +(define (filtrerec L1 L2 C) + ;FIXME: use the function argument C + (cond + ((null? L1) + (cond + ((null? L2) true) + ((= '? (first L2)) (filtrerec L1 (rest L2))) + (nil))) + ((null? L2) (filtrerec L2 L1)) + ((= '? (first L1)) (filtrerec (rest L1) L2)) + ((= '? (first L2)) (filtrerec L1 (rest L2))) + ((= (first L1) (first L2)) (filtrerec (rest L1) (rest L2)) ) + (nil))) +(println "filtrerec") +(println (filtrerec L1 L2 ?)) +(println (filtrerec L M ?)) (exit)