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

今日から使おうSmalltalk

newapplesho
November 29, 2010

 今日から使おうSmalltalk

第26回 Smalltalk勉強会資料

newapplesho

November 29, 2010
Tweet

More Decks by newapplesho

Other Decks in Programming

Transcript

  1. ୈճ4NBMMUBMLษڧձ Smalltalk͕෼͔Βͳ͍ จ๏ ։ൃ؀ڥ array := Array with:-1 with:1 with:100.

    array inject: Float infinity negated into:[:v1 :v2 | v1 max: v2 ]. 3
  2. ୈճ4NBMMUBMLษڧձ ୯߲ϝοηʔδ(Unary messages) 4 sqrt. "ฏํࠜ" 12 i. "ڏ਺" 1

    asFloat. "ුಈখ਺ͱ͢Δ" #(1 2 3) first. "࠷ॳͷཁૉΛऔΓग़͢" Ҿ਺ΛऔΒͳ͍ϝοηʔδ 13
  3. ୈճ4NBMMUBMLษڧձ 2߲ϝοηʔδ(Binary Messages) 4 + 1. 10 / 2. 8

    // 3. 1 < 2. 'Small','talk'. ه߸        c  d !Λ૊Έ߹Θ໊ͤͨલΛ ΋ͭϝοηʔδ ओʹ਺ֶͷ2߲ԋࢉࢠ(2ͭͷσʔλʹର͢Δԋࢉ)Λ දͨ͢Ίͷ΋ͷ 14
  4. ୈճ4NBMMUBMLษڧձ Ωʔϫʔυϝοηʔδ(Keyword Messages) ̏൪໨ͷཁૉΛऔΓग़͢ #($z $y $x) at: 3. ͔Βͷؒͷ਺ͳΒ͹USVFΛฦ͢

    11 between: 10 and: 100. 11.between(10,100) ൪໨ͷཁૉΛIFMMPʹஔ͖׵͑Δ #($a $b $c) at: 2 put: 'hello'. 1 to: 10 by: 2 do:[:v | Transcript cr; show:v ]. Ҿ਺ΛऔΔϝοηʔδͷ͏ͪ ɹ߲ϝοηʔδҎ֎ ϝοηʔδͷऴΘΓʹ͸ίϩϯ  ͕ඞͣ෇͘ 15
  5. ୈճ4NBMMUBMLษڧձ ࿅श໰୊ 3 + 4 * 5. 3 + 4

    sqrt. 50 + 4 sqrt between: 10 and: 100. ࣮ߦॱংͱ࣮ߦ݁ՌΛߟ͑·͠ΐ͏ 18
  6. ୈճ4NBMMUBMLษڧձ ϒϩοΫ block := [:x :y | x + y].

    block value: 1 value: 2. block valueWithArguments: #(3 4) ओʹ੍ޚߏ଄ʹ༻͍ΒΕΔ ೚ҙͷ࣌఺Ͱ࣮ߦՄೳͳϓϩάϥϜͷݻ·Γ •function(x){x + 1}ͷΑ͏ͳ΋ͷ •(lambda (x) (+ x 1)) ࣮ߦ͢Δࡍʹ͸ɼҾ਺ͷ਺ʹԠͯ͡ WBMVFɼWBMVF౳Λૹ৴͢Δ 19
  7. ୈճ4NBMMUBMLษڧձ Χεέʔυ Transcript show: 'Hello '; cr; show:'Squeak'. Transcript show:

    'Hello '. Transcript cr. Transcript show: 'Squeak'. ઌ಄ΦϒδΣΫτʹରͯ͠ϝοηʔδΛ࿈ଓతʹ ૹ৴͢Δࡍʹ༻͍Δ ; ηϛίϩϯΛ༻͍Δ 20
  8. ୈճ4NBMMUBMLษڧձ ੍ޚจʢ܁Γฦ͠ʣ 1 to: 10 by: 2 do:[:v | Transcript

    cr;show:v ]. | i | "Ұ࣌ม਺" i := 1. [i < 10] whileTrue:[:v | Transcript cr; show:v. i := i + 2. ]. for(int i=1; i<=10; i=i+2) int i=1; while(i<10;){ i=i+2; } 23
  9. ୈճ4NBMMUBMLษڧձ ΠϯεϖΫλΛ࢖ͬͯΈΑ͏ "഑ྻͷཁૉΛϥϯμϜͰऔΓग़͢" x := #(#(7 9) #(3 1)) atRandom.

    x. "ΠϯεϖΫτ" x inspect. "Do It" ͲͪΒͷ഑ྻ͕Yʹ୅ೖ͞Ε͔ͨௐ΂ͯΈΔ ·ͨ͸ 36
  10. ୈճ4NBMMUBMLษڧձ γϣʔτΧοτ .BD 8JOEPXT ϫʔΫεϖʔε Λ։͘ $.% L "-5 L

    τϥϯεΫϦϓτ Λ։͘ $.% U "-5 U γεςϜϒϥ΢β Λ։͘ $.% C "-5 C EPJU $.% E "-5 E QSJOUJU $.% Q "-5 Q $.% "-5  ϐϦΦυʢ.ʣ ڧ੍ऴྃ ׂΓࠐΈ 40
  11. ୈճ4NBMMUBMLษڧձ Πϝʔδͷอଘʹ͍ͭͯ छྨ ಺༰ อଘ TBWF ݱࡏͷঢ়ଶΛݱࡏ࢖༻͍ͯ͠ΔΠϝʔδʹอଘ ผ໊อଘ TBWFBT ผͷΠϝʔδʹอଘʹঢ়ଶΛอଘɽΠϝʔδ໊

    Λܾఆ͢Δɽอଘޙ͸ɼ৽ͨʹ࡞੒ͨ͠Πϝʔ δը໘͕දࣔ ৽͍͠൛ͱͯ͠อଘ TBWFBTOFXWFSTJPO ࣗಈతʹΠϝʔδ໊ʹόʔδϣϯ൪߸͕෇Ճ͞ ΕΔ อଘͯ͠ऴྃ TBWFBOERVJU ݱࡏͷঢ়ଶΛݱࡏ࢖༻͍ͯ͠ΔJNBHFʹ อଘͯ͠ऴྃ Πϝʔδͱ͸4NBMMUBMLͷΦϒδΣΫτΛ ϑΝΠϧʹμϯϓͨ͠΋ͷ 42
  12. ୈճ4NBMMUBMLษڧձ | h w bmi sw | h := FillInTheBlank

    request: '਎௕(cm)͸?' initialAnswer: '0'. h asInteger <= 0 ifTrue:[ ^false ]. w := FillInTheBlank request: 'ମॏ(kg)͸?' initialAnswer: '0'. h asInteger <= 0 ifTrue:[ ^false ]. bmi := w // ( ( h*h ) //10000 ). sw := ( h*h*22 ) // 10000 Utilities informUser: 'ܭࢉத' ! during: [(Delay forSeconds: 1) wait ]. Ұ෦ 47
  13. ୈճ4NBMMUBMLษڧձ ϝιουͷఆٛ messageSelectorAndArgumentNames "comment stating purpose of message" | temporary

    variable names | statements ϝιουͷςϯϓϨʔτͷҙຯ ̍ߦ໨͸ϝιου໊ ̎ߦ໨͸ίϝϯτ ̐ߦ໨͸Ұ࣌ม਺ͷఆٛ ̑ߦ໨Ҏ߱͸ϝιουͷಈ࡞هड़ 54
  14. ୈճ4NBMMUBMLษڧձ ݱࡏνϡʔτϦΞϧ࡞੒த  4RVFBLΠϯετʔϧ  4RVFBLͷجຊૢ࡞  جຊจ๏  Ϋϥεఆٛ౳

     جຊΫϥε /VNCFS #MPDL $PMMFDUJPOΫϥε  ΠςϨʔλ౳ จࣈྻʢ4USJOHʣ 4USFBN  σόοΫ  ྫ֎ॲཧ  πʔϧ  ୳ࡧͷཱྀ εϨουॲཧ .PSQI ύοέʔδ؅ཧ 8FC 4FBTJEF *MJBE .BHNB +40/ 9.- ਖ਼نදݱ 5SBJUT ଞʹ΋ཁ๬͕͋Ε͹Ͳ͏ͧ 67