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

DSL でナンデモプログラミング!? / dsl-programming

874fb6168eaee95c155b850a934de418?s=47 Watson
October 13, 2016

DSL でナンデモプログラミング!? / dsl-programming

TeX と Vim script を比較してみた

874fb6168eaee95c155b850a934de418?s=128

Watson

October 13, 2016
Tweet

Transcript

  1. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ DSL ͰφϯσϞϓϩάϥϛϯάʂʁ ʙTEX ͱ Vim script Λൺֱͯ͠Έͨʙ ϫτιϯ

    (@Watson_DNA) Yokohama.vim #8 2016 ೥ 10 ݄ 16 ೔ 1 / 10
  2. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ ࣗݾ঺հ ϫτιϯ (@Watson_DNA) ▶ ๭ T େֶ ཧֶ෦

    ੜ෺৘ใՊֶՊ ˠจࣈྻॲཧֶՊʹओʹ഑ྻղੳ ▶ ߴߍ࣌୅͸෼ࢠੜ෺ֶΛѪ͍ͯͨ͠ ˠ͍·͸਺ֶ΍৘ใՊֶʹڵຯ͕Ҡߦ ▶ झຯ͸ొࢁʢΫϥΠϛϯά΍୔ొΓ΋ؚΉʣ ˠࠓ೥͸ઇࢁ΋ߦ͖͍ͨɽ໋͕͍ͭ͋ͬͯ͘΋଍Γͳ͍ ▶ ΋ͪΖΜϓϩάϥϛϯά΋޷͖ େ޷͖ͳݴޠɿTEX (on L A TEX), Ruby ࢖ͬͨ͜ͱ͋ΔݴޠɿC/C++, R, Python, Scheme, etc. ▶ Vim ઓಆྗ͸ 315ʢ2016 ೥ 10 ݄ 16 ೔ݱࡏʣ 2 / 10
  3. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ DSL ͱ͸ ఆٛ C ΍ Python ͳͲͷϓϩάϥϛϯάݴޠΛʮ൚༻ݴޠʯͱݺͿͷʹ ର͠ɼ͋Δಛఆͷछྨͷ໰୊ʹಛԽͨ͠ίϯϐϡʔλݴޠΛ

    DSL ʢDomain Specific Language ʹυϝΠϯಛԽݴޠʣͱݺͿɽ ྫ ▶ ϋʔυ΢ΣΞهड़ɿVerilog, VHDL ▶ Ϗϧυπʔϧɿmake, Rake ▶ ͦͷଞɿAWK, HTML/CSS, SQL, yacc, VBA ͳͲͳͲ ΋ͪΖΜɼ૊൛ݴޠ TEX ΍ Vim script ΋ DSL ʹؚ·ΕΔʂ DSL + φϯσϞϓϩάϥϛϯά = τϯσϞϓϩάϥϛϯάʂʁ 3 / 10
  4. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ TEX ݴޠͱ͸ TEXʢTeX; ςϑ, ςοΫʣ ΞϝϦΧͷ਺ֶऀ Knuth ͕ࣗஶ

    The Art of Computer Programming Λ૊൛͢ΔͨΊ 1976 ೥ʹߟҊͨ͠૊൛ιϑτ΢ΣΞɽಛʹ਺ࣜ ͷॲཧʢ ඒ͠͞ʣʹఆධ͕͋Δɽ ζ(s) = ∞ ∑ n=1 1 ns = ∏ p:prime 1 1 − p−s ▶ Ұൠʹ͸ L A TEX ౳ͷϚΫϩύοέʔδΛಡΈࠐ·ͤͯ࢖͏ ▶ εϥΠυ༻ͷ Beamer ͱ͍͏จॻΫϥε΋ʢຊࢿྉ͕࣮ྫʣ ˠ Vim ͰεϥΠυ࡞੒Մೳʂ Vimmer ͷօ͞ΜʹΦεεϝʂ ▶ ૊൛ʹಛԽͨ͠ DSLʢTEX ݴޠʣͷΠϯλϓϦλͰ΋͋Δ ▶ TEX ݴޠ͸νϡʔϦϯά׬શੑΛ΋ͭ 4 / 10
  5. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ Vim script ͱ͸ʢऍՠʹઆ๏ʣ VimʢVi IMproved; ϰΟϜ, ϰΟΞΠΤϜʣ ΦϥϯμͷϓϩάϥϚ

    Moolenaar ʹΑͬͯ 1980 ೥୅ʹ։ൃ͞ΕͨςΩετΤσΟλɽ ಛʹϓϩάϥϚͷؒͰ޿͘Ѫ͞Ε͍ͯΔɽ ߴ͍ΧελϚΠζੑ͸ͦͷಛ௃ͷ 1 ͭɽ ▶ Vim script ͱ͍͏ಈతܕ෇͚ݴޠ͕૊Έࠐ·Ε͍ͯΔ ˠઃఆϑΝΠϧ΍ϓϥάΠϯʹෳࡶͳॲཧΛهड़Մೳ ▶ Vim script ͸νϡʔϦϯά׬શ ˠͦ΋ͦ΋ vi ͷΩʔόΠϯυࣗମ͕νϡʔϦϯά׬શʁ ▶ “VimScript” ΍ “VimL” ͳͲ͸ਖ਼͘͠ͳ͍දه ˠͳ͔ͳ͔ “TeX” ͱॻ͍ͯ΋Β͑ͳ͍ TEX ͱࣅ͍ͯΔʁ 5 / 10
  6. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ ΫΠοΫιʔτΛ࣮૷ͯ͠Έͨ TEX ࣮૷ Vim script ࣮૷ ιʔείʔυɿhttps://git.io/vPu97 6

    / 10
  7. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ ϕϯνϚʔΫ ଌఆ৚݅ ▶ 10 ສཁૉ·Ͱͷ੔਺഑ྻΛιʔτ͢Δͷʹ͔͔ͬͨ࣌ؒ ▶ ೖྗ͸ҎԼͷϫϯϥΠφʔͰ࡞੒ (n

    = 3, 4, 5) $ ruby -e "puts Array(1..10**n).shuffle" ▶ ֤αΠζʹ͖ͭ 10 ճͣͭܭଌͨ͠ฏۉ஋ͱͯ͠ࢉग़ ▶ ٕज़త໰୊ʹΑΓೖྗͷಡΈࠐΈ࣌ؒ౳΋ؚΉ ଌఆ݁Ռʢ୯Ґɿmsʣ ཁૉ਺ C ݴޠ TEX ݴޠ Vim script 1,000 3.75 × 10−1 1.45 × 102 2.53 × 102 10,000 3.49 × 100 3.19 × 102 1.90 × 103 100,000 3.65 × 101 3.96 × 103 4.37 × 104 7 / 10
  8. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ ײ૝ͳͲ ▶ ࣮ߦ଎౓͕ͱͯ΋஗͍ ˠ C ݴޠ ≫ ʢӽ͑ΒΕͳ͍นʣ

    ≫ TEX ݴޠ ≥ Vim script ▶ ݴޠ࢓༷͕ͱͯ΋ΞϨ ▶ TEX ݴޠɿϨδελͷ্ݶɼ੍ޚ௲ͷཏྻɼల։ͱධՁ ▶ Vim scriptɿه߸|΍"ͷڍಈɼίϚϯυͷཏྻɼؔ਺໊ ˠͦΕͧΕྺ࢙తࣄ৘͕͋ΔͷͰɼ͋Δఔ౓࢓ํͳ͍ ▶ Vim script ͸ʢTEX ݴޠͱൺֱ͢ΔͱʣαΫοͱॻ͚Δ ▶ ϕϯνϚʔΫΛऔΔࡍͷγΣϧ͕ܳҰ൪ਏ͔ͬͨ ˠ Vim ͷىಈ࣌Φϓγϣϯଟ͗͢Ͱ͸ʂʁʢศར͚ͩͲʣ ࠷ޙʹ࢒ͬͨ΋ͷʜʜ ָ͍͠ʋ (ɾ˲ɾ) ůʋ (ɾ˲ɾ) ůʋ (ɾ˲ɾ) ůͱ͍͏ؾ࣋ͪ 8 / 10
  9. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ ೔ຊʹ͓͚Δαϙʔτମ੍ TEX ίϛϡχςΟ ▶ TEX Forum ͕த৺ http://oku.edu.mie-u.ac.jp/tex

    ▶ Q&A ܗࣜ ▶ ࣭໰ͷ࢓ํʹίπ͕ඞཁ ▶ TEX Ϣʔβͷू͍ 2016 11 ݄ 5 ೔ˏ۝भେֶ ▶ ๭ T େʹ͸Ѫ޷ձ͕ଘࡏ Vim ίϛϡχςΟ ▶ Lingr ͷ Vim ෦԰͕த৺ http://lingr.com/room/vim ▶ ৗ࣌ٞ࿦ ▶ ࣭໰ͯ͠΋ྑ͍ͷ͔ ▶ VimConf 2016 11 ݄ 5 ೔ˏϛΫγΟʢौ୩ʣ ▶ ༷ʑͳ৔ॴͰ {city}.vim ։࠵ ͍ͣΕ΋ Twitter Ͱαϙʔτͯ͠΋Β͑Δ͜ͱ͕͋Δʂ 9 / 10
  10. DSL ͰφϯσϞϓϩάϥϛϯάʂʁ ຊ౰ʹ DSL + φϯσϞϓϩάϥϛϯά = τϯσϞϓϩάϥϛϯά ͸ true

    ਅͩΖ͏͔ʁ ▶ DSL ͸ιϑτ΢ΣΞར༻ऀͷ͙ͦ͢͹ʹ͍Δଘࡏ ˠϑϩϯτΤϯυͷར఺Λଘ෼ʹ׆͔ͤΔ ▶ ͔ͤͬ͘ॻ͍ͨϓϩάϥϜɼ୭͔ʹ࢖ͬͯ΋Β͍͍ͨ ˠχον͔ͩΒɼϥΠόϧ͸গͳ͍ ▶ ϚΠφʔͰ΋ɼॿ͚ͯ͘ΕΔਓ͸͍Δ ˠ஥͕͍ؒΕ͹ɼಆ͍͚ͬͯΔ Բͤͣॻ͚͹ɼ͖ͬͱ޾ͤʹͳΕΔʂ 10 / 10