Slide 1

Slide 1 text

DDD@H ৽͍͠ϓϩάϥϛϯάݴޠͷֶͼํ )551αʔόʔΛ࡞ֶͬͯͿ
 +BWB 4DBMB $MPKVSF ++6($$$'BMM !UPEPLS ָ͍͠

Slide 2

Slide 2 text

IUUQTUXJUUFSDPNNBUUO@KQTUBUVT

Slide 3

Slide 3 text

IUUQTUXJUUFSDPNNBUUO@KQTUBUVT

Slide 4

Slide 4 text

DDD@H DDD@H

Slide 5

Slide 5 text

DDD@H ୭ͩ ాॴॣ༎!UPEPLS w גࣜձࣾϏζϦʔν4DBMBΤϯδχΞ w ٻਓݕࡧΤϯδϯ8FCΫϩʔϥʔ΍޿ࠂγεςϜ։ൃͳͲ w Ұ෦ͷਓ͔Β͸ΤϞδχΞͱݺ͹Ε͍ͯ·͢ w จࣈίʔυͱ͔&NBDT͕޷͖ͳωΦ࿝֐

Slide 6

Slide 6 text

DDD@H ৽͍͠ϓϩάϥϛϯάݴޠΛֶͿ w εΩϧ΍ϓϩάϥϛϯάελΠϧͷ෯Λ޿͛ΔͨΊ w ७ਮʹָ͠ΈͷͨΊ

Slide 7

Slide 7 text

DDD@H ֶͿखஈͷҰͭͱͯ͠ )551αʔόʔ։ൃ͕
 ͓͢͢ΊͰ͢

Slide 8

Slide 8 text

DDD@H

Slide 9

Slide 9 text

DDD@H

Slide 10

Slide 10 text

DDD@H

Slide 11

Slide 11 text

DDD@H ͓࿩͢͠Δ͜ͱ w ͳͥ)551αʔόʔ w 4DBMB $MPKVSFʹ͍ͭͯ w )551αʔόʔΛ࡞Γͳ͕Βֶ΅͏ w ͬ͘͟ΓΞʔΩςΫνϟ w ֤ݴޠͰ࣮૷ͯ͠ΈΔ w 4PDLFUͷѻ͍ w ਖ਼نදݱ w Ϧιʔεͷ։์ w ฒྻॲཧ w จࣈྻͷѻ͍ w ·ͱΊ

Slide 12

Slide 12 text

DDD@H IUUQTHJUIVCDPNUPEPLSTJNQMFIUUQTFSWFS

Slide 13

Slide 13 text

DDD@H ͳͥ)551αʔόʔʁ

Slide 14

Slide 14 text

DDD@H ৽͍͠ݴޠΛֶͿ࣌ʹΑ͘΍Δ͜ͱ w )FMMPXPSME 'J[[#V[[Λ΍Δ w ॻ੶ΛಡΉ w 50%0ΞϓϦͳͲ؆୯ͳ8FCαʔϏεΛ࡞Δ w FUD

Slide 15

Slide 15 text

DDD@H ৽͍͠ݴޠΛֶͿ࣌ʹΑ͘΍Δ͜ͱ w )FMMPXPSME 'J[[#V[[Λ΍Δ w ॻ੶ΛಡΉ w 50%0ΞϓϦͳͲ؆୯ͳ8FCαʔϏεΛ࡞Δ w FUD

Slide 16

Slide 16 text

DDD@H 8FCαʔϏεʁ

Slide 17

Slide 17 text

DDD@H 8FCαʔϏεʹ͸%#͕͋Δ w ͱΓ͋͑ͣ)Ͱྑ͍͔ʜ w .Z42-8PSL#FODIͰ࡞ͬͨ%%-͕ྲྀͤͳ͍ʂ w ϩʔΧϧͷ.Z42-͕ݹ͍ɻCSFXVQEBUFʂ w ͍΍VQHSBEFͩͬͨ w %PDLFS ͱ͔͍͏΍ͭͰ .Z42-Λಈ͔͢ͷ͕
 φ΢͍ΜͰ͔͢Ͷ w IFSPLV͸1PTUHSF42-ͳΜͩͬͨ

Slide 18

Slide 18 text

DDD@H 8FCαʔϏεʹ͸ը໘͕͋Δ w ͱΓ͋͑ͣద౰ʹCPPUTUSBQͰ࡞Ζ͏ʂ w ΄͏΄͏ɺ4FNBOUJD6*ͷ΄͏͕ΠϚυΩͬΆ͍Β͍͠ w ςϯϓϨʔτΤϯδϯʁ࣌୅͸41"Ͱ͠ΐ w ੜ$44ਏ͍͔Β4BTTʹ͠Α͏ w 8FCQBDL CBCFMMPBEFS ͳʹͦΕ͓͍͍͠ͷʁ w EJW͕தԝʹدΒͳ͍

Slide 19

Slide 19 text

DDD@H ͦΕͬͯ΍Γ͍ͨ͜ͱ͚ͩͬʁ

Slide 20

Slide 20 text

DDD@H %POUTIBWFUIBUZBL w ผʹ%#Λ৮Γ͍ͨΘ͚Ͱ͸ͳ͍ w ผʹը໘Λ࡞Γ͍ͨΘ͚Ͱ͸ͳ͍ w ৽͍͠ݴޠΛֶͼ͍ͨ

Slide 21

Slide 21 text

DDD@H ͦ͜Ͱ)551αʔόʔͰ͢Α

Slide 22

Slide 22 text

DDD@H )551αʔόʔͳΒ w %#΍ը໘Λ༻ҙ͢Δखؒͳ͘ɺखܰʹ։ൃ͕࢝ΊΒΕΔ w 8FC։ൃʹඞཁͳཁૉʹͦͦ͜͜Ұ௨Γ৮ΕΒΕΔ w จࣈྻૢ࡞ɺೖग़ྗɺฒྻॲཧͳͲ w ҧ͏ݴޠɺಉ͡࢓༷Ͱ࡞Ε͹ݴޠͷൺֱ΋͠΍͍͢

Slide 23

Slide 23 text

DDD@H )551αʔόʔͬͯԿͯ͠Δͷʁ

Slide 24

Slide 24 text

DDD@H )551αʔόʔ͕΍͍ͬͯΔ͜ͱ w ΫϥΠΞϯτ͔Βͷ઀ଓΛ଴ͪड͚ w ΫϥΠΞϯτ͔ΒૹΒΕ͖ͯͨ)551ϦΫΤετΛύʔε w ϦΫΤετʹج͍ͮͯ)551ϨεϙϯεΛੜ੒ w ΫϥΠΞϯτʹϨεϙϯεΛฦ͢

Slide 25

Slide 25 text

DDD@H )551ͷ࢓༷ w 3'$ʢ3FRVFTU'PS$PNNFOUTʣ w *&5'ʹΑΔٕज़࢓༷ͷอଘɺެ։ܗࣜ w ϓϩτίϧ΍ϑΝΠϧϑΥʔϚοτͳͲ͕த৺ w )551͸3'$d

Slide 26

Slide 26 text

DDD@H IUUQTUPPMTJFUGPSHIUNMSGD

Slide 27

Slide 27 text

DDD@H IUUQIUUQXHPSH

Slide 28

Slide 28 text

DDD@H ؆қͳ࣮૷ͳΒ਺ඦߦఔ౓

Slide 29

Slide 29 text

DDD@H 1ZUIPOͷ4JNQMF)5514FSWFS w 1ZUIPOͷ4JNQMF)5514FSWFSΛࢀߟʹ͢Δͷ΋̋ w ܥ w ܥ $ python -m SimpleHTTPServer $ python -m http.server

Slide 30

Slide 30 text

DDD@H 4DBMB$MPKVSF

Slide 31

Slide 31 text

DDD@H 4DBMB

Slide 32

Slide 32 text

DDD@H 4DBMB w +BWBͱͷ૬ޓӡ༻ੑ w γʔϜϨεͳݺͼग़͠ɺ+BWBඪ४ϥΠϒϥϦͷ࠶ར༻ w ؆ܿੑ w লུՄೳͳߏจɺܕਪ࿦ɺڧྗͳඪ४ϥΠϒϥϦ w ந৅౓ͷߴ͍ίʔυɺ৽੍͍͠ޚߏจΛఆٛͰ͖Δදݱྗ w 8IBUͷڧௐɺ)PXͷӅณ w ੩తܕ෇͚ w ݕূՄೳੑɺϦϑΝΫλͷ͠΍͢͞ɺυΩϡϝϯτੑ

Slide 33

Slide 33 text

DDD@H 4DBMBͬͯόϦόϦͷ
 ؔ਺ܕݴޠͳΜͰ͠ΐ

Slide 34

Slide 34 text

IUUQTMFBOQVCDPNGQNPSUBMTSFBE

Slide 35

Slide 35 text

IUUQTMFBOQVCDPNGQNPSUBMTSFBE

Slide 36

Slide 36 text

DDD@H 1MFBTF EPOUEPUIJTJO4DBMB .BSUJO0EFSTLZ

Slide 37

Slide 37 text

DDD@H 1MFBTF EPOUEPUIJTJO4DBMB .BSUJO0EFSTLZ ௨শখా޷ઌੜ

Slide 38

Slide 38 text

DDD@H 4DBMBͷ࡞ऀ 1MFBTF EPOUEPUIJTJO4DBMB .BSUJO0EFSTLZ ௨শখా޷ઌੜ

Slide 39

Slide 39 text

DDD@H ΦϒδΣΫτࢦ޲ͱؔ਺ܕͷʮ౷߹ʯ w ΦϒδΣΫτࢦ޲ͷ֓೦Ͱؔ਺ܕͷػೳΛղऍ ஋ΦϒδΣΫτ DBTFDMBTT ୅਺తσʔλܕ 001 '1

Slide 40

Slide 40 text

DDD@H $MPKVSF

Slide 41

Slide 41 text

DDD@H $MPKVSF w -JTQ w จ๏͕গͳ͍ɺσʔλͱͯ͠ͷίʔυ w ؔ਺ܕϓϩάϥϛϯάͷͨΊͷݴޠ w ୈҰڃؔ਺ɺΠϛϡʔλϒϧͳσʔλߏ଄ɺ࠶ؼతͳϧʔϓ w +BWBͱͷ૬ޓӡ༻ੑ w ฒߦॲཧͷͨΊʹઃܭ w 3&1-Λ׆͔ͨ͠ΠϯλϥΫςΟϒΠϯΫϦϝϯλϧͳ ։ൃ

Slide 42

Slide 42 text

DDD@H ίϯηϓτ͕໘ന͍ w ঢ়ଶʹ͍ͭͯͷߟ͑ํɺ*EFOUJUZ 4UBUF 7BMVFͷ෼཭ w γϯϓϧ͞ʹ͍ͭͯ ͍Ζ͍Ζܹࢗత

Slide 43

Slide 43 text

DDD@H IUUQCPYPGQBQFSTIBUFOBCMPHDPNFOUSZTJNQMF@NBEF@FBTZ

Slide 44

Slide 44 text

DDD@H -JTQͷγϯλοΫε ׅހͷ࢝·Γ͔ΒऴΘΓ·Ͱ͕୯Ґ (ԿΒ͔ͷॲཧ ॲཧͷର৅ͳͲ…)

Slide 45

Slide 45 text

DDD@H $MPKVSF͸Χοίͷछྨ͕ଟ͘ɺಡΈ΍͍͢ ͨͱ͑͹ؔ਺ͷҾ਺ $PNNPO-JTQ 4DIFNF $MPKVSF (defun square (x) (* x x)) (define (square x) (* x x)) (defn square [x] (* x x))

Slide 46

Slide 46 text

DDD@H େৎ෉

Slide 47

Slide 47 text

DDD@H جຊจ๏Ͱ΢ΥʔϛϯάΞοϓ

Slide 48

Slide 48 text

DDD@H ࢛ଇԋࢉ 12 + 40 10 - 1 2 * 3 5 / 2 +BWB 4DBMB (+ 12 40) (- 10 1) (* 2 3) (/ 5 2) ; -> 5/2 ෼਺Λѻ͏Ratioܕ $MPKVSF

Slide 49

Slide 49 text

DDD@H ม਺એݴ int x = 10; +BWB val x = 10 val x: Int = 10 4DBMB (def x 10) (let [y 10] (+ y 3)) ; y͸letͷׅހ಺͚ͩͰࢀরͰ͖Δ $MPKVSF

Slide 50

Slide 50 text

DDD@H ϝιουɾؔ਺એݴ public int f(int x) { return x + 1; } +BWB (defn f [x] (+ x 1)) $MPKVSF def f(x: Int) = x + 1 4DBMB

Slide 51

Slide 51 text

DDD@H

Slide 52

Slide 52 text

DDD@H )551αʔόʔΛ
 ࡞Γͳ͕Βֶ΅͏

Slide 53

Slide 53 text

DDD@H ࠓճ༻ҙͨ͠)551αʔόʔ w ىಈ͠ɺMPDBMIPTUͷಛఆͷϙʔτͰ)551ϦΫΤετΛ଴ͪड͚Δ w ରԠ͢Δ)551ϦΫΤετϝιου͸(&5ͷΈ
 ͦΕҎ֎ͷϝιου΋(&5ͱΈͳ͢ w QVCMJDσΟϨΫτϦΑΓ্ͷ֊૚΁ͷϦΫΤετʹ͸
 'PSCJEEFOΛฦ͢ w Ϧιʔεͷ.*.&͸֎෦ϑΝΠϧͰઃఆͰ͖Δ w ϦΫΤετΛϒϩοΫ͠ͳ͍ʢϚϧνεϨουʣ w ,FFQ"MJWF͸͠ͳ͍ɻίωΫγϣϯ͸౎౓DMPTF͢Δ w )551$BDIF͸͠ͳ͍ɻ͸ฦ͞ͳ͍

Slide 54

Slide 54 text

DDD@H ىಈ w +BWB NWODPNQJMF NWOFYFDKBWB w 4DBMB TCUSVO w $MPKVSF MFJOSVO

Slide 55

Slide 55 text

DDD@H ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ├── MimeDetector.java ├── Request.java ├── RequestHandler.java ├── RequestParser.java ├── Response.java ├── SimpleJavaHttpServer.java └── WorkerThread.java ΞϓϦέʔγϣϯͷΤϯτϦʔϙΠϯτ 3FRVFTU *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN ϦΫΤετͷύʔε ϦΫΤετͷϋϯυϦϯά Ϩεϙϯεͷ8SJUF

Slide 56

Slide 56 text

DDD@H ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ├── MimeDetector.java ├── Request.java ├── RequestHandler.java ├── RequestParser.java ├── Response.java ├── SimpleJavaHttpServer.java └── WorkerThread.java )551ϦΫΤετΛύʔε͢Δ 3FRVFTU *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN ϦΫΤετͷύʔε ϦΫΤετͷϋϯυϦϯά Ϩεϙϯεͷ8SJUF

Slide 57

Slide 57 text

DDD@H ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ├── MimeDetector.java ├── Request.java ├── RequestHandler.java ├── RequestParser.java ├── Response.java ├── SimpleJavaHttpServer.java └── WorkerThread.java ϦΫΤετΛද͢ΦϒδΣΫτ 3FRVFTU *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN ϦΫΤετͷύʔε ϦΫΤετͷϋϯυϦϯά Ϩεϙϯεͷ8SJUF

Slide 58

Slide 58 text

DDD@H ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ├── MimeDetector.java ├── Request.java ├── RequestHandler.java ├── RequestParser.java ├── Response.java ├── SimpleJavaHttpServer.java └── WorkerThread.java ϦΫΤετ͔ΒϨεϙϯεΛੜ੒ 3FRVFTU *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN ϦΫΤετͷύʔε ϦΫΤετͷϋϯυϦϯά Ϩεϙϯεͷ8SJUF

Slide 59

Slide 59 text

DDD@H ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ├── MimeDetector.java ├── Request.java ├── RequestHandler.java ├── RequestParser.java ├── Response.java ├── SimpleJavaHttpServer.java └── WorkerThread.java ϨεϙϯεΛද͢ΦϒδΣΫτ 3FRVFTU *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN ϦΫΤετͷύʔε ϦΫΤετͷϋϯυϦϯά Ϩεϙϯεͷ8SJUF

Slide 60

Slide 60 text

DDD@H ͭ͘Γʹ͍ͭͯͬ͘͟Γͱ ├── MimeDetector.java ├── Request.java ├── RequestHandler.java ├── RequestParser.java ├── Response.java ├── SimpleJavaHttpServer.java └── WorkerThread.java )551ϨεϙϯεΛ8SJUF 3FRVFTU *OQVU4USFBN 3FTQPOTF 0VUQVU4USFBN ϦΫΤετͷύʔε ϦΫΤετͷϋϯυϦϯά Ϩεϙϯεͷ8SJUF

Slide 61

Slide 61 text

DDD@H ֤ݴޠͰ΍ͬͯΈΔ w 4PDLFUͷѻ͍ w ਖ਼نදݱ w Ϧιʔεͷ։์ w ฒߦॲཧ w จࣈྻͷѻ͍

Slide 62

Slide 62 text

DDD@H ࡞Γ࢝ΊΔίπ w ೉͘͠ߟ͑͗͢ͳ͍ w ॳΊ͔Βߟ͑ํΛࠜຊతʹม͑Δඞཁ͸ͳ͍ w O೥ޙʹ΋͏Ұ౓࡞Γ௚͢ͱ੒௕͕࣮ײͰ͖Δ͔΋

Slide 63

Slide 63 text

DDD@H 4PDLFUͷѻ͍

Slide 64

Slide 64 text

DDD@H 4PDLFU

Slide 65

Slide 65 text

DDD@H 4PDLFU w ௨৴ʹ͓͚ΔΤϯυϙΠϯτΛදݱͨ͠σʔλϞσϧ ֤ΤϯυϙΠϯτΛࣝผ͢Δ̎ͭͷ஋ɺ
 ͢ͳΘͪ*1ΞυϨεͱϙʔτ൪߸͸ɺ
 ଟ͘ͷ৔߹ιέοτ TPDLFU ͱݺ͹ΕΔɻ ʮ6/*9ωοτϫʔΫϓϩάϥϛϯάʯ

Slide 66

Slide 66 text

DDD@H 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ

Slide 67

Slide 67 text

DDD@H 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ

Slide 68

Slide 68 text

DDD@H 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ ΫϥΠΞϯτιέοτ

Slide 69

Slide 69 text

DDD@H 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ ΫϥΠΞϯτιέοτ ઀ଓཁٻ

Slide 70

Slide 70 text

DDD@H 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ ΫϥΠΞϯτιέοτ ઀ଓ

Slide 71

Slide 71 text

DDD@H 4PDLFU௨৴ͷ໛ࣜਤ ΫϥΠΞϯτ αʔόʔ αʔόʔιέοτ ΫϥΠΞϯτιέοτ

Slide 72

Slide 72 text

DDD@H 4PDLFUͷѻ͍ // αʔόʔιέοτͷੜ੒ ServerSocket serverSocket = new ServerSocket(8080); while (true) { // ઀ଓΛ଴ͪड͚Δɻ઀ଓ͞ΕΔ·ͰϒϩοΫɻ Socket socket = serverSocket.accept(); InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); ... } 4JNQMF+BWB)UUQ4FSWFSKBWBʢൈਮʣ

Slide 73

Slide 73 text

DDD@H 4PDLFUͷѻ͍ // αʔόʔιέοτͷੜ੒ val serverSocket = new ServerSocket(8080) while (true) { // ઀ଓΛ଴ͪड͚Δɻ઀ଓ͞ΕΔ·ͰϒϩοΫ val socket = serverSocket.accept val in = s.getInputStream val out = s.getOutputStream ... } 4JNQMF)UUQ4FSWFSTDBMBʢൈਮʣ

Slide 74

Slide 74 text

DDD@H 4PDLFUͷѻ͍ (let [server-socket (new ServerSocket 8080)] (while true (let [socket (.accept server-socket) in (.getInputStream socket) out (.getOutputStream socket)] ...))) DPSFDMKʢൈਮʣ

Slide 75

Slide 75 text

DDD@H 4PDLFUͷѻ͍ʹֶ͍ͭͯΜͩ͜ͱ w 4FSWFS4PDLFUΦϒδΣΫτΛੜ੒͠ɺ
 ΫϥΠΞϯτ͔Βͷ઀ଓΛBDDFQUͰ଴ͪड͚Δ w 4PDLFUΦϒδΣΫτʢΫϥΠΞϯτιέοτʣ͔Β
 *O0VUQVU4USFBN͕औಘͰ͖Δ w *OQVU4USFBN͔Β)551ϦΫΤετΛ3FBE͠ɺ
 0VUQVU4USFBNʹ)551ϨεϙϯεΛ8SJUF͢Δ

Slide 76

Slide 76 text

DDD@H ਖ਼نදݱ

Slide 77

Slide 77 text

DDD@H ਖ਼نදݱ w 4PDLFUͷ*OQVU4USFBNΛ
 ҰߦಡΉ
 ˠSFRVFTUMJOF w ֤ཁૉΛநग़͍ͨ͠

Slide 78

Slide 78 text

DDD@H ਖ਼نදݱ w 4PDLFUͷ*OQVU4USFBNΛ
 ҰߦಡΉ
 ˠSFRVFTUMJOF w ֤ཁૉΛநग़͍ͨ͠

Slide 79

Slide 79 text

DDD@H w 4PDLFUͷ*OQVU4USFBNΛ
 ҰߦಡΉ
 ˠSFRVFTUMJOF w ֤ཁૉΛநग़͍ͨ͠ ਖ਼نදݱ

Slide 80

Slide 80 text

DDD@H ໊લ෇͖άϧʔϓ

Slide 81

Slide 81 text

DDD@H ໊લ෇͖άϧʔϓ w ਖ਼نදݱͷάϧʔϓʹ໊લΛ෇͚Δ͜ͱ͕Ͱ͖Δ w άϧʔϓͷॱং͕มΘͬͨͱͯ͠΋औΓग़͢ॲཧ͸ͦͷ·· import java.util.regex.*; String regex = "(?\\d+)/(?\\d+)/(?\\d+)"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher("2017/11/18"); if (m.find()) { System.out.println(m.group("year")); // 2017 System.out.println(m.group("month")); // 11 System.out.println(m.group("day")); // 18 }

Slide 82

Slide 82 text

DDD@H w ϦΫΤετϥΠϯͷ֤ཁૉʹ໊લΛ෇͚ͯநग़ public static Pattern requestLinePattern = Pattern.compile("(?.*) (?.*?) (?.*?)"); public Request fromInputStream(InputStream in){ BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String requestLine = reader.readLine(); Matcher matcher = requestLinePattern.matcher(requestLine); if (!matcher.find()) return null; String method = matcher.group("method"); String targetPath = matcher.group("path"); String httpVersion = matcher.group("version"); return new Request(method, targetPath, httpVersion); } ໊લ෇͖άϧʔϓ 3FRVFTU1BSTFSKBWBʢൈਮʣ

Slide 83

Slide 83 text

DDD@H ύλʔϯϚον S

Slide 84

Slide 84 text

DDD@H ύλʔϯϚον w +BWBͷTXJUDIจʹࣅ͍ͯΔ͕ɺΑΓॊೈͰڧྗ w ஋ʹҰக͢Δ͔͚ͩͰͳ͘ɺܕ΍ߏ଄Ͱ΋෼ذ 0 match { case 0 => "Zero" // "Zero" case _ => "Other" } List(1, 2, 3) match { case List(_, x, _) => x // 2 case _ => -1 } 1 match { x: Int => s"$x͸Int" // 1͸Int x: String => s"$x͸String" x => s"$x͸???" }

Slide 85

Slide 85 text

DDD@H ύλʔϯϚον w ࠓޙ+BWBʹ΋ೖΔ͔΋͠Εͳ͍ IUUQPQFOKELKBWBOFUKFQT

Slide 86

Slide 86 text

DDD@H ύλʔϯϚον w ਖ਼نදݱΦϒδΣΫτʹରͯ͠΋Ϛονͤ͞ΒΕΔ val pattern = "(.+)/(.+)/(.+)".r //.rͰregexܕ "2017/11/18" match { case pattern(y, m, d) => s"${y}೥${m}݄${d}೔" case _ => "???" }

Slide 87

Slide 87 text

DDD@H ύλʔϯϚον val pattern = "(.+) (.+) (.+)".r requestLine match { case pattern(method, path, version) => Some(Request(method, path, version)) case _ => None } 3FRVFTU1BSTFSTDBMBʢൈਮʣ

Slide 88

Slide 88 text

DDD@H 0QUJPOܕ requestLine match { case pattern(method, path, version) => Some(Request(method, path, version)) case _ => None } w +BWBͰ͍͏0QUJPOBM w 4PNFͱ/POF͔ΒͳΔܕ w ஋͕͋Δ͔ͳ͍͔෼͔Βͳ͍ঢ়ଶΛද͢ w ஋͕ଘࡏ͢Δ͔ͷνΣοΫΛڧ੍Ͱ͖Δ

Slide 89

Slide 89 text

DDD@H SFpOE

Slide 90

Slide 90 text

DDD@H SFpOE w ਖ਼نදݱʹϚονͨ͠จࣈྻΛऔಘ w Ҿ਺ʹάϧʔϓԽͨ͠ਖ਼نදݱΦϒδΣΫτΛ౉͢ͱɺ
 ઌ಄ʹ͸Ϛονͨ͠จࣈྻશମɺҎ߱ʹΩϟϓνϟ͞ΕͨจࣈྻͷϕΫλʔ ;; #"" ͸java.util.regex.PatternͷϦςϥϧ (re-find #"(.+)/(.+)/(.+)" "2017/11/18") ;; => ["2017/11/18" "2017" "11" "18"] ;; restͰઌ಄Ҏ֎ͷཁૉΛऔಘ (rest (re-find #"(.+)/(.+)/(.+)" "2017/11/18")) ;; => ("2017" "11" "18")

Slide 91

Slide 91 text

DDD@H [JQNBQ w ڧྗͳίϨΫγϣϯϥΠϒϥϦ͸$MPKVSFͷಛ௃ w [JQNBQ͸ͭͷίϨΫγϣϯ͔Β.BQΛ࡞Δ w $MPKVSFͰ͸ΫϥεΑΓ΋.BQΛ޷Ή (zipmap [:a :b :c] [1 2 3]) ;; => {:a 1, :b 2, :c 3}

Slide 92

Slide 92 text

DDD@H SFpOE[JQNBQ (let [line (.readLine reader)] (zipmap [:method :path :version] (rest (re-find #"(.+) (.+) (.+)" line)))) ;; => {:method "GET", :path "/", :version "HTTP/1.1"} SFRVFTU@QBSTFSDMKʢൈਮʣ

Slide 93

Slide 93 text

DDD@H SFpOE[JQNBQ (let [line (.readLine reader)] (zipmap [:method :path :version] (rest (re-find #"(.+) (.+) (.+)" line)))) ;; => {:method "GET", :path "/", :version "HTTP/1.1"} SFRVFTU@QBSTFSDMKʢൈਮʣ <NFUIPEQBUIWFSTJPO> <(&5)551>

Slide 94

Slide 94 text

DDD@H SFpOE[JQNBQ (let [line (.readLine reader)] (zipmap [:method :path :version] (rest (re-find #"(.+) (.+) (.+)" line)))) ;; => {:method "GET", :path "/", :version "HTTP/1.1"} SFRVFTU@QBSTFSDMKʢൈਮʣ <NFUIPEQBUIWFSTJPO> <(&5)551>

Slide 95

Slide 95 text

DDD@H ਖ਼نදݱʹֶ͍ͭͯΜͩ͜ͱ ໊લ෇͖άϧʔϓ ύλʔϯϚον
 S SFpOE
 ఴࣈͰΞΫηε͢ΔΑΓ҆৺ ߏ଄ͷ෼ղʹ΋࢖͑Δ ݁Ռ͸ίϨΫγϣϯɺڧྗͳίϨΫγϣϯૢ࡞ͱ૊Έ߹Θͤͯ

Slide 96

Slide 96 text

DDD@H Ϧιʔεͷղ์

Slide 97

Slide 97 text

DDD@H Ϧιʔεͷղ์ w ετϦʔϜ΍%#ίωΫγϣϯɺιέοτ͸
 ࢖͍ऴΘͬͨΒDMPTF w ๨ΕΔͱϝϞϦϦʔΫͷݪҼʹͳΔ͜ͱ͕͋Δ w खͰDMPTFॻ͖ͨ͘ͳ͍ʂ

Slide 98

Slide 98 text

DDD@H 5SZXJUI3FTPVSDFT

Slide 99

Slide 99 text

DDD@H 5SZXJUI3FTPVSDFT try (InputStream in = new FileInputStream(file)) { // Կ͔ϦιʔεΛѻ͏ॲཧ } // try۟Λൈ͚ͨΒclose w USZ۟Λൈ͚ͨΒࣗಈͰDMPTF w ର৅͸KBWBJP$MPTFBCMF 
 KBWBMBOH"VUP$MPTFBCMFͷ࣮૷Ϋϥε

Slide 100

Slide 100 text

DDD@H -PBO1BUUFSO

Slide 101

Slide 101 text

DDD@H -PBO1BUUFSO w ʮआΓͨΒฦ͢ʯΛ࣮֬ʹߦ͏ w ੍ޚߏ଄ͷΑ͏ʹݟ͔͚࣮ͤͯ͸ϝιου val reader = new BufferedReader(...) using(reader) { r => // readerΛ࢖ͬͨԿ͔ͷॲཧ } // ϒϩοΫΛൈ͚ͨΒreader͸close͞Ε͍ͯΔ

Slide 102

Slide 102 text

DDD@H -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A): A = { try { f(resource) } finally { resource.close() } }

Slide 103

Slide 103 text

DDD@H -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A): A = { try { f(resource) } finally { resource.close() } } ܕม਺3͸$MPTFBCMF

Slide 104

Slide 104 text

DDD@H -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A): A = { try { f(resource) } finally { resource.close() } } 3ܕͷԿ͔Λड͚औΓɺԿΒ͔ͷܕ"Λฦؔ͢਺ΛҾ਺ʹͱΔ

Slide 105

Slide 105 text

DDD@H -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A): A = { try { f(resource) } finally { resource.close() } } Ϧιʔεʹରͯؔ͠਺Λద༻

Slide 106

Slide 106 text

DDD@H -PBO1BUUFSOͷ࣮૷ def using[A, R <: Closeable](resource: R)(f: R => A): A = { try { f(resource) } finally { resource.close() } } ࠷ޙʹDMPTF

Slide 107

Slide 107 text

DDD@H ׅހ ͱதׅހ\^ "hoge".startsWith{"ho"} // ͋·Γ΍Βͳ͍ "hoge".replace{"ho", "fu"} // Ͱ͖ͳ͍ "hoge" map { c => c.someFunc ... } // Α͘΍Δ w Ҿ਺͕Ұ͚ͭͩͷ৔߹ɺׅހΛதׅހͰॻ͍ͯ΋ྑ͍ w Ҿ਺ʹؔ਺Λ౉͢৔߹ɺதׅހΛ࢖͏͜ͱ͕Α͋͘Δ

Slide 108

Slide 108 text

DDD@H -PBO1BUUFSO using(socket) { s => val in = s.getInputStream val out = s.getOutputStream val request = parser.fromInputStream(in) val response = request.map(handleRequest) response.foreach(_.writeTo(out)) } 4JNQMF)UUQ4FSWFSTDBMBʢൈਮʣ

Slide 109

Slide 109 text

DDD@H XJUIPQFO

Slide 110

Slide 110 text

DDD@H w -PBO1BUUFSOʹࣅͨXJUIPQFOͱ͍͏ϚΫϩ w MFUͱಉ͡Α͏ͳײ͡Ͱ࢖͏ XJUIPQFO (with-open [f (io/file "test.txt")] ...)

Slide 111

Slide 111 text

DDD@H XJUIPQFO (with-open [s socket] (-> (request-parser/from-input-stream (.getInputStream s)) (request-handler/handle-request) (response-writer/write (.getOutputStream s)))) DPSFDMKʢൈਮʣ

Slide 112

Slide 112 text

DDD@H Ϧιʔεͷղ์ʹֶ͍ͭͯΜͩ͜ͱ 5SZXJUI3FTPVSDFT -PBO1BUUFSO XJUIPQFO USZ۟Λൈ͚Δ࣌ʹDMPTF ؔ਺͕஋Ͱ͋Δ͜ͱΛ׆͔͠ɺ੍ޚߏจͷΑ͏ʹݟͤΔ DMPTFͯ͘͠ΕΔMFUΈ͍ͨͳΠϝʔδ

Slide 113

Slide 113 text

DDD@H ฒߦॲཧ

Slide 114

Slide 114 text

DDD@H ฒߦॲཧ w ϦΫΤετΛγϦΞϧʹॲཧ͢ΔͱଞͷϦΫΤετΛ଴ͨͤͯ͠·͏ w ͳͷͰϦΫΤετΛड͚෇͚ͨઌ͸ฒߦʹॲཧ͢Δ w +7.ݴޠͳͷͰϚϧνεϨουͰ

Slide 115

Slide 115 text

DDD@H 5ISFBE &YFDVUPS4FSWJDF

Slide 116

Slide 116 text

DDD@H 5ISFBE class HogeThread extends Thread { public void run() { // Կ͔ඇಉظʹ࣮ߦ͍ͨ͠ॲཧ } } HogeThread h = new HogeThread(); h.start(); class FugaRunnable implements Runnable { public void run() { // Կ͔ඇಉظʹ࣮ߦ͍ͨ͠ॲཧ } } FugaRunnable f = new Thread(new FugaRunnable()); f.start(); 5ISFBEΛFYUFOET3VOOBCMFΛJNQMFNFOUT

Slide 117

Slide 117 text

DDD@H 5ISFBE public class WorkerThread extends Thread { private Socket socket; private RequestParser parser; private RequestHandler handler; public WorkerThread( Socket socket, RequestParser parser, RequestHandler handler) { ... 8PSLFS5ISFBEKBWBʢൈਮʣ 4JNQMF+BWB)UUQ4FSWFSKBWBʢൈਮʣ Thread worker = new WorkerThread(socket, parser, handler); worker.start();

Slide 118

Slide 118 text

DDD@H &YFDVUPS4FSWJDF ExecutorService cachedPool = Executors.newCachedThreadPool(); cachedPool.execute(runnable); ExecutorService fixedPool = Executors.newFixedThreadPool(4); fixedPool.execute(runnable); w ʮλεΫʯΛผεϨουͰॲཧ͢ΔͨΊͷ࢓૊Έ w εϨουϓʔϧͷछྨΛࢦఆͰ͖Δ

Slide 119

Slide 119 text

DDD@H 'VUVSF

Slide 120

Slide 120 text

DDD@H 'VUVSF w 'VUVSFBQQMZ͸౉͞ΕͨॲཧΛඇಉظʹ࣮ߦ w ͍ͭͲͷΑ͏ʹඇಉظʹ࣮ߦ͢Δ͔͸&YFDVUJPO$POUFYU࣍ୈ import scala.concurrent.Future // ForkJoinPoolɺσϑΥϧτͰ͸ίΞ਺෼ͷฒྻ౓Ͱॲཧ import scala.concurrent.ExecutionContext. Implicits.global val result: Future[User] = Future { userRepository.fetch(userId) } result.map(user => user.id)

Slide 121

Slide 121 text

DDD@H &YFDVUJPO$POUFYU͸Ͳ͏ड͚औΔʁ w 'VUVSFBQQMZʹ͸Ҿ਺ϒϩοΫ͕ͭ w ͭ໨ͷҾ਺ϒϩοΫͰ&YFDVUJPO$POUFYUΛड͚औΔ object Future { ... def apply[T](body: =>T)(implicit executor: ExecutionContext) } Future { userRepository.fetch(user) } Future.apply( userRepository.fetch(user) )

Slide 122

Slide 122 text

DDD@H JNQMJDJU8IBUͱ)PXͷ෼཭ w )PX͕ڊେʹͳΔͱɺίʔυͷຊདྷͷҙਤ͕ຒ΋Εͯ͠·͏ w JNQMJDJUͷେ͖ͳϞνϕʔγϣϯ͸)PXͷӅณ w 8IBUͱ)PXΛ෼཭͢Δ͜ͱͰɺ໨తΛ୺తʹࣔ͢͜ͱ͕Ͱ͖Δ val values: Seq[(String, Option[Int])] val sorted = sort(values)( tuple2Comparator( stringComparator, optionComparator(intComparator))) val sorted = sort(values) // implicit

Slide 123

Slide 123 text

DDD@H IUUQHBLV[[[[HJUIVCJPTMJEFTJNQMJDJU@SFJOUSPEVDUJPO

Slide 124

Slide 124 text

DDD@H UISFBE

Slide 125

Slide 125 text

DDD@H $MPKVSFͷฒߦॲཧؔ਺ w $MPKVSFͷฒߦॲཧؔ਺͸ͨ͘͞Μ͋Δ w HP w UISFBE w TFOE w TFOEPGG w GVUVSF w FUD

Slide 126

Slide 126 text

DDD@H IUUQUZBOPTIFMpODDPNQPTUDMPKVSFDPODVSSFOU

Slide 127

Slide 127 text

DDD@H $MPKVSFͷฒߦॲཧؔ਺ εϨουϓʔϧ εϨου਺ TFOE 'JYFE5ISFBE1PPM ίΞ਺ TFOEPGG $BDIFE5ISFBE1PPM ੍ݶͳ͠ GVUVSFGVUVSFDBMM QNBQQDBMMT $BDIFE5ISFBE1PPM ੍ݶͳ͠ HP 'JYFE5ISFBE1PPM ίΞ਺ UISFBE
 UISFBEDBMM $BDIFE5ISFBE1PPM ੍ݶͳ͠ SFEVDFST 'PSL+PJO1PPM ࣗಈ੍ޚ IUUQUZBOPTIFMpODDPNQPTUDMPKVSFDPODVSSFOU

Slide 128

Slide 128 text

DDD@H *0ό΢ϯυ$16ό΢ϯυ w $MPKVSFͷฒߦॲཧؔ਺͸ɺ*0$16ό΢ϯυͷछྨʹେผ *0ό΢ϯυͳॲཧ͸ɺ࣮ߦதͷॲཧ͕$16ΑΓ΋*0ॲཧʹ
 ڧ͘ґଘ͠·͢ɻ%#ΞΫηεͱ͔ϦϞʔτ௨৴ͱ͔Ͱ͢Ͷɻ
 ผεϨουͰ͜ͷॲཧΛ࣮ߦͨ͠৔߹ɺεϨου͸େ෦෼Λɺ
 *0ॲཧ଴ͪঢ়ଶͰա͝͠·͢ɻ $16ό΢ϯυͳॲཧ͸ɺ్தʹ*0଴ͪͷΑ͏ͳʮ଴ػʯ͕
 ൃੜͤͣɺ$16ΛͿΜճ͠ଓ͚ΔΑ͏ͳॲཧͰ͢ɻ
 શσʔλ͕ϝϞϦʹࡌ͍ͬͯͯɺ$16͕ϑϧՔಇͰͦΕΒΛ
 ॲཧ͢ΔΑ͏ͳέʔεͰ͢ɻ IUUQUZBOPTIFMpODDPNQPTUDMPKVSFDPODVSSFOU

Slide 129

Slide 129 text

DDD@H $MPKVSFͷฒߦॲཧؔ਺ εϨουϓʔϧ εϨου਺ TFOE 'JYFE5ISFBE1PPM ίΞ਺ TFOEPGG $BDIFE5ISFBE1PPM ੍ݶͳ͠ GVUVSFGVUVSFDBMM QNBQQDBMMT $BDIFE5ISFBE1PPM ੍ݶͳ͠ HP 'JYFE5ISFBE1PPM ίΞ਺ UISFBE
 UISFBEDBMM $BDIFE5ISFBE1PPM ੍ݶͳ͠ SFEVDFST 'PSL+PJO1PPM ࣗಈ੍ޚ IUUQUZBOPTIFMpODDPNQPTUDMPKVSFDPODVSSFOU

Slide 130

Slide 130 text

DDD@H $MPKVSFͷฒߦॲཧؔ਺ εϨουϓʔϧ εϨου਺ TFOE 'JYFE5ISFBE1PPM ίΞ਺ TFOEPGG $BDIFE5ISFBE1PPM ੍ݶͳ͠ GVUVSFGVUVSFDBMM QNBQQDBMMT $BDIFE5ISFBE1PPM ੍ݶͳ͠ HP 'JYFE5ISFBE1PPM ίΞ਺ UISFBE
 UISFBEDBMM $BDIFE5ISFBE1PPM ੍ݶͳ͠ SFEVDFST 'PSL+PJO1PPM ࣗಈ੍ޚ IUUQUZBOPTIFMpODDPNQPTUDMPKVSFDPODVSSFOU

Slide 131

Slide 131 text

DDD@H UISFBE (thread (with-open [s socket in (.getInputStream s) out (.getOutputStream s)] (-> (request-parser/from-input-stream in) (request-handler/handle-request) (response-writer/write out)))) DPSFDMKʢൈਮʣ

Slide 132

Slide 132 text

DDD@H ฒߦॲཧʹֶ͍ͭͯΜͩ͜ͱ 5ISFBE
 &YFDVUPS4FSWJDF 'VUVSF UISFBE FYUFOET5ISFBEJNQMFNFOUT3VOOBCMF 5ISFBE্ཱͪ͛Ͱ͸ͳ͍ɻ
 Ͳ͏࣮ߦ͢Δ͔͸&YFDVUJPO$POUFYU࣍ୈɻ
 JNQMJDJUʹΑΔ)PXͷӅณɻ *0$16ό΢ϯυ͔Λҙࣝ͠Α͏

Slide 133

Slide 133 text

DDD@H จࣈྻͷѻ͍

Slide 134

Slide 134 text

DDD@H จࣈྻ݁߹ w ϨεϙϯεʢΦϒδΣΫτϚοϓʣ͔Β
 )551ϨεϙϯεϔομΛ૊Έཱ͍ͯͨ public class Response { public final Status status; public final String contentType; public final int contentLength; public final byte[] body; }

Slide 135

Slide 135 text

DDD@H 4USJOH#VJMEFS

Slide 136

Slide 136 text

DDD@H 4USJOH#VJMEFS String response = "HTTP/1.1 " + status.statusCode + CRLF + "Server: SimpleJavaHttpServer" + CRLF + "Content-Type: " + contentType + CRLF + "Content-Length: " + 
 String.valueOf(contentLength) + CRLF + "Connection: Close" + CRLF + CRLF; 3FTQPOTFKBWBʢൈਮʣ ࠷దԽ͞ΕΔ͔ࣗ৴͕ͳ͚Ε͹KBWBQD

Slide 137

Slide 137 text

DDD@H 4USJOH*OUFSQPMBUJPO 5SJQMF2VPUF

Slide 138

Slide 138 text

DDD@H 4USJOH*OUFSQPMBUJPO w จࣈྻϦςϥϧͷલʹTΛ෇͚Δͱɺม਺Λల։Ͱ͖Δ val price = 1000 s"Price is $price" // => Price is 1000

Slide 139

Slide 139 text

DDD@H 5SJQMF2VPUF "Hello triple quote!\nHello stripMargin!" """Hello triple quote! Hello stripMargin!""" """|Hello triple quote! |Hello stripMargin!""".stripMargin w վߦΛؚΉจࣈྻΛຒΊࠐΉʹ͸ɺΛ࢖͏ w ΠϯσϯτΛଗ͑Δʹ͸Πϯσϯτจࣈ c ͱTUSJQ.BSHJOΛ࢖͏

Slide 140

Slide 140 text

DDD@H 4USJOH*OUFSQPMBUJPOͱ5SJQMF2VPUF val response = s"""HTTP/1.1 ${status.value} |Date: ${rfc1123Formatter.format(now)} |Server: SimpleScalaHttpServer |Content-Type: $contentType |Content-Length: ${body.length.toString} |Connection: Close | |""".stripMargin 3FTQPOTFTDBMBʢൈਮʣ

Slide 141

Slide 141 text

DDD@H TUS

Slide 142

Slide 142 text

DDD@H w $MPKVSFͰ͸จࣈྻͷ݁߹͸Ͱ͸ͳ͘TUS w Մม௕Ҿ਺ɺ4ࣜͳΒͰ͸ TUS (+ "hoge" "fuga") ClassCastException java.lang.String cannot be cast to java.lang.Number clojure.lang.Numbers.add (Numbers.java:128) (str "hoge" "fuga" "piyo") // => hogefugapiyo

Slide 143

Slide 143 text

DDD@H TUS (let [header (str "HTTP/1.1" sp status sp reason-phrase crlf "Content-Length:" (count body) crlf "Content-Type:" content-type crlf "Connection: Close" crlf crlf)] ...) SFTQPOTF@XSJUFSDMKʢൈਮʣ

Slide 144

Slide 144 text

DDD@H จࣈྻ݁߹ʹֶ͍ͭͯΜͩ͜ͱ 
 4USJOH#VJMEFS 4USJOH*OUFSQPMBUJPO
 5SJQMF2VPUF TUS KBWBQD ͪΐͬͱͨ͠ςϯϓϨʔτΤϯδϯΈ͍ͨʹ࢖͑Δ ָ͞͸4ࣜͳΒͰ͸ɻͪΐͬͱ-JTQ͕޷͖ʹͳΔ

Slide 145

Slide 145 text

DDD@H ֤ݴޠͰ΍ͬͯΈͨ w 4PDLFUͷѻ͍ w ਖ਼نදݱ w Ϧιʔεͷ։์ w ฒߦॲཧ w จࣈྻͷѻ͍

Slide 146

Slide 146 text

DDD@H ·ͱΊ

Slide 147

Slide 147 text

DDD@H )551αʔόʔΛ࡞ͬͯݴޠΛֶ΅͏ w %#΍ը໘Λ༻ҙ͢Δखؒͳ͘ɺखܰʹ։ൃ͕࢝ΊΒΕΔ w 8FC։ൃʹඞཁͳཁૉʹͦͦ͜͜Ұ௨Γ৮ΕΒΕΔ w จࣈྻૢ࡞ɺೖग़ྗɺฒྻॲཧͳͲ w ࠷ॳ͸೉͘͠ߟ͑͗͢ͳ͍ɻ
 ॳΊ͔Βߟ͑ํΛࠜຊతʹม͑Δඞཁ͸ͳ͍ w طʹ஌͍ͬͯΔ͜ͱͱEJGGΛͱͬͯΈΑ͏ w ͦͷݴޠͷੈք؍Λ஌Δख͕͔Γ͕ͦͷEJGGʹ͋Δ͔΋

Slide 148

Slide 148 text

DDD@H w ڭཆͱͯ͠ͷ$MPKVSFʢճ໨ظ೔ະఆʣ w ڭཆͱͯ͠ͷ4DBMBʢ༧ఆʣ w DPOQBTTͰ%$VCFͷϝϯόʔʹͳΔͱ
 ͓஌Β͕ͤಧ͖·͢ ڭཆγϦʔζ༧ఆ͍ͯ͠·͢

Slide 149

Slide 149 text

DDD@H (PPE$PEJOH