Ioã«ã¯é¢æ°åŒã³åºãã¯ãããŸããããã¡ãã»ãŒãžãéä¿¡ããŠããŸãã ã¡ãã»ãŒãžã«ã¯åŒæ°ãå«ããããšãã§ããŸããïŒé¢æ°ã®åŒæ°ãšã»ãŒåãïŒãã¡ãã»ãŒãžåŒæ°ã¯éä¿¡åã«å®è¡ãããŸããã
ã¡ãã»ãŒãžãéä¿¡ããæ¹æ³
ã¡ãã»ãŒãžã®éä¿¡ã¯ãããªããžã§ã¯ããããã¹ããŒã¹ãããã¡ãã»ãŒãžãã®ããã«èŠããŸããDatabase connect
ã¡ãã»ãŒãžã«ã¯åŒæ°ãå«ãŸããå ŽåããããŸãã
Database findByName("Oleg")
ã¡ãã»ãŒãžãéä¿¡ããçµæã«ã¯ãã¡ãã»ãŒãžãéä¿¡ããããšãã§ããŸãã
Database findByName("Oleg") lastName # , "Andreev"
èšãæãããšã
abcd
æ§é ã¯
a().b().c().d()
ãšåçã®javaã«äŒŒãæ§æã§ãã
ã¡ãã»ãŒãžã®å®è¡æ¹æ³
ãŸããã¡ãã»ãŒãžåŒæ°ãå®è¡ãããªãããšã«æ³šæããŠãã ãããDatabase connect(blah-blah)
ãæžã蟌ãŸããå Žåãæ¥ç¶ãéä¿¡ãããåã«blah-blahã¯å®è¡ãããŸããããã¡ãã»ãŒãžãconnectïŒblah-blahïŒãã®äžéšãšããŠéä¿¡ãããŸãïŒã¯ããèšèã§ïŒã
ãªããžã§ã¯ããã¡ãã»ãŒãžãåä¿¡ãããšããã®ã¡ãã»ãŒãžã®ååãæã€ã¹ããããæ€çŽ¢ããŸãïŒãã®äŸã§ã¯
connect
ïŒã ã¹ããããèŠã€ãããªãå ŽåïŒéåžžïŒããã®æ€çŽ¢ã¯ãã¹ãŠã®ãªããžã§ã¯ããããã¿ã€ããšãã®ãããã¿ã€ãã§ååž°çã«å®è¡ãããŸãã ç®çã®ã¹ããããã©ãã«ãèŠã€ãããªãå Žåã
forward
ã¹ãããæ€çŽ¢ãéå§ãããŸãïŒRubyã®
method_missing
ã«é¡äŒŒïŒã é©åãªã¹ããããèŠã€ãããšããã«ããã®å€ãã¢ã¯ãã£ãã«ãªããŸã ïŒã¢ã¯ãã£ãåïŒã ïŒæ³šïŒèŠã€ãã£ãã¹ããããã©ã®ç¹å®ã®ãªããžã§ã¯ãã«ããããObject contextWithSlotïŒslotNameïŒãéç¥ããŸããïŒ
ã¢ã¯ãã£ããŒã·ã§ã³
éåžžã®å€ã®å Žåãã¢ã¯ãã£ããŒã·ã§ã³ã¯äœãããããã®å€ãè¿ããŸãã ãããã£ãŠãæ°å€ãæååããŸãã¯ä»ã®å€ãã®ãªããžã§ã¯ããæ ŒçŽããéåžžã®ã¹ãããã®ã¢ã¯ãã£ãåã¯ãgetSlotïŒ slotName ïŒãä»ããŠå€ãååŸããããšãšå€ãããŸããã ãã ãã èµ·å å¯èœãšããŠããŒã¯ãããŠãããªããžã§ã¯ãã¯ã activateã¡ãœãããåŒã³åºããŸãã ããã©ã«ãã§ã¯ããããã¯ïŒãããã¯ãšã¡ãœããïŒãšCFunctionïŒé¢æ°ãžã®ãªã³ã¯ïŒã®2ã€ã®ãªããžã§ã¯ãã®ã¿ãã¢ã¯ãã£ãã«ãªããŸãã ä»ã®ãã¹ãŠã®ãªããžã§ã¯ãã¯ãsetIsActivatableïŒtrueïŒã䜿çšããŠã¢ã¯ãã£ãåã§ããŸããgetSlotïŒslotNameïŒã¡ãœãããåŒã³åºããããšãã¹ãããã®ã¢ã¯ãã£ãåã¯è¡ãããŸããïŒãã¡ãããgetSlotã¹ãããèªäœã¯ã¢ã¯ãã£ãã«ãªããŸããã slotNameã¯ããååšããŸããïŒã ãããã£ãŠãã¡ãœãããŸãã¯ãã®ãŸãŸã®ãããã¯ãåŒã³åºããã«ååŸããå Žåã¯ãgetSlotïŒmethodNameïŒã䜿çšããŸãã
1ã€ã®èœãšãç©Žã¯ã¢ã¯ãã£ããŒã·ã§ã³ã«é¢é£ããŠãããããã«ã€ããŠã¯èšäºã®æåŸã§èª¬æããŸãã
ã㌠ãããŠãåŒæ°ã¯ãã€å®è¡ãããŸããïŒ
ã¡ãã»ãŒãžãéä¿¡ãããã¹ããããèŠã€ãããã¢ã¯ãã£ãã«ãªããŸããã ããããã¡ãã»ãŒãžåŒæ°ã¯ãã€ãã©ã®ãããªã³ã³ããã¹ãã§èšç®ãããŸããïŒäŸãèããŠã¿ãŸãããïŒ
withoutArgs := method() # nil
withoutArgs("Hello!" println)
åŒæ°ãHelloïŒãPrintlnãå®è¡ãããªãã£ãããããã®ã³ãŒãã¯äœãåºåããŸããã
withArgs := method(a, b, c, list(a,b,c)) #
withArgs("Hello!" println) # list("Hello!", nil, nil)
ãã®ã³ãŒãã¯æåã®åŒæ°ãå®è¡ããHelloïŒã衚瀺ããŸãã æ¬ èœããŠããåŒæ°ã¯nilã§ãã
å¥ã®äŸïŒ
withTwoArgs := method(a, b, nil)
withTwoArgs(1 print, 2 print, 3 print, 4 print)
ãã®ã³ãŒãã¯12ãåºåããŸããã1234ã¯åºåããŸããã
æãç¬åµçãªäººã¯ã宣èšãããåŒæ°ã®ã¿ãå®è¡ãããŠããããšããã§ã«èªèããŠããŸãã æãé¢çœãã®ã¯ãããããã©ã®ããã«å®è¡ãããããã©ãã§ã©ãã§æ±ããæãåããããšãã§ãããã§ãã ãããŠããªãããããã¹ãŠå¿ èŠãªã®ãã
ã€ã³ããã¹ãã¯ã·ã§ã³ã¡ãœããã®åŒã³åºã
Ioã«ã¯ãªããžã§ã¯ãããããã¿ã€ããã¹ããããã¡ãã»ãŒãžã®ã¿ãããããšããŸã èŠããŠããŸããïŒ ãã®ãªã¹ãã«ã¯ã°ããŒãã«å€æ°ãããŒã«ã«å€æ°ããããŸãããIoã¯ã¹ããããã¢ã¯ãã£ãã«ããïŒã€ãŸããã¡ãœãããåŒã³åºãïŒãšãç¹å¥ãªLocalsãªããžã§ã¯ããäœæããŸãã ããã¯å€ãã®éèŠãªæ©èœãåããéåžžã«é¢çœããªããžã§ã¯ãã§ãã ãŸãããã®ãªããžã§ã¯ãã®ãããã¿ã€ãã¯selfãã€ãŸãã§ãã ã¡ãã»ãŒãžã®éä¿¡å ã®ãªããžã§ã¯ããžã®ãã€ã³ã¿ãŒã ãããã£ãŠãåä¿¡è ãªããžã§ã¯ãã«å¹²æžããããšãªãããŒã«ã«ã¹ãããïŒããŒã«ã«å€æ°ãšãåŒã°ããŸãïŒãäœæãããã®ãªããžã§ã¯ãã®ãã¹ãŠã®ã¹ãããã«ã¢ã¯ã»ã¹ã§ããŸãã 次ã«ããã®ãªããžã§ã¯ãã«ã¯å°ãªããšã3ã€ã®ã¹ãããããããŸãïŒselfïŒåä¿¡è ãªããžã§ã¯ããæãïŒãcallïŒåŒã³åºãã«é¢ããå€ãã®æ å ±ãå«ãïŒãããã³updateSlotã åŸè ã¯ãããŒã«ã«ã§ã¯ãªãåä¿¡è ãªããžã§ã¯ãã§ã¹ããããæŽæ°ãããšããç¹ã§ãéåžžã®updateSlotãšã¯ç°ãªããŸãã ããã¯ãself a = bã§ã¯ãªããa = bãšæžãããã ãã«è¡ãããŸãã
åŒã³åºããªããžã§ã¯ãã®çŽ æŽããããšããã¯ããã®è€æ°ã®ã¹ãããã§ãïŒ
- åŒã³åºãéä¿¡è
-ã¡ãã»ãŒãžãéä¿¡ããããªããžã§ã¯ãïŒããŒã«ã«ïŒã
call target-ã¡ãã»ãŒãžã®éä¿¡å ã®ãªããžã§ã¯ãïŒ== selfïŒã
åŒã³åºãã¡ãã»ãŒãž-å®éã«ã¯ãååãšåŒæ°ãå«ãã¡ãã»ãŒãžã
evalArgAtïŒargNumberïŒãåŒã³åºããevalArgsã¯éä¿¡è ã®ã³ã³ããã¹ãïŒéä¿¡è ã®åŒã³åºãïŒã§åŒæ°ã®äžéšãŸãã¯ãã¹ãŠãå®è¡ããŸãã ãããã誰ããã®ãããªããšãããããšãæ°ã«ããŸããïŒ
Object do := method(call message arguments first doInContext(self) )
"string" do(
type println
size println
encoding println
)
ç»é¢äžã«è¡šç€ºãããŸãïŒ
Sequence
6
ascii
ã€ãŸããä»»æã®ã³ã³ããã¹ãã§ã®éä¿¡ãä¿åãå®è¡ãªã©ã奜ããªããã«ã³ãŒããæäœã§ããŸãã æ¢ã«äœæããããªããžã§ã¯ãã®ã³ãŒããèŠãããšãã§ããŸãïŒã³ã«ãŒãã³getSlotïŒ "yield"ïŒã³ãŒãã¯yieldã¡ãœããã³ãŒããæååãšããŠè¿ããŸãïŒ
method(
if(yieldingCoros isEmpty, return )
yieldingCoros append(self)
next := yieldingCoros removeFirst
if(next == self, return )
if(next, next resume)
)
ã¡ãªã¿ã«ãç§ã¯å°å ã®ãããã¿ã€ãã«ã€ããŠåãã€ããã ãŸã èŠããŠããã°ãIoã®ã¡ãœããã®ä»ã«ãããã¯ïŒã¯ããŒãžã£ãŒïŒããããŸãã ã¡ãœãããšã®å¯äžã®éãã¯ããããã¯ã®Localsãããã¿ã€ãããã¡ãã»ãŒãžã®åä¿¡è ãžã®ãã€ã³ã¿ãŒã§ã¯ãªããã¹ã³ãŒããžã®ãã€ã³ã¿ãŒã§ãããšããããšã§ãã ãããã¯ãäœæãããïŒããã³éããããïŒãªããžã§ã¯ãã æåŸã«ãå±æ ¹ãåºãããã«ãã¹ã³ãŒããããã¯ã¹ãããã¯ããããã¯ã¡ãœãããåŒã³åºãããæç¹ã®çºä¿¡è ãšæ£ç¢ºã«çããããšãè¿œå ããŸãã
ããŒã«ã«å€æ°ã«æ»ã
åŒã³åºãéä¿¡è ãåŒã³åºãã¡ãã»ãŒãžãªã©ã®åŒ·åãªæŠåšã䜿çšããŠãã¡ãœããåŒã³åºããšåŒæ°ã®å®è¡ãIoèšèªã§èšè¿°ããããšãã§ããŸãã å®éãã¡ãœããïŒaãbãnilïŒãšèšã£ãŠãããŒã«ã«ã«ã¹ããããaããšãbããäœæããåŒã³åºãéä¿¡è ã®ã³ã³ããã¹ãã§å¯Ÿå¿ããåŒæ°ãå®è¡ãããåŸã«åä¿¡ããå€ã§ããããåããããšèšããŸãã 宿é¡ïŒçµã¿èŸŒã¿ã¡ãœãããšåãæ¹æ³ã§ã¡ãœãããäœæãã宣èšããã³æž¡ãããåŒæ°ã«å¯ŸããŠdoInContextã䜿çšããŠå¿ èŠãªãã¹ãŠã®æäœãè¡ãmethod2ã¡ãœãããèšè¿°ããŸãã
çŽæãããã¢ã¯ãã£ããŒã·ã§ã³ããªãã¯
Javaã®ãããªæ§æã§ã¯ãé¢æ°ãšãã®åŒã³åºããžã®ã¢ã¯ã»ã¹ã¯æ¬¡ã®ããã«ãªããŸãïŒobj.funcããã³obj.funcïŒïŒã Ioã§ã¯ãobjã¹ããããã¹ãããã®å€ãå¿ ãã¢ã¯ãã£ãã«ããå Žåãã¢ã¯ãã£ãåããã«å€ãååŸããã«ã¯obj getSlotïŒ "slot"ïŒã䜿çšããŸãã
åŒæ°ãšããŠå¥ã®ã¡ãœãããåãããšãã§ããã¡ãœãããæžããŠãããšä»®å®ããŸãïŒ
method(func, ...)
ã¡ãœããã®æ¬äœå ã«funcãèšè¿°ããå Žåãå¿ ãæž¡ãããã¡ãœãããåŒã³åºããŸãã å€ãååŸããå¿ èŠãããå Žåã¯ãgetSlotïŒ "func"ïŒã䜿çšããŠæ¯åã¢ã¯ã»ã¹ããå¿ èŠããããŸãã
ã¡ãã»ãŒãžãã¶ã€ã³
messageã¡ãœããã¯ãæåã®åŒæ°ãæªè§£æ±ºã®ã¡ãã»ãŒãžãšããŠè¿ããŸãã
msg := message(something(arg1, arg2, arg3) nextMessage(arg1, arg2) more)
msg name # => "something"
msg next # => message(nextMessage(arg1, arg2) more)
msg next next # => message(more)
msg next name # => "nextMessage"
msg arguments # => list(message(arg1), message(arg2), message(arg3))
ãŸãšã
ããã§ãã¡ãã»ãŒãžã®éä¿¡æ¹æ³ãã¡ãœããã®åŒã³åºããããã³åŒæ°ã®å®è¡æ¹æ³ãããããŸããã ãªã¹ãïŒ1,2,3ïŒforeachïŒå°å·ïŒïŒå°å·ã¯ãªã¹ãã®åèŠçŽ ã«éä¿¡ãããïŒãŸãã¯ãªã¹ãïŒ1,2,3ïŒãããïŒ* 2ïŒïŒ*ïŒ2ïŒã¯äœææã«åèŠçŽ ã«éä¿¡ãããïŒãªã¹ãã®ã³ããŒïŒã
ããŒãã¹ãã©ãã¯ïŒé»è©±ãµã€ã
èšäºã®æåŸãŸã§èªãã 1.5人ã®æãæã¯ãç¹ã«é©ãã¹ãæ å ±ã§å ±ãããããšãã§ããŸãã Ioã®æŠå¿µã§ã¯ããããããåŒã³åºããã€ã³ããã«å°éããããšãå¯èœã§ãã ããã¯ã¿ã€ã§ã¯ãªããå¥åãã³ãŒã«éä¿¡è ãã³ã³ããã¹ãã§ã¯ãªããã³ãŒã«ãçºçããã³ãŒãã®ãã€ã³ãã§ãã 倧äºãªããšã¯ãåŒã³åºãã¡ãã»ãŒãžã¯ããã®å Žã§çæããããã³ãŒãã§èšè¿°ãããŠããå ŽåïŒåžžã«çæãããããåžžã«éä¿¡ãããïŒãåžžã«åããªããžã§ã¯ããè¿ããšããããšã§ãã ããã¯äœãäžããŸããïŒ 1ã€ã®ã¡ãœããã§ïŒããã°ã©ã å ã®ç°ãªãå Žæã§ïŒããŸããŸãªã¡ãã»ãŒãžãåŠçã§ãããããé¢é£ããå Žæã§æçšãªãã®ããã£ãã·ã¥ããããšãå¯èœã«ãªããŸãã
æãåçŽãªïŒã¡ãã»ãŒãžsetCachedResultïŒresïŒã¯ããã®ã¡ãã»ãŒãžãã©ããã«éä¿¡ããããšãããšãã«è¿ãããã¡ãã»ãŒãžã®èšç®å€ãèšå®ããŸãã ããè€éãªãªãã·ã§ã³ïŒç¹å®ã®ãã€ã€ã«ãã¢ã§ç¹å®ã®ã¡ãã»ãŒãžã«é©åããç¹å¥ãªããžãã¯ããã£ãã·ã¥ããŸãã
ããšãã°ãList mapã¡ãœããã«ã¯ã1ã€ã2ã€ã3ã€ã®åŒæ°ãæã€3ã€ã®å®è£ ããããŸãã çŸåšã®å®è£ ã§ã¯ãåŒã³åºãããšã«åŒæ°ã®æ°ã®æ€èšŒãè¡ãããŸãããåŒã³åºãã¡ãã»ãŒãžã«ç®çã®ã¡ãœãããªãã·ã§ã³ããã£ãã·ã¥ããããšã¯å¯èœã§ãã
ãã®æ©èœã«åºã¥ããŠãããè€éãªæé©åã¹ããŒã ãæ§ç¯ã§ããŸãã