;;AUTOLOAD: filter-list
;;AUTODOC: filter-list "filters a list through a regexp or a predicate"
Usage: (filter-list LIST REGEXP)
        (filter-list LIST FUNCTION)

Builds a new list that contains the items statisfying the FUNCTION condition, 
or matching the REGEXP. If you're using a REGEXP, list elements must be 
convertible to String. Else the FUNCTION must have one parameter.

? (filter-list '(toto 347 "abc" "rty" "a34g") "a.*")
 = (abc a34g)
(filter-list '(toto 347 "abc" "rty" "a34g") (lambda(i) (typep i Number)))
 = (347)

returns a modifiable list, never THE empty list


(defun filter-list (from filter)
  (with (to (list))
    (if 
      
      (typep filter String)
	    ;; String, use a regexp match
      (progn
	(with (re (regcomp filter))
	  (dolist (item from)
	    (if (regexec re (String item))
	      (lappen to item)))
      ))
      
      (typep filter Function)
	  ;; predicate, apply it
      (progn
	(with (result ())
	  (dolist (item from)
	    (setq result (apply filter (list item)))
	    (if result (lappend to item))
      )))
    )
	;; return nil instead of empty list
    (if to to ())
))
