Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Command Liner with Scala

1,376 views

Published on

Published in: Technology
  • Be the first to comment

Command Liner with Scala

  1. 1. Scala id:clairvy 2010/09/04 @Scala 01
  2. 2. Scala id:clairvy 2010/09/04 @Scala 01
  3. 3. • id:clairvy ( •4 PHPer • Perl
  4. 4.
  5. 5. Church 0 := λf x. x • 1 := λf x. f x • :
  6. 6. object Main { override def main(args : Array[String]) {   println("zero: " + zero(0)(i => i +1))   println("one: " + succ[Int](zero)(0)(i => i + 1))   def zero[A](i : A) = (f : A => A) => i   def succ[A](n : A=>(A=>A)=>A) = (i:A)=>(f:A=>A)=>f(n(i)(f)) } }
  7. 7. • [Int]
  8. 8. • [Int] •
  9. 9. • [Int] • •
  10. 10. Android Recipes with Scala
  11. 11. Android Recipes with Scala • 108104 1 …
  12. 12. Android Recipes with Scala • 108104 1 … • id:papamitra …
  13. 13. Android Recipes with Scala • 108104 1 … • id:papamitra … • @gabu …
  14. 14. Android Recipes with Scala • 108104 1 … • id:papamitra … • @gabu … • Recipe001 YO
  15. 15. orz
  16. 16. orz • OCamlMeetingNagoya
  17. 17. orz • OCamlMeetingNagoya • OCamlGolf sort
  18. 18. orz • OCamlMeetingNagoya • OCamlGolf sort •
  19. 19.
  20. 20. • •
  21. 21. • • •
  22. 22. • scala + zsh
  23. 23. export JAVACMD=$HOME/local/bin/java function scall () { local f while getopts 'e:B:E:' opt; do case $opt in B) B=$OPTARG;; E) E=$OPTARG;; e) f=$OPTARG;; esac done shift $((OPTIND - 1)) if [[ x"$f" == x"" ]]; then f='println' fi scala -e "import scala.io._;$B; (if(args.length>0)args.map(arg=>Source.fromFile(arg, "UTF-8"))else Array(Source.stdin)).foreach(s=>s.getLines.foreach($f));$E" "$@" }
  24. 24. #compdef scall function _scall () { _arguments : '-h[Show message and exit]' '-e[Specify expression to run with each line]:Expression' '-B[Specify expression to run on begin of program]:Expression' '-E[Specify expression to run on end of program]:Expression' '*:argument:_files' }
  25. 25. • Zsh •
  26. 26. • …
  27. 27. $ time (scall ~/.zshrc > /dev/null) (; scall ~/.zshrc > /dev/null; ) 1.76s user 0.17s system 42% cpu 4.536 total $ time (cat ~/.zshrc > /dev/null) (; cat ~/.zshrc > /dev/null; ) 0.00s user 0.00s system 61% cpu 0.004 total $ time (perl -pe1 ~/.zshrc > /dev/null) (; perl -pe1 ~/.zshrc > /dev/null; ) 0.00s user 0.00s system 52% cpu 0.008 total
  28. 28.
  29. 29. object Scall { import scala.tools.nsc._ import scala.io._ def main(args : Array[String]) { // val interp : Interpreter = new Interpreter() val script = "((" + begin + "), (" + expression + "), (" + end + "))" var result : (()=>Unit, (String)=>Unit, ()=>Unit) = null interp.eval[(()=>Unit, (String)=>Unit, ()=> Unit)](script) match { case Some(ret) => result = ret; case _ => println("compile error");exit(1); } result._1() (if (files.length > 0) files.map(f=>Source.fromFile(f)) else List(Source.stdin)).foreach(f=>f.getLines.foreach((l:String)=>re sult._2(l))) result._3() } }
  30. 30. … • … •
  31. 31. # $ time (scall ~/.zshrc > /dev/null) (; scala-2.8 -deprecation -cp com.myexample.Scall ~/.zshrc > / dev/null; ) 13.35s user 0.75s system 72% cpu 19.502 total $ time (cat ~/.zshrc > /dev/null) (; cat ~/.zshrc > /dev/null; ) 0.00s user 0.00s system 61% cpu 0.004 total $ time (perl -pe1 ~/.zshrc > /dev/null) (; perl -pe1 ~/.zshrc > /dev/null; ) 0.00s user 0.00s system 52% cpu 0.008 total
  32. 32. • (by )

×