X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=exercices%2Flists.lsp;h=35590dada335ff070e4a9546859cdafbe8777b1c;hb=7c69bee537f3343712cfa6b35b6433c9f8cb3459;hp=25360bcf166d051570501485b0e2ed6ddb61c5ca;hpb=f1823b2e26078df70254dca41b2f1e5af4443809;p=TD_LISP.git diff --git a/exercices/lists.lsp b/exercices/lists.lsp index 25360bc..35590da 100755 --- a/exercices/lists.lsp +++ b/exercices/lists.lsp @@ -46,11 +46,11 @@ ;(trace true) -(define (rang x L) - (if (boolmemrec x L) +(define (rang E L) + (if (boolmemrec E L) (cond - ((= x (first L)) 0) - ((+ 1 (rang x (rest L))))) + ((= E (first L)) 0) + ((+ 1 (rang E (rest L))))) nil)) (println "rang/find") (println (rang 4 L)) @@ -60,11 +60,11 @@ ;(trace nil) -(define (tete n L) +(define (tete N L) (cond ((null? L) '()) - ((= n 0) '()) - ((cons (first L) (tete (- n 1) (rest L)))))) + ((= N 0) '()) + ((cons (first L) (tete (- N 1) (rest L)))))) (println "tete/slice") (println (tete 3 L)) (println (slice L 0 3)) @@ -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) @@ -144,20 +144,20 @@ (println (reverseL L)) (println (reverse L)) -(define (list< n L) +(define (list< N L) (cond ((null? L) '()) - ((>= (first L) n) (list< n (rest L))) - ((cons (first L) (list< n (rest L)))))) + ((>= (first L) N) (list< N (rest L))) + ((cons (first L) (list< N (rest L)))))) (println "list<") (println (list< 5 L)) (println (list< 5 C)) -(define (list>= n L) +(define (list>= N L) (cond ((null? L) '()) - ((< (first L) n) (list>= n (rest L))) - ((cons (first L) (list>= n (rest L)))))) + ((< (first L) N) (list>= N (rest L))) + ((cons (first L) (list>= N (rest L)))))) (println "list>=") (println (list>= 5 C)) @@ -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)) @@ -180,20 +180,46 @@ (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)) +;(println "replace") +;(println L1) +;(println L2) +;the replace function modify the passed argument +;(println (replace 'B L1)) +;(println (replace '? L1)) +;(println (replace '? L2)) +;(println L1) +;(println L2) (define (filtre L1 L2 C) + ;the replace function modify the passed argument + ;FIXME: use the function argument C + (replace '? L1) + (replace '? L2) (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 ?)) +(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)