Skip to content

Instantly share code, notes, and snippets.

@danking
Created May 20, 2013 20:25
Show Gist options
  • Select an option

  • Save danking/5615217 to your computer and use it in GitHub Desktop.

Select an option

Save danking/5615217 to your computer and use it in GitHub Desktop.
#lang racket
;; Report each unique line from stdin
(let ([saw (make-hash)])
(for ([line (in-lines)])
(unless (hash-ref saw line #f)
(displayln line))
(hash-set! saw line #t)))
;; do it purely.
(for/fold ([seen (set)])
([line (in-lines)])
(unless (set-contains? seen line)
(displayln line))
(set-add seen line))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment