[plt-dev] Racket web page

From: Eli Barzilay (eli at barzilay.org)
Date: Tue May 25 13:35:12 EDT 2010

On May 25, Danny Yoo wrote:
> ;; gets the unique lines, although not guaranteeing order:
> (let ([a-ht  (for/fold ([a-ht #hash()])
>                                 ([line (in-lines (current-input-port))])
>          (hash-set a-ht line #t))])
>   (for ([line (in-hash-keys a-ht)])
>     (printf "~a~n" line)))

How about

  #lang racket
  (for ([line (in-list
                (sort (port->lines (current-input-port)) string<?)))])
    (printf "~a\n" line))

> ;; nl: show line numbers along the side
> (for ([line (in-lines (current-input-port))]
>       [no (in-naturals 1)])
>   (printf "~a: ~a~n" no line))
> #lang racket
> ;; Compute md5 checksum of the file given at the command line
> (require scheme/cmdline
>          file/md5)
> (printf "~a~n" (md5 (command-line #:args (filename) filename)))

Good points.  (But what's with the old "~n"s?)

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

Posted on the dev mailing list.