[plt-scheme] help writing idiomatic plt scheme
Just ignore my code above , i incorrectly read the problem statement.
Apologies to all.
Veer
On Mon, Jun 16, 2008 at 12:44 AM, Veer <diggerrrrr at gmail.com> wrote:
> I might as well try :
>
> ;;multi-filter : (string->boolean) port -> (list (listof string)
> (listof string) string)
> ;;to produce a list such that it simulates (list (filter f lst)
> (filter neg-f lst) extra)
> (define (multi-filter f in)
> (local ((define (multi-filter-accum in L R S)
> (local ((define a-line (read-line in)))
> (cond
> [(eof-object? a-line) (list L R S)]
> [(f a-line) (multi-filter-accum in (cons a-line L) R
> (string-append S
> (substring a-line 0 1)))]
> [else (multi-filter-accum in L (cons a-line R)
> (string-append S (substring
> a-line 0 1)))]))))
> (multi-filter-accum in empty empty "")))
>
> ;;expression
> (local ((define ALL (multi-filter (lambda (s) (char=? (string-ref s 0) #\#))
> (open-input-file "line-ex")))
> (define line-# (map (lambda (s) (substring s 1)) (first ALL)))
> (define line-= (map (lambda (s) (substring s 1)) (second ALL)))
> (define str-acc (third ALL)))
> (list line-# line-= str-acc))
>
>
> If only S could be somehow made optional or not reqd then
> multi-filter can be useful in other cases i guess.
>
> Veer
>