(define (parse initial callback)
;; Construct and return a purely-functional parser of length-ten
;; strings.
;; `initial' is the initial data to process.
;; `callback' is a function to call with length-ten strings.
;; The return value is a function which accepts data as an
;; argument. The return value of *that* is a function with an
;; identical signature. When you want to push more data into the
;; parser, always pass it to the most recently returned function.
(lambda (data)
(let ([buf (string-append initial data)])
(if (>= (string-length buf) 10)
(begin
(callback (substring buf 0 10))
(parse (substring buf 10) callback))
(parse buf callback)))))
(((((parse "hello" write) " world") " radix") " is") " here!!!!!!!!!!!!!!!")
No comments:
Post a Comment