Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Programming Language Crystal

Programming Language Crystal

#w8lt 第四回 (2015-07-29) の発表資料です
http://w8lt.connpass.com/event/16856/

Daisuke Fujita

July 29, 2015
Tweet

More Decks by Daisuke Fujita

Other Decks in Technology

Transcript

  1. Crystal • Ruby ͬΆ͍γϯλοΫε • ੩తܕνΣοΫ • Crystal ͷίʔυ಺Ͱ C

    ॻ͚Δ • ωΠςΟϒίʔυੜ੒ • Crystal -> LLVM IR -> ωΠςΟϒ http://crystal-lang.org/ https://github.com/manastech/crystal
  2. Crystal • Initial commit ͸ 2012-09-04 • v0.1.0 ͸ 2014-06-19

    • ݱࡏ͸ v0.7.4 (2015-06-24) http://crystal-lang.org/ https://github.com/manastech/crystal
  3. Crystal • Πϯετʔϧ (Mac OS X): • Try it online:

    http://play.crystal-lang.org/ $ brew tap manastech/crystal $ brew update $ brew install crystal-lang
  4. Crystal • Πϯετʔϧ (Mac OS X): • Try it online:

    http://play.crystal-lang.org/ $ brew tap manastech/crystal $ brew update $ brew install crystal-lang CSFXOQNͰDSZTUBMೖΕͯΔͱ
 1"5)ʹΑͬͯ͸Ϳ͔ͭΔ Ϳ͔ͭͬͨ DSZTUBM͸
 ·͕͍ͪ
  5. Crystal • εΫϦϓτ࣮ߦ • όΠφϦϏϧυ & ࣮ߦ: • ࠷దԽϏϧυ &

    ࣮ߦ $ crystal [run] hoge.cr $ crystal build hoge.cr $ ./hoge $ crystal build hoge.cr --release $ ./hoge
  6. Ruby ͱͷҧ͍ • Ҿ਺ʹܕࢦఆͰ͖Δ def hoge(n : Int) • γϯάϧΫΥʔτͩΊ

    • Bool ஋͸ Bool ϦςϥϧɺΫϥε͡Όͳ͍ • RubyGems తͳύοέʔδγεςϜແ͍ • (crystal#220) • ࣗલͷґଘ؅ཧγεςϜ͕͋Δ $ crystal deps • ඪ४ϥΠϒϥϦʹ͍Ζ͍ΖἧͬͯΔ • ͳͲͳͲ $VSTFT )551 .BSLEPXO 0"VUI 4QFDʜ
  7. ஛಺ؔ਺ #!/usr/bin/env crystal def tarai(x, y, z) return y if

    x <= y tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y)) end puts tarai(13, 10, 0) #!/usr/bin/env ruby def tarai(x, y, z) return y if x <= y tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y)) end puts tarai(13, 10, 0)
  8. ஛಺ؔ਺ #!/usr/bin/env crystal def tarai(x, y, z) return y if

    x <= y tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y)) end puts tarai(13, 10, 0) #!/usr/bin/env ruby def tarai(x, y, z) return y if x <= y tarai(tarai(x - 1, y, z), tarai(y - 1, z, x), tarai(z - 1, x, y)) end puts tarai(13, 10, 0) ιʔείʔυ͸ શ͘ಉ͡ ճ UBSBJݺͼग़͠
  9. ஛಺ؔ਺ 3VCZ $SZTUBM ͦͷ·· $SZTUBM Ϗϧυࡁ $SZTUBM ࠷దԽࡁ UBSBJ 

      T T T T ͦͷ··Y όΠφϦϏϧυY
  10. ؆୯ͳ HTTP αʔό #!/usr/bin/env crystal require "http/server" server = HTTP::Server.new(8080)

    do |request| HTTP::Response.ok "text/plain", "Hello world!" end server.listen #!/usr/bin/env ruby require "rack" app = Proc.new do |env| ["200", { "Content-Type" => "text/plain" }, ["Hello world!"]] end Rack::Handler::WEBrick.run(app, Port: 8080)
  11. ؆୯ͳ HTTP αʔό 3VCZ $SZTUBM ͦͷ·· $SZTUBM Ϗϧυࡁ $SZTUBM ࠷దԽࡁ

    ฒྻ SFRT 
 SFRT 
 SFRT 
 SFRT  SFRT $ ab -k -c 10 -n 10000 http://localhost:8080/
  12. ؆୯ͳ HTTP αʔό 3VCZ $SZTUBM ͦͷ·· $SZTUBM Ϗϧυࡁ $SZTUBM ࠷దԽࡁ

    ฒྻ SFRT 
 SFRT 
 SFRT 
 SFRT  SFRT $ ab -k -c 10 -n 10000 http://localhost:8080/ ͦͷ··Y ࠷దԽϏϧυY