From: Ken A. <kan...@bb...> - 2004-08-17 14:13:29
|
At 08:30 PM 8/16/2004 -0400, Geoffrey Knauth wrote: >while(<>) { print if (/BEGIN/ .. /END/); } Perl is hard to beat for one liners. The best i could come up with was: (let ((flipFlop (.. (// "BEGIN") (// "END")))) (iterate (stdin) (_ (if (flipFlop _) (print _))))) Here's the rest of the code you'll need: (load "using/run.scm") This macro looks a little strange, but i find it very useful for writing one argument functions. (define-macro (_ . body) `(lambda (_) ,@body)) (define (stdin) (BufferedReader System.in$)) (define (// pattern) (lambda (x) (.matches x pattern))) (define (.. p1 p2 . inclusive?) (let ((state #f) (inclusive? (if (pair? inclusive?) (car inclusive?) #f))) (lambda (line) (if state (if (p2 line) (begin (set! state #f) inclusive?) #t) (if (p1 line) (begin (set! state #t) inclusive?) #f))))) k |