Welcome to the CHICKEN Scheme pasting service

don't mind me, just pastin' added by anonymous on Thu Sep 20 13:39:05 2018

(require-extension (only srfi-1 filter))
(require-extension srfi-41)

(define-constant *time-frame*    10)
(define-constant *stream-length* 1000)
(define-constant *dict-size*     10)

(define (random-elem lst)
  (list-ref lst (random (length lst))))

(define dict
  (map string->symbol (take (read-lines "/usr/share/dict/words") *dict-size*)))

(define (random-word)
  (random-elem dict))

(define-stream (streaminate proc)
  (stream-cons (proc) (streaminate proc)))

(define-record entry timestamp key values)

(define-record-printer (entry x out)
  (fprintf out "#(entry ~s ~s ~s)"
           (entry-timestamp x) (entry-key x) (entry-values x)))

(define (generate-entry)
  (make-entry (inexact->exact (current-milliseconds)) (random-word) (list (random 256))))

(define input
  (streaminate generate-entry))

(define output

(define (parse-entries input output)
  (when (stream-null? input)
    (print "Reached end of stream.")
    (print "End result:")
    (for-each print output)
  (let* ((entry (stream-car input))
         (time (entry-timestamp entry))
         (key (entry-key entry))
         (values (entry-values entry))
         (keys (filter (lambda (x)
                         (eq? key (entry-key x))) output))
         (stamps (filter (lambda (x)
                           (<= time (+ (entry-timestamp x) *time-frame*))) keys)))
    (print "Received: " entry)
    (cond ((null? stamps)
           (print "No key matches \"" key "\" in the " *time-frame* " second range.")
           (print "Adding new entry for " entry)
           (parse-entries (stream-cdr input) (cons entry output)))
           (print "Found an entry for \"" key "\".")
           (print "Appending " entry)
           (entry-values-set! (car stamps)
                              (append (entry-values entry) (entry-values (car stamps))))
           (parse-entries (stream-cdr input) output)))))

(define (main args)
  (parse-entries (stream-take *stream-length* input) output))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Type in the text below:
 _   _     _            
| |_| |__ (_) ___ _ __  
| __| '_ \| |/ _ \ '_ \ 
| |_| |_) | |  __/ | | |
 \__|_.__/|_|\___|_| |_|
Visually impaired? Let me spell it for you (wav file) download WAV