Skip to content

Instantly share code, notes, and snippets.

@kiyoka
Created April 4, 2012 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiyoka/afe3903231307738fd56 to your computer and use it in GitHub Desktop.
Save kiyoka/afe3903231307738fd56 to your computer and use it in GitHub Desktop.
Nendo sample for Enumerable::Lazy of Ruby 2.0
#!/bin/sh
:; #-*- mode: nendo; syntax: scheme -*-;;
:; exec /usr/local/bin/nendo $0 $*
(define (grep-and-take5 in)
(let1 arr
(.
(. (map (lambda (x) x.chomp) in) grep #/ruby/)
take 5)
(for-each print arr)))
(define (main argv)
(with-open "test.txt"
(lambda (f)
(cond
((< 0 (length argv))
(print "[with Lazy]")
(grep-and-take5 f.lazy))
(else
(print "[without Lazy]")
(grep-and-take5 f)))))
;; print the peek memory usage of this process.
(with-open "|cat /proc/#{Process.pid}/status"
(lambda (f)
(print (+ "=> " (car (to-list (f.readlines.grep #/vmpeak/i))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment