I'm trying to remove an item (file name) from a list, nothing I have done works, no remove functions from the documentation, nothing from this website.. here is my code:
#lang racket
(define file-collection '())
(for ([f (directory-list)] #:when (regexp-match? "\\.log$" f))
(set! file-collection (foldr cons (list f) file-collection)))
(define (check-file file-in)
(for/list ([i (file->lines file-in)])
(cond ((equal? i "[robot warrior]") (remove file-in file-collection) ))))
(for ([i file-collection])(check-file i))
still, no matter what I try, file-collection remains the same and all files are included in the collection.. however, if i use displayln file-in, only the files without [robot warrior] are displayed, and that's perfect, thats what I need, but I need to store it somehow. I find it very odd/weird how it refuses to work.
Here is two ways to remove certain files from a list.
The result is:
Note that both
for/list
andfilter
rather han removing elements from an existing list produces new lists with the same elements (and omitting "file2" in this case).