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

Extend your own programming language (RubyKaigi 2018)

Extend your own programming language (RubyKaigi 2018)

RubyKaigi 2018 : Extend your own programming language

seki at druby.org

June 01, 2018
Tweet

More Decks by seki at druby.org

Other Decks in Programming

Transcript

  1. slide sponsors " " ! !!! @moro @ tricknotes dRuby

    Web ( ) https://t.co/fLhzWll5gY @hisashim Rails 700 https://t.co/wAMLWDekJh?amp=1 @igaiga555 https://lambdanote.com @golden_lucky @vestige_
  2. slide sponsors 5 !! 6 2 Scratch Day in !!

    @mame iSeq iSeq @youchan Speee Ruby @koichiroo RubyKaigi 2018 2 @ktou RubyWorld Conference 2018 yancya @yancya
  3. slide sponsors seki @tsuboi @ogijun people.suzuri.jp hsbt tatsuosakurai kenchan june29

    zaimy tnmt umazura 4 -20 pixiv FANBOX halfmoon_0419 usa shimashima35 igaiga
  4. Agenda About Me MinRuby Binary Operator, Builtin Function ⭐ Tail

    Call Optimization ⭐⭐ Linda eval / Process Migration ⭐⭐⭐ ࢲʹ͍ͭͯ࿩ͨ͋͠ͱɺ.JO3VCZΛ਺ஈ֊ʹ෼͚ͯվ଄͠·͢ɻ࠷ ऴతʹɺҾ਺ΛධՁ͠ͳ͍ؔ਺ݺͼग़͠ʢʁʣͱϓϩηεͷҠૹΛ ࣮૷ͯ͠ɺ-JOEBͷFWBMΛ࡞Γ·͢ɻ⭐ ͸೉͠͞
  5. First printing from 2005 (Still available) dRuby ʹΑΔ ؔকढ़ஶ ෼ࢄ

    ɾ Web ϓϩάϥϛϯά ೥ͷॳ࡮Γ͕·ͩങ͑·͢ʂʂ101ॻ͍͔ͨΒݟͯʂ
  6. Ruby Committer ERB, dRuby, Rinda 3VCZίϛολͰ͢ɻ&3#  E3VCZ  3JOEB͕कඋൣғɻ͜ΕΒ͸

    ׬੒ͨ͠਺গͳ͍ϓϩδΣΫτͰ͢ɻ࠷ۙͷίϛοτ͸LLVCVO ͞ΜΛίϛολʹίϛοτͨ͜͠ͱͱɺE3VCZͷ%PDLFSରԠͰ ͢ɻ
  7. Cancelled Projects Agent Ruby, Persistent Ruby dRuby for mruby Bartender

    ͦΕ͔Βɺ์غ͞ΕͨେྔͷϓϩδΣΫτɻ ࠷ॳͷೋͭ͸࣮ߦίϯςΩετΛγϦΞϥΠζͰ͖ͳͯ͘಴ ࠳ɻޙऀ͸NSVCZͷϏϧυ͕ΊΜͲͯ͘͘͞๞͖ͯ͠·ͬͨɻ ࡢ೥ͷ3VCZ,BJHJͰ࿩ͨ͠'JCFSͱ#BSUFOEFS͸ͦͷ໊࢒ɻ
  8. toRuby (Tochigi Ruby meetup) Ruby 1st Wednesday at 18:30 (June

    6th) Nishinasuno, Tochigi ͱͪ͗3VCZͷษڧձͰ͸࣍ͷຊΛษڧ͍ͯ͠·͢
  9. slide sponsors " " ! !!! @moro @ tricknotes dRuby

    Web ( ) https://t.co/fLhzWll5gY @hisashim Rails 700 https://t.co/wAMLWDekJh?amp=1 @igaiga555 https://lambdanote.com @golden_lucky @vestige_
  10. MinRuby A small language that extracts particularly important language functions

    in Ruby ʮ3VCZͷதͰಛʹॏཁͳݴޠػೳ͚ͩΛநग़ͨ͠খ͞ͳݴޠʯ ҉هͰ͖Δ͘Β͍খ͍͚͞Ͳɺࣗ෼ࣗ਎Λॻ͚Δ͘Β͍ʹେ ͖͍ɻ͔͍͍ͬ͜ɻ (Ruby Ruby p.iii)
  11. Implementation Use ripper for parsing Convert ripper's output into MinRuby

    AST evaluate() function evaluates it ࣮૷ͷಛ௃ɻߏจղੳ͸3JQQFSʹ೚͍ͤͯΔɻ3JQQFSͷग़ྗ Λ؆ུԽͯ͠.JO3VCZͷ"CTUSBDU4ZOUBY5SFFʹม׵͢Δɻ "45Λ௚઀ධՁ͢ΔFWBMVBUF ؔ਺͕ΠϯλϓϦλͷਖ਼ମɻ 5SFF8BMLJOH*OUFSQSFUFS
  12. Hash literal Array literal String literal )BTI  "SSBZ 

    4USJOHͷϦςϥϧ͕͋Δɻσʔλߏ଄Ά͍΋ͷΛ࡞Δ ͷʹΪϦΪϦ͘Β͍ͷදݱྗ͕͋Γͦ͏ɻ
  13. CJOBSZ + - * / % < <= == !=

    >= > binary operator ೋ߲ԋࢉࢠɻ࢛ଇԋࢉ͸Ͱ͖Δ͚Ͳɺ࿦ཧ࿨ɺ࿦ཧੵ͕ͳ͍ͳʔɻ
  14. builtin p, minruby_parse, minruby_load, minruby_call function def / call variable

    assgin / ref Literal Integer / String Hash / Array if ... else case while Array / Hash assign /ref binary operator ΠϯλϓϦλʹඞཁͳ΋ͷɺগͳ͍ʂDMBTT΋ϝιουݺͼग़͠΋ͳ ͍ɻେৎ෉͔ʂʁ
  15. Language Specification if, while Integer, String Hash, Array variable no

    classes, no method calls .JO3VCZࣗ਎Λ࡞Δͷʹඞཁͳ࠷খݶͷػೳʹ࢛ଇԋࢉͳͲ Λ௥Ճͨ͠΋ͷ͕.JO3VCZͷݴޠ࢓༷Ͱ͢ɻDMBTT΍ϝιου ίʔϧͳͲ͸͋Γ·ͤΜɻʮ3VCZͷதͰಛʹॏཁͳݴޠػೳ ͚ͩΛநग़ͨ͠খ͞ͳݴޠʯͷখ͍͢͞͞͝ʂ
  16. for DSL Make library to read settings. Unsupported features do

    not work. 3VCZͷ͕ࣜॻ͚ΔઃఆϑΝΠϧͷϥΠϒϥϦʹ࢖͏ͷ͸Ͳ͏ ͔ɻ$3VCZͷػೳΛͦͷ··࢒ͨ͠%4-ͩͱةݥͳૢ࡞Λࢭ ΊΔͷ͕໘౗͚ͩͲɺ.JO3VCZͳΒ͜͏͍ͬͨૢ࡞͸ػೳ͠ ͳ͍ɻ҆৺ʂ dpi = 400 { "width" => dpi * 10, "height" => dpi * 20, # "bang!" => system("rm *") }
  17. for DSL MinRuby ͍ͨͣΒ͠Α͏ͱͯ͠΋༻ҙ͞Εͯͳ͍ػೳ͸ΤϥʔʹͳΔʂ ҆৺ʂʢΤϥʔ͸ͪΐͬͱෆ਌੾͚ͩͲؾʹ͠ͳ͍ʣ dpi = 400 { "width"

    => dpi * 10, "height" => dpi * 20, "bang!" => system("rm *") } % ruby interp.rb prog.rb Traceback (most recent call last): 3: from interp.rb:118:in `<main>' 2: from interp.rb:33:in `evaluate' 1: from interp.rb:95:in `evaluate' interp.rb:61:in `evaluate': undefined method `[]' for nil:NilClass (NoMethodError)
  18. Extend MinRuby Binary Operator, Builtin Function ⭐ Tail Call Optimization

    ⭐⭐ Linda eval / Process Migration ⭐⭐⭐
  19. builtin function ⭐ bultin function p() require() case study: add

    car(), cdr() εΫϦϓτͰ࢖͑ΔCVJMUJOؔ਺͸Q ͘Β͍ɻ"SSBZ͸͋Δ͚ Ͳ"SSBZͷϝιου͸ݺ΂·ͤΜɻ"SSBZͷૢ࡞ɺཉ͍͠Ͱ͢ ΑͶɻ-*41ʹ฿ͬͯDBSͱDESΛ.JO3VCZʹ௥Ճ͠·͠ΐ͏ɻ
  20. require MinRuby require is implemented by CRuby require require "minruby"

    require "your_library" def evaluate(tree, genv, lenv) case tree[0] ...
  21. genv HFOWʹCVJMUJOͱͯ͠ొ࿥͢Δ genv = { "p" => ["builtin", "p"], "require"

    => ["builtin", "require"], "minruby_parse" => ["builtin", "minruby_parse"], "minruby_load" => ["builtin", "minruby_load"], "minruby_call" => ["builtin", "minruby_call"], "car" => ["builtin", "car"], "cdr" => ["builtin", "cdr"] }
  22. binary operator copy & paste  Λਅࣅͯ͠࿦ཧ࿨ɺ࿦ཧੵΛ௥Ճͯ͠Έ·͢ɻFWBMVBUF ͷXIFO۟Λ௥Ճ͢Ε͹0,ɻ3VCZʹଘࡏ͢Δԋࢉࢠ͸SJQQFS ͕ରԠࡁΈ͔ͩΒ؆୯ʹͰ͖·͢ɻ 3VCZʹͳ͍ͱ͖͸ΊΜͲͦ͘͞͏ɻ

    case tree[0] ... when "+" evaluate(tree[1], genv, lenv) + evaluate(tree[2], genv, lenv) ... when "||" evaluate(tree[1], genv, lenv) || evaluate(tree[2], genv, lenv) when "&&" evaluate(tree[1], genv, lenv) && evaluate(tree[2], genv, lenv)
  23. if ⭐ if ... else ... end - works! if

    ... end - does not woke.
  24. if ⭐ վ଄͍ͯͯ͠ؾ͍͚ͮͨͲɺFMTF۟ͷͳ͍JGจ͸Τϥʔʹͳͬ ͯ͠·͍·͢ɻͦ͏͍͏ͷɺΠϯλϓϦλͷ࣮૷ʹ͸ඞཁͳ ͔ͬͨͷ͔ͶɻͰ΋ࣗ෼͸࢖͍͍ͨͷͰ௚͍ͨ͠ɻ if false p "not reached"

    end p "done" % ruby interp.rb prog.rb Traceback (most recent call last): 3: from interp.rb:118:in `<main>' 2: from interp.rb:33:in `evaluate' 1: from interp.rb:45:in `evaluate' interp.rb:4:in `evaluate': undefined method `[]' for nil:NilClass (NoMethodError)
  25. fixed tree[1] - condition evaluate(tree[2]) if true evaluate(tree[3]) if false

    JGͷߏจ໦͸USFF<>͕৚݅ɺUSFF<>͕৚͕݅ਅͷ৔߹ʹධՁ ͢ΔࢬɺUSFF<>͕৚ِ͕݅ͷͱ͖ʹධՁ͢ΔࢬͰ͢ɻFMTF۟ ͕ͳ͍৔߹USFF<>͸OJMͳͷͰɺͦͷ৔߹͸USFF<>ΛධՁ͠ ͳ͍Α͏ʹ͠·ͨ͠ɻ when "if" if evaluate(tree[1], genv, lenv) evaluate(tree[2], genv, lenv) else evaluate(tree[3], genv, lenv) end when "if" if evaluate(tree[1], genv, lenv) evaluate(tree[2], genv, lenv) elsif tree[3] evaluate(tree[3], genv, lenv) end
  26. syntax sugar elsif case ... when FWBMVUBUF ͷXIFOΛݟͯΈΔͱɺFMTJG΍DBTF͕ͳ͍͜ͱ ʹؾ͖ͮ·͢ɻNJOSVCZ@QBSTF ͸SJQQFSͷग़ྗΛ.JO3VCZ

    ͷ"45ʹม׵͢ΔࡍʹɺFMTJG΍DBTΛෳ਺ͷJGͷ૊Έ߹Θͤʹ ͍ͯ͠·͢ɻ when "if" if evaluate(tree[1], genv, lenv) evaluate(tree[2], genv, lenv) elsif tree[3] evaluate(tree[3], genv, lenv) end
  27. syntax sugar ͜ͷೋͭͷεΫϦϓτ͸FMTJGΛ࢖͏έʔεͱ࢖Θͳ͍έʔεͰ ͕͢ɺͲͪΒͷ৔߹΋ಉ͡"45ʹม׵͞Ε·͢ɻ if a == 0 "IF" elsif

    a == 1 "ELSIF" else "ELSE" end if a == 0 "IF" else if a == 1 "ELSIF" else "ELSE" end end ["if", ["==", ["var_ref", "a"], ["lit", 0]], ["lit", "IF"], ["if", ["==", ["var_ref", "a"], ["lit", 1]], ["lit", "ELSIF"], ["lit", "ELSE"]]]
  28. stack level too deep def fact(n, v) if n ==

    1 v else fact(n-1, v * (n-1)) end end p fact(5000, 1) % ruby interp.rb fact.rb Traceback (most recent call last): 5241: from interp.rb:118:in `<main>' 5240: from interp.rb:33:in `evaluate' 5239: from interp.rb:57:in `evaluate' 5238: from interp.rb:71:in `evaluate' 5237: from interp.rb:45:in `evaluate' 5236: from interp.rb:71:in `evaluate' 5235: from interp.rb:45:in `evaluate' 5234: from interp.rb:71:in `evaluate' ... 5229 levels... 4: from interp.rb:71:in `evaluate' 3: from interp.rb:45:in `evaluate' 2: from interp.rb:57:in `evaluate' 1: from interp.rb:12:in `evaluate' interp.rb:10:in `evaluate': stack level too deep (SystemStackError) ΄Βಈ͔ͳ͍Ͱ͠ΐɻ
  29. AST of fact.rb ["stmts", ["func_def", "fact", ["n", "v"], ["if", ["==",

    ["var_ref", "n"], ["lit", 1]], ["var_ref", "v"], ["func_call", "fact", ["-", ["var_ref", "n"], ["lit", 1]], ["*", ["var_ref", "v"], ["-", ["var_ref", "n"], ["lit", 1]]]]]], ["func_call", "p", ["func_call", "fact", ["lit", 5000], ["lit", 1]]]] def fact(n, v) if n == 1 v else fact(n-1, v * (n-1)) end end p fact(5000, 1)
  30. AST of fact.rb ["stmts", ["func_def", "fact", ["n", "v"], ["if", ["==",

    ["var_ref", "n"], ["lit", 1]], ["var_ref", "v"], ["func_call", "fact", ["-", ["var_ref", "n"], ["lit", 1]], ["*", ["var_ref", "v"], ["-", ["var_ref", "n"], ["lit", 1]]]]]], ["func_call", "p", ["func_call", "fact", ["lit", 5000], ["lit", 1]]]] func_def func_call statements
  31. "func_def" GVOD@EFG͸ؔ਺ఆٛͰ͢ɻHFOWʢάϩʔόϧʁʣͱ͍͏ϋο γϡʹؔ਺໊ɺԾҾ਺ɺؔ਺ຊମͷ໦ΛϝϞ͠·͢ɻ when "func_def" genv[tree[1]] = ["user_defined", tree[2], tree[3]]

    name param body ["func_def", "fact", ["n", "v"], ["if", ["==", ["var_ref", "n"], ["lit", 1]], ["var_ref", "v"], ["func_call", "fact", ["-", ["var_ref", "n"], ["lit", 1]], ["*", ["var_ref", "v"], ["-", ["var_ref", "n"], ["lit", 1]]]]]],
  32. when "func_call" args = [] i = 0 while tree[i

    + 2] args[i] = evaluate(tree[i + 2], genv, lenv) i = i + 1 end mhd = genv[tree[1]] if mhd[0] == "builtin" minruby_call(mhd[1], args) else new_lenv = {} params = mhd[1] i = 0 while params[i] new_lenv[params[i]] = args[i] i = i + 1 end evaluate(mhd[2], genv, new_lenv) end evaluate arguments prepare new_lenv evaluate body "func_call" GVOD@DBMM͸ؔ਺ݺͼग़͠Ͱ͢ɻ࣮Ҿ਺Λܭࢉ͠ɺԾҾ਺ͱ ࣮Ҿ਺Ληοτͨ͠ϋογϡOFX@MFOWΛ࡞Γ·͢ɻ࠷ޙʹؔ ਺ͷຊମΛFWBMVBUF ͠·͢ɻ
  33. Implementation mark_tail() add "tail" handler add "(jump)" loop ຤ඌݺͼग़͠࠷దԽ͸࣍ͷࡾͭͷύʔτ͔ΒͰ͖͍ͯ·͢ɻҰͭ ͸ؔ਺ͷ຤ඌʹ͋Δؔ਺ݺͼग़͠Λ୳ͯ͠UBJMϚʔΫΛ͚ͭΔ෦

    ෼ɺ΋͏Ұͭ͸UBJMʹରԠ͢Δ໦ͷॲཧɻͦͯ͠UBJMͷॲཧͷ ͱ͖ʹ࡞੒͢Δδϟϯϓ৘ใΛ࢖ͬͯδϟϯϓ͢Δ෦෼Ͱ͢ɻ
  34. mark_tail() NBSL@UBJM ͸ؔ਺ఆٛ࣌ʹݺ͹ΕΔαϒϧʔνϯͰ͢ɻ"45 Λ୳ࡧͯ͠຤ඌͷGVOD@DBMMͷࢬΛUBJMʹॻ͖׵͑·͢ɻ when "func_def" mark_tail(tree[3], genv) genv[tree[1]] =

    ["user_defined", tree[2], tree[3]] ["if", ["==", ["var_ref", "n"], ["lit", 1]], ["var_ref", "v"], ["func_call" "tail", "fact", ["-", ["var_ref", "n"], ["lit", 1]], ["*", ["var_ref", "v"], ["-", ["var_ref", "n"], ["lit", 1]]]]]], set "tail"
  35. mark_tail() ෳจͷ຤ඌͷࢬΛ୳ࡧʢϚʔΫʣɺJGͷೋͭͷࢬΛ୳ࡧɺͦ͠ ͯؔ਺ݺͼग़͠ʹग़ձͬͨΒGVOD@DBMMΛUBJMʹॻ͖׵͑· ͢ɻ def mark_tail(tree, genv) case tree &&

    tree[0] when "stmts" mark_tail(tree[-1], genv) when "if" mark_tail(tree[2], genv) mark_tail(tree[3], genv) when "func_call" mhd = genv[tree[1]] if mhd == nil || mhd[0] == "user_defined" tree[0] = "tail" end end end tail of statements ෼ذͷೋͭͷࢬΛ୳ࡧ set "tail" two branches of if
  36. "tail" handler UBJMͷॲཧ͸GVOD@DBMMͱΑ͘ࣅ͍ͯ·͢ɻҾ਺ͷࢬΛධՁ ͯ͠Ҿ਺ͷOFX@MFOWΛ࡞Γ·͢ɻδϟϯϓઌͷࢬͱOFX@MFOW ΛHFOW< KVNQ >ʹϝϞ͠·͢ɻʢ΋͔͢͠ΔͱMFOWͰ΋Α ͔͔ͬͨ΋ʣ when "tail"

    mhd = genv[tree[1]] new_lenv = {} params = mhd[1] i = 0 while params[i] new_lenv[params[i]] = evaluate(tree[i + 2], genv, lenv) i = i + 1 end genv["(jump)"] = [new_lenv, mhd[2]] true evaluate arguments remember jump destination and arguments
  37. add "(jump)" loop  KVNQ ͷϝϞ͕͋Δؒɺͦ͜ʹॻ͍ͯ͋Δδϟϯϓઌͷࢬͱ Ҿ਺ΛFBWBMVBUF ͠·͢ɻ when "func_call"

    mhd = genv[tree[1]] if mhd[0] == "builtin" .... else new_lenv = {} params = mhd[1] i = 0 while params[i] new_lenv[params[i]] = evaluate(tree[i + 2], genv, lenv) i = i + 1 end last = evaluate(mhd[2], genv, new_lenv) while genv["(jump)"] new_lenv = genv["(jump)"][0] jump = genv["(jump)"][1] genv["(jump)"] = nil last = evaluate(jump, genv, new_lenv) end last end (jump) loop
  38. It might work! def fact(n, v) if n == 1

    v else fact(n-1, v * (n-1)) end end p fact(5000, 1) % ruby interp.rb fact.rb
  39. Unreadable def fact(n, v) if n == 1 v else

    fact(n-1, v * (n-1)) end end p fact(5000, 1) % ruby interp.rb fact.rb 845715585321108704440212840046716881078157334925329349769956480436271610541621640138179809574341277507416949331460137089175697213336762547267442178754557526255878072611692432128780895797396447974385941779242322530593664355100079848439367406293814528945757579580809509768324430453343856821938473820899131943 472705896800447680762241289640461715342209004612349789510856619523563448081610649619855618657568110972398729096582423752516497604378347955800100426425196087278489252921541022717693190217350941171667849310451178070948871976694766357976069266016917263020418183019871307640021866095931485113483861834110345610 400472150171982395270457511815804086739486247013833662423848991943112534815042924397972466177251996605719729715157498891926230573941773420092536847296357979810909381722783226436688348297614372468896229662418980722393093745535511235773657440538209628184912820683671951208552916323026357151803322143565088313 961766718745459991206742742400942098875312582284977210670598999284601399944409836240201638118878281350106530009551067701798195890203102182973814008814239144672052486736264660437418575398393613313139505580844516535683122166752851562065258405374422140549362788702257203004652381299918343794728352756872982439 418219681889029790717918207608353883913315669644143498211025505278296762344105209653930325285420189838786665322060208721060918234029114419169428707443896493373586934751809744536266820415721807314217612753232499499014826214154803364361171891052890342818554938460125395022692088349135893471657564523259168497 350314758345885448357566210859716490235151023769013148849655149321600477176756984792494737523014031535451796642257264591074089805032775850255181683583489280933827062094695968929992309191084027992634714952603480073592385839884381525790891312523534083599076322266774625647023068305162618175831767276703329594 451825888541307114285023474647614465265916243595833359384659374193847802006511149578110199614974122094461292391969910479315224417347733028343398615115383795805350314684151729592690676893670171930981454652643821008128579426192449010324129338936197739834244254809008041369846532483520265820455733374540610569 418905053650993235544999290413399673851821381788165274802086996743182252911644561212722788230688633543539868707328569856588872829539231763987322776511154975419874009189507815690298068869042349121188079832536889395323642774941410651119155866392921993324290755129870948339417124778429546445731014364980860032 372284385520904615341242285923534549408247232214440019487517294985507330299064329561698150292660142033382626841325765125236567731673967264217521420855032146696695576829593464854160821721523682563776614230197964270676813221304294174093749521990854947347018903107199538080734706771102105143365300635364811487 986829724784663962865158364386643797880901730027221996196767986221992711962656002099463177192624263707602410093575285821338731200874611266863969758097997049402586601578689065736313359525760991065692772040266960530559673892786769991350099987415629493123086877860862768475757963695605772019942177391265976695 423726244765571927306230264755862747294794858738822998057503944455999090365230976597902303853364224902710636944419980870711899774599844070124079632022172752473079564344760475693301347249021270068846374630676616424087609421998838455642079495105434832087780339447922611098743689672239607131792124050018187328 798720344014767226708810188658144953037819005015449351683978824449318784326232704076294724959057079464178619066843821271405611153259440313113021535561611866907262243659123585775346005604901864245557705936836416523556953911289960771382551574745356081918317423467942206330465356121596255218492347008240365333 748525610770551687958335218015486761496841502370238205843920678752561973507330170425738510643073575865043765148203732274108657947471725450740357117613279702700773888079209856517640360838356147299387771605195516797784028779494330931947021705211412468804139274131320259071468087165922946854551611261679021334 750698519319037151293879446436551560006501187790607641079395117741023086147841654844881032599417479199536922412493258196224736025159782569605010188057833919530158790874382622758628854810271199260751284429054588683594492375195928148478295677987083131669432313716998073546113222707666734175097800826183963352 661498083020675194614493771678493883431096591461501237011763163919057985320451253806879146626901333945904230461337392455841895559948673148945346942817856142822567776165386754756154586208221535027278952401221716081192039278116031522004674927738704456771602869914356251162891725860084958808131473719724015829 209180510827859900176089420769517980653096194676333881000170905447427142789804927640617337083605676635055336128556979122011511719983437933572898308127140028994388499757841719462508551135029150412798236301472794966204981587683451306843788553538233196306860169274175539020590830273103469350108030479412085143 492002179936880997691970955955810063265136978313114462012999452997442961600363540715403005966017758974487775437768833666069417446479010755284465888191546438275164743347849408433446004513766271558460789377801324932365065316981448813534049879159394434934971125996366299331223487995360964188332514927759320610 342549850238452735230675048763312434661543300259041977509712934263725204775239928669735923028816657804122165666361782442651707365712939832015904210333920903390861228424611486013754434814310946435915154035191935281127625458307735027397424791141084701998457211950939924372391062708264278252873353800930859993 623361101475733541331976054125945004003765691772290688737542910722608828931226738185725496553963893672961101905937363517429719945946164665848189554170550559846609785439266629503126622385492300778438581233561215802766902274132601368752534399771030287362532274639824206470939573512842421249798011107128045848 691662528462076726833563439816708280823435480371901213348396696286690888494382873656451308760095720781151844834143605341293750908423253917493590797081568929308280763502299930547242247081760333980560298066450278921665336341861427737653099954748572255578835569505362656743637518207284281763566441479616119428 406570619442886083690918366005666817411566276569946567522572365854273490323794732414474792265581889968028308816608148810786135081534252365095194261686940622779631390731943577128045501348474800647243700189530535043883802482774956559766852941747233624970768888025545042100144558631706192558242262320335544155 905145227600481368843770907074242683804472759368024770510577214379935451388454866647897190151141678123754900319304368829996310952215096016108384636873896383465262861207096799581566614535273458181961545654711708696064520134945074195570929135522363614734848734783539727516144291719582970067401185989927586738 200566889116179676108035270807474266038622586161916575224214760749601320539535685776716531474973113571737644030286092499311991520759537370636384731612938399168143690987213844339552275085324479317289979541842956269418255834921743260441643962869308490131462525366179158062025786721577288214460369610800746272 028432458318293984039768296580028828625601806204215666610180476871453558832354493746823007197400006302185631400662163454831249360865954410140900913367797252603405978602290728954833713465024660752955763498072105145211041368741232233079510265082738607735566534416454647328498412864726178537537653301879383723 366543479514959105986484812373984840727563858970736196070512662184896430538552438232518291772787354069306960735774252266734233936452901829994110897042519503740169440051349317504807864122091806140078876504038766204961858039369204944342596643256475989254250732719943796748850198241347376767476599307784061325 686149095118148470690548058423212182692655369499044092020819151214696310203354406375160178448989505844062187683323177647169987863490299828791114715283168370959663404857047930902175050850929554589190460721892833083995595894273612689831997544818352886274742357084421481144242333737384306480980160768411842385 245750881796522957816247397912734161609375257048999794881711355938913818084681060711887049281503355747906227857397228694455144289893783792186588750953482469815585508676698824646120157535220179898312253868077842296740434386775235646740717851634225739126900002735239794290801973286923844395353951860021110450 397826004246043561663868661760893185909104331823711878405159562245904130714725828956809892949130006230996144113160721334761779145492928750856111638644598610178575613749074802654200548856635850710006903073386344224176455207885619577291454613959942571299153868708008061456881163493296753316996079917928486740 366908303440570675621808226248924865806707928593302218965673769160255177402586312198450089036250920226549972028940875514627762002638552249352233229667057871115006212036899577988756549227709303416483226335362927823740001625690288682813479970860145544607516223227022188711229792647859501692766305860527165070 723569675117039333899944503871031907614415677230284260568900103590479521936866396585197843246447164792780525097713711750916396743118016895720173491891418236257586456444103535018743732220026387251690446987899659022398561675721047012825538675096261219188528926850155202294668418278257083256366344524287566125 924816298783994375056212734697753356963204685486460054316384808375373091653038723981374673785773430267680490972221964964008965443598993317424514348858089833562389648331263120606947666635330242436105561591916440596661223890328038826631100759325960430715361462249061171831939419947976111487100166558143689919 504707189288709579360744252689018846140507990205728916474909355522027113832424619504572304106427997491346068255353006739273364613331104103124982265057852311727737006201698361841015361316531830552327439857388516701209719464547898572160521281255042682015603630211247575852424078849563666878867754412791602231 618168381588640390356471480381093191980579235423552390540708102387454459444496884160880197500738822555373186044266021250063724170290152842105961017674395972105115500607899212316885677693732275021936883134619676158788699140026058530355914241251111703902627148059795178566951050668819717822801388898616865748 010031108665175587790160482257077517451890272801676649888942692873652296390812008229691740468145853395481262651757269581335396532363002512235384551430582498329643404745768832715201993702201878822889355256372014144557044629882097128792511593616442579871598524417107778442329530441700735412952982992267578707 523074783138355644475489675228240506685245016014601026946845542854666212691943606480488453900916181078653378207238763997677688072463590564870990724979341468311896135377030642146128952155719257255704567314489128612898192555034345313908476785883916819054506563319145069062856779259788011773078973648234227859 254713877946965871709300557378874029596767652004116417707034146432577450429044410531939229924295769680258009015474504849210148679321636365920592038392628249997076844035390220722761123402032715487085062297338739988261881816736440143872870223957185564986982954104374453092218399194538878304800935802347205042 060103772160674169680229620492702576527972340163609776761500407042896697481698309437428957715619149030999010010141578857685776820055755554911962264639881248353064297372633163473548820168126873919979038576621738249035732685118706916485178822781032938880755125331643155691873659819359509096701020947267541678 302067709279205506972803270409267768684693429871282858321713693449748489564110227518336472944595587225942160605061868956231055475080917937980709616116618762534647187126197093128752418770742105616689214378152006777563236039706547518997133833409406896876727006832736650532806448349038953356280856638654965703 764280688638768890950913530506839318388664265170864540141518077130479336454342600018378244101690370523029255875435195057705957275863422425059058886647515820145818003407117527597224960562926187888783833900258672630090570327078625737172854874592218892202471209754879726599223799511931993217498098542335370537 350671982595166418179106592819047280232120156990010755785567500294688244247555815454268293294808979675178975350846589093798708440683339922733397953059957161591798111728100777014166274666153679533764927361984710439454483663470255292378224760971766231138955776203519417955364299288680635848886170340607384428 275242388777283979016720678612918074723685874057421516643933215092227522152725087857228632485781508042164467240024618769474624440748538067677159857357145878868336574107526748183876369264522263481868556235837783284895027086956892081098910759669112326707631736883384109037397838868350773327800671513531206528 727535813443253240661756851090314416234492762503025339693371774418026289723265120922039026743629170499976353259850284290029420412386380747342760695326862059410444829570060376550212694892482517415874678170191515448633470133770188417523072328880887511720321251674182601148324130547341883777335929141101489449 428274003936330431908761397031998966722715042644212263769543853283884790702824467093492922983486026951732074676353065209114805850944558720577852378771799391313753566034373747977527775251945487952125626526893295358827359452369866790149331640883355979613208407874233332673392565138698194696782311738009712065 024438483068537044738632073530982095405467043080286336677745936810886593935368072146364870672449730867647196247088335029216681562333323717563467961248398509155706925356078079875115605519885914410562087551333958793676218682237918951532440382435070187277970930566157384741325024647368780471175272456649314322 367428157615322324359035775945603683144039278168800538074900762385594340628979743630062639984223127816606034576025221284124010718480556554787836052783435440272251969553867961294127526045217770719875190158177578163583604391536066763937210240974215221749796823137480319906041278196277986522191077736528168024 321662081051949078503152807465778173473896732809469245417120081783221564443886810359589100310695365933710640195003811162839829182248363002124511254822463142754717394388748261644054767687631881277142775826675184724660880906974466094481337568266666095797990510442937695947627136167991289066010445102640310535 537790825540658557341654980082344153326225567276304687095363326242378173729982760472563550551892122423626684109583603238440693825520763801056024687947196540922999629022649236391317056464089316540164129869360503113022545644167623126384513019890402445333206452118792494039415337160792573951102230379946098170 103517530613571516001320848133788341240607693571720514741268705199173770177359308008930375580417885870306434633500227476062932069284858978152644456267526599839282673004057254578536175120073227541214927151030158175964199445320260945815651493816350903904811147582626226341234646383197347943176746216337833937 315408301391025895304772269631533935160729524010578120445489063488610996805726097701739115523057300652161882321377141397789524092957001768607946214825548383923394901034220658165630402547777326845262984294180440033881273009624094072033477204581343259632822396404537215922649479100115135129136409509238080846 022124742734791991357881769411953719029010034483035492034702861981945231018756669440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  40. Is this fact(5000) ? def fact(n, v) if n ==

    1 v else fact(n-1, v * (n-1)) end end p fact(5000, 1) % ruby interp.rb fact.rb 845715585321108704440212840046716881078157334925329349769956480436271610541621640138179809574341277507 416949331460137089175697213336762547267442178754557526255878072611692432128780895797396447974385941779 242322530593664355100079848439367406293814528945757579580809509768324430453343856821938473820899131943 472705896800447680762241289640461715342209004612349789510856619523563448081610649619855618657568110972 398729096582423752516497604378347955800100426425196087278489252921541022717693190217350941171667849310 451178070948871976694766357976069266016917263020418183019871307640021866095931485113483861834110345610 400472150171982395270457511815804086739486247013833662423848991943112534815042924397972466177251996605 719729715157498891926230573941773420092536847296357979810909381722783226436688348297614372468896229662 418980722393093745535511235773657440538209628184912820683671951208552916323026357151803322143565088313 961766718745459991206742742400942098875312582284977210670598999284601399944409836240201638118878281350 106530009551067701798195890203102182973814008814239144672052486736264660437418575398393613313139505580 844516535683122166752851562065258405374422140549362788702257203004652381299918343794728352756872982439 418219681889029790717918207608353883913315669644143498211025505278296762344105209653930325285420189838 786665322060208721060918234029114419169428707443896493373586934751809744536266820415721807314217612753 232499499014826214154803364361171891052890342818554938460125395022692088349135893471657564523259168497 350314758345885448357566210859716490235151023769013148849655149321600477176756984792494737523014031535 451796642257264591074089805032775850255181683583489280933827062094695968929992309191084027992634714952 603480073592385839884381525790891312523534083599076322266774625647023068305162618175831767276703329594 451825888541307114285023474647614465265916243595833359384659374193847802006511149578110199614974122094 461292391969910479315224417347733028343398615115383795805350314684151729592690676893670171930981454652 643821008128579426192449010324129338936197739834244254809008041369846532483520265820455733374540610569 418905053650993235544999290413399673851821381788165274802086996743182252911644561212722788230688633543 539868707328569856588872829539231763987322776511154975419874009189507815690298068869042349121188079832 536889395323642774941410651119155866392921993324290755129870948339417124778429546445731014364980860032 372284385520904615341242285923534549408247232214440019487517294985507330299064329561698150292660142033 382626841325765125236567731673967264217521420855032146696695576829593464854160821721523682563776614230 197964270676813221304294174093749521990854947347018903107199538080734706771102105143365300635364811487 986829724784663962865158364386643797880901730027221996196767986221992711962656002099463177192624263707 602410093575285821338731200874611266863969758097997049402586601578689065736313359525760991065692772040 266960530559673892786769991350099987415629493123086877860862768475757963695605772019942177391265976695 423726244765571927306230264755862747294794858738822998057503944455999090365230976597902303853364224902 710636944419980870711899774599844070124079632022172752473079564344760475693301347249021270068846374630 676616424087609421998838455642079495105434832087780339447922611098743689672239607131792124050018187328 798720344014767226708810188658144953037819005015449351683978824449318784326232704076294724959057079464 178619066843821271405611153259440313113021535561611866907262243659123585775346005604901864245557705936
  41. ࣮ߦͯ͠ΈΔ def fact(n, v) if n == 1 v else

    fact(n-1, v * (n-1)) end end p fact(5000, 1) 178619066843821271405611153259440313113021535561611866907262243659123585775346005604901864245557705936 836416523556953911289960771382551574745356081918317423467942206330465356121596255218492347008240365333 748525610770551687958335218015486761496841502370238205843920678752561973507330170425738510643073575865 043765148203732274108657947471725450740357117613279702700773888079209856517640360838356147299387771605 195516797784028779494330931947021705211412468804139274131320259071468087165922946854551611261679021334 750698519319037151293879446436551560006501187790607641079395117741023086147841654844881032599417479199 536922412493258196224736025159782569605010188057833919530158790874382622758628854810271199260751284429 054588683594492375195928148478295677987083131669432313716998073546113222707666734175097800826183963352 661498083020675194614493771678493883431096591461501237011763163919057985320451253806879146626901333945 904230461337392455841895559948673148945346942817856142822567776165386754756154586208221535027278952401 221716081192039278116031522004674927738704456771602869914356251162891725860084958808131473719724015829 209180510827859900176089420769517980653096194676333881000170905447427142789804927640617337083605676635 055336128556979122011511719983437933572898308127140028994388499757841719462508551135029150412798236301 472794966204981587683451306843788553538233196306860169274175539020590830273103469350108030479412085143 492002179936880997691970955955810063265136978313114462012999452997442961600363540715403005966017758974 487775437768833666069417446479010755284465888191546438275164743347849408433446004513766271558460789377 801324932365065316981448813534049879159394434934971125996366299331223487995360964188332514927759320610 342549850238452735230675048763312434661543300259041977509712934263725204775239928669735923028816657804 122165666361782442651707365712939832015904210333920903390861228424611486013754434814310946435915154035 191935281127625458307735027397424791141084701998457211950939924372391062708264278252873353800930859993 623361101475733541331976054125945004003765691772290688737542910722608828931226738185725496553963893672 961101905937363517429719945946164665848189554170550559846609785439266629503126622385492300778438581233 561215802766902274132601368752534399771030287362532274639824206470939573512842421249798011107128045848 691662528462076726833563439816708280823435480371901213348396696286690888494382873656451308760095720781 151844834143605341293750908423253917493590797081568929308280763502299930547242247081760333980560298066 450278921665336341861427737653099954748572255578835569505362656743637518207284281763566441479616119428 406570619442886083690918366005666817411566276569946567522572365854273490323794732414474792265581889968 028308816608148810786135081534252365095194261686940622779631390731943577128045501348474800647243700189 530535043883802482774956559766852941747233624970768888025545042100144558631706192558242262320335544155 905145227600481368843770907074242683804472759368024770510577214379935451388454866647897190151141678123 754900319304368829996310952215096016108384636873896383465262861207096799581566614535273458181961545654 711708696064520134945074195570929135522363614734848734783539727516144291719582970067401185989927586738 200566889116179676108035270807474266038622586161916575224214760749601320539535685776716531474973113571 737644030286092499311991520759537370636384731612938399168143690987213844339552275085324479317289979541 842956269418255834921743260441643962869308490131462525366179158062025786721577288214460369610800746272 028432458318293984039768296580028828625601806204215666610180476871453558832354493746823007197400006302 185631400662163454831249360865954410140900913367797252603405978602290728954833713465024660752955763498 072105145211041368741232233079510265082738607735566534416454647328498412864726178537537653301879383723 366543479514959105986484812373984840727563858970736196070512662184896430538552438232518291772787354069 306960735774252266734233936452901829994110897042519503740169440051349317504807864122091806140078876504 038766204961858039369204944342596643256475989254250732719943796748850198241347376767476599307784061325 686149095118148470690548058423212182692655369499044092020819151214696310203354406375160178448989505844 062187683323177647169987863490299828791114715283168370959663404857047930902175050850929554589190460721
  42. ࣮ߦͯ͠ΈΔ def fact(n, v) if n == 1 v else

    fact(n-1, v * (n-1)) end end p fact(5000, 1) 062187683323177647169987863490299828791114715283168370959663404857047930902175050850929554589190460721 892833083995595894273612689831997544818352886274742357084421481144242333737384306480980160768411842385 245750881796522957816247397912734161609375257048999794881711355938913818084681060711887049281503355747 906227857397228694455144289893783792186588750953482469815585508676698824646120157535220179898312253868 077842296740434386775235646740717851634225739126900002735239794290801973286923844395353951860021110450 397826004246043561663868661760893185909104331823711878405159562245904130714725828956809892949130006230 996144113160721334761779145492928750856111638644598610178575613749074802654200548856635850710006903073 386344224176455207885619577291454613959942571299153868708008061456881163493296753316996079917928486740 366908303440570675621808226248924865806707928593302218965673769160255177402586312198450089036250920226 549972028940875514627762002638552249352233229667057871115006212036899577988756549227709303416483226335 362927823740001625690288682813479970860145544607516223227022188711229792647859501692766305860527165070 723569675117039333899944503871031907614415677230284260568900103590479521936866396585197843246447164792 780525097713711750916396743118016895720173491891418236257586456444103535018743732220026387251690446987 899659022398561675721047012825538675096261219188528926850155202294668418278257083256366344524287566125 924816298783994375056212734697753356963204685486460054316384808375373091653038723981374673785773430267 680490972221964964008965443598993317424514348858089833562389648331263120606947666635330242436105561591 916440596661223890328038826631100759325960430715361462249061171831939419947976111487100166558143689919 504707189288709579360744252689018846140507990205728916474909355522027113832424619504572304106427997491 346068255353006739273364613331104103124982265057852311727737006201698361841015361316531830552327439857 388516701209719464547898572160521281255042682015603630211247575852424078849563666878867754412791602231 618168381588640390356471480381093191980579235423552390540708102387454459444496884160880197500738822555 373186044266021250063724170290152842105961017674395972105115500607899212316885677693732275021936883134 619676158788699140026058530355914241251111703902627148059795178566951050668819717822801388898616865748 010031108665175587790160482257077517451890272801676649888942692873652296390812008229691740468145853395 481262651757269581335396532363002512235384551430582498329643404745768832715201993702201878822889355256 372014144557044629882097128792511593616442579871598524417107778442329530441700735412952982992267578707 523074783138355644475489675228240506685245016014601026946845542854666212691943606480488453900916181078 653378207238763997677688072463590564870990724979341468311896135377030642146128952155719257255704567314 489128612898192555034345313908476785883916819054506563319145069062856779259788011773078973648234227859 254713877946965871709300557378874029596767652004116417707034146432577450429044410531939229924295769680 258009015474504849210148679321636365920592038392628249997076844035390220722761123402032715487085062297 338739988261881816736440143872870223957185564986982954104374453092218399194538878304800935802347205042 060103772160674169680229620492702576527972340163609776761500407042896697481698309437428957715619149030 999010010141578857685776820055755554911962264639881248353064297372633163473548820168126873919979038576 621738249035732685118706916485178822781032938880755125331643155691873659819359509096701020947267541678 302067709279205506972803270409267768684693429871282858321713693449748489564110227518336472944595587225 942160605061868956231055475080917937980709616116618762534647187126197093128752418770742105616689214378 152006777563236039706547518997133833409406896876727006832736650532806448349038953356280856638654965703 764280688638768890950913530506839318388664265170864540141518077130479336454342600018378244101690370523 029255875435195057705957275863422425059058886647515820145818003407117527597224960562926187888783833900 258672630090570327078625737172854874592218892202471209754879726599223799511931993217498098542335370537 350671982595166418179106592819047280232120156990010755785567500294688244247555815454268293294808979675 178975350846589093798708440683339922733397953059957161591798111728100777014166274666153679533764927361
  43. ࣮ߦͯ͠ΈΔ def fact(n, v) if n == 1 v else

    fact(n-1, v * (n-1)) end end p fact(5000, 1) 984710439454483663470255292378224760971766231138955776203519417955364299288680635848886170340607384428 275242388777283979016720678612918074723685874057421516643933215092227522152725087857228632485781508042 164467240024618769474624440748538067677159857357145878868336574107526748183876369264522263481868556235 837783284895027086956892081098910759669112326707631736883384109037397838868350773327800671513531206528 727535813443253240661756851090314416234492762503025339693371774418026289723265120922039026743629170499 976353259850284290029420412386380747342760695326862059410444829570060376550212694892482517415874678170 191515448633470133770188417523072328880887511720321251674182601148324130547341883777335929141101489449 428274003936330431908761397031998966722715042644212263769543853283884790702824467093492922983486026951 732074676353065209114805850944558720577852378771799391313753566034373747977527775251945487952125626526 893295358827359452369866790149331640883355979613208407874233332673392565138698194696782311738009712065 024438483068537044738632073530982095405467043080286336677745936810886593935368072146364870672449730867 647196247088335029216681562333323717563467961248398509155706925356078079875115605519885914410562087551 333958793676218682237918951532440382435070187277970930566157384741325024647368780471175272456649314322 367428157615322324359035775945603683144039278168800538074900762385594340628979743630062639984223127816 606034576025221284124010718480556554787836052783435440272251969553867961294127526045217770719875190158 177578163583604391536066763937210240974215221749796823137480319906041278196277986522191077736528168024 321662081051949078503152807465778173473896732809469245417120081783221564443886810359589100310695365933 710640195003811162839829182248363002124511254822463142754717394388748261644054767687631881277142775826 675184724660880906974466094481337568266666095797990510442937695947627136167991289066010445102640310535 537790825540658557341654980082344153326225567276304687095363326242378173729982760472563550551892122423 626684109583603238440693825520763801056024687947196540922999629022649236391317056464089316540164129869 360503113022545644167623126384513019890402445333206452118792494039415337160792573951102230379946098170 103517530613571516001320848133788341240607693571720514741268705199173770177359308008930375580417885870 306434633500227476062932069284858978152644456267526599839282673004057254578536175120073227541214927151 030158175964199445320260945815651493816350903904811147582626226341234646383197347943176746216337833937 315408301391025895304772269631533935160729524010578120445489063488610996805726097701739115523057300652 161882321377141397789524092957001768607946214825548383923394901034220658165630402547777326845262984294 180440033881273009624094072033477204581343259632822396404537215922649479100115135129136409509238080846 022124742734791991357881769411953719029010034483035492034702861981945231018756669440000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00
  44. bootstrap def fact(n, v) if n == 1 v else

    fact(n-1, v * (n-1)) end end p fact(5000, 1) % ruby interp.rb interp.rb fact.rb 845715585321108704440212840046716881078157334925329349769956480436271610541621640138179809574341277507416949331460137089175697213336762547267442178754557526255878072611692432128780895797396447974385941779242322530593664355100079848439367406293814528945757579580809509768324430453343856821938473820899131943 472705896800447680762241289640461715342209004612349789510856619523563448081610649619855618657568110972398729096582423752516497604378347955800100426425196087278489252921541022717693190217350941171667849310451178070948871976694766357976069266016917263020418183019871307640021866095931485113483861834110345610 400472150171982395270457511815804086739486247013833662423848991943112534815042924397972466177251996605719729715157498891926230573941773420092536847296357979810909381722783226436688348297614372468896229662418980722393093745535511235773657440538209628184912820683671951208552916323026357151803322143565088313 961766718745459991206742742400942098875312582284977210670598999284601399944409836240201638118878281350106530009551067701798195890203102182973814008814239144672052486736264660437418575398393613313139505580844516535683122166752851562065258405374422140549362788702257203004652381299918343794728352756872982439 418219681889029790717918207608353883913315669644143498211025505278296762344105209653930325285420189838786665322060208721060918234029114419169428707443896493373586934751809744536266820415721807314217612753232499499014826214154803364361171891052890342818554938460125395022692088349135893471657564523259168497 350314758345885448357566210859716490235151023769013148849655149321600477176756984792494737523014031535451796642257264591074089805032775850255181683583489280933827062094695968929992309191084027992634714952603480073592385839884381525790891312523534083599076322266774625647023068305162618175831767276703329594 451825888541307114285023474647614465265916243595833359384659374193847802006511149578110199614974122094461292391969910479315224417347733028343398615115383795805350314684151729592690676893670171930981454652643821008128579426192449010324129338936197739834244254809008041369846532483520265820455733374540610569 418905053650993235544999290413399673851821381788165274802086996743182252911644561212722788230688633543539868707328569856588872829539231763987322776511154975419874009189507815690298068869042349121188079832536889395323642774941410651119155866392921993324290755129870948339417124778429546445731014364980860032 372284385520904615341242285923534549408247232214440019487517294985507330299064329561698150292660142033382626841325765125236567731673967264217521420855032146696695576829593464854160821721523682563776614230197964270676813221304294174093749521990854947347018903107199538080734706771102105143365300635364811487 986829724784663962865158364386643797880901730027221996196767986221992711962656002099463177192624263707602410093575285821338731200874611266863969758097997049402586601578689065736313359525760991065692772040266960530559673892786769991350099987415629493123086877860862768475757963695605772019942177391265976695 423726244765571927306230264755862747294794858738822998057503944455999090365230976597902303853364224902710636944419980870711899774599844070124079632022172752473079564344760475693301347249021270068846374630676616424087609421998838455642079495105434832087780339447922611098743689672239607131792124050018187328 798720344014767226708810188658144953037819005015449351683978824449318784326232704076294724959057079464178619066843821271405611153259440313113021535561611866907262243659123585775346005604901864245557705936836416523556953911289960771382551574745356081918317423467942206330465356121596255218492347008240365333 748525610770551687958335218015486761496841502370238205843920678752561973507330170425738510643073575865043765148203732274108657947471725450740357117613279702700773888079209856517640360838356147299387771605195516797784028779494330931947021705211412468804139274131320259071468087165922946854551611261679021334 750698519319037151293879446436551560006501187790607641079395117741023086147841654844881032599417479199536922412493258196224736025159782569605010188057833919530158790874382622758628854810271199260751284429054588683594492375195928148478295677987083131669432313716998073546113222707666734175097800826183963352 661498083020675194614493771678493883431096591461501237011763163919057985320451253806879146626901333945904230461337392455841895559948673148945346942817856142822567776165386754756154586208221535027278952401221716081192039278116031522004674927738704456771602869914356251162891725860084958808131473719724015829 209180510827859900176089420769517980653096194676333881000170905447427142789804927640617337083605676635055336128556979122011511719983437933572898308127140028994388499757841719462508551135029150412798236301472794966204981587683451306843788553538233196306860169274175539020590830273103469350108030479412085143 492002179936880997691970955955810063265136978313114462012999452997442961600363540715403005966017758974487775437768833666069417446479010755284465888191546438275164743347849408433446004513766271558460789377801324932365065316981448813534049879159394434934971125996366299331223487995360964188332514927759320610 342549850238452735230675048763312434661543300259041977509712934263725204775239928669735923028816657804122165666361782442651707365712939832015904210333920903390861228424611486013754434814310946435915154035191935281127625458307735027397424791141084701998457211950939924372391062708264278252873353800930859993 623361101475733541331976054125945004003765691772290688737542910722608828931226738185725496553963893672961101905937363517429719945946164665848189554170550559846609785439266629503126622385492300778438581233561215802766902274132601368752534399771030287362532274639824206470939573512842421249798011107128045848 691662528462076726833563439816708280823435480371901213348396696286690888494382873656451308760095720781151844834143605341293750908423253917493590797081568929308280763502299930547242247081760333980560298066450278921665336341861427737653099954748572255578835569505362656743637518207284281763566441479616119428 406570619442886083690918366005666817411566276569946567522572365854273490323794732414474792265581889968028308816608148810786135081534252365095194261686940622779631390731943577128045501348474800647243700189530535043883802482774956559766852941747233624970768888025545042100144558631706192558242262320335544155 905145227600481368843770907074242683804472759368024770510577214379935451388454866647897190151141678123754900319304368829996310952215096016108384636873896383465262861207096799581566614535273458181961545654711708696064520134945074195570929135522363614734848734783539727516144291719582970067401185989927586738 200566889116179676108035270807474266038622586161916575224214760749601320539535685776716531474973113571737644030286092499311991520759537370636384731612938399168143690987213844339552275085324479317289979541842956269418255834921743260441643962869308490131462525366179158062025786721577288214460369610800746272 028432458318293984039768296580028828625601806204215666610180476871453558832354493746823007197400006302185631400662163454831249360865954410140900913367797252603405978602290728954833713465024660752955763498072105145211041368741232233079510265082738607735566534416454647328498412864726178537537653301879383723 366543479514959105986484812373984840727563858970736196070512662184896430538552438232518291772787354069306960735774252266734233936452901829994110897042519503740169440051349317504807864122091806140078876504038766204961858039369204944342596643256475989254250732719943796748850198241347376767476599307784061325 686149095118148470690548058423212182692655369499044092020819151214696310203354406375160178448989505844062187683323177647169987863490299828791114715283168370959663404857047930902175050850929554589190460721892833083995595894273612689831997544818352886274742357084421481144242333737384306480980160768411842385 245750881796522957816247397912734161609375257048999794881711355938913818084681060711887049281503355747906227857397228694455144289893783792186588750953482469815585508676698824646120157535220179898312253868077842296740434386775235646740717851634225739126900002735239794290801973286923844395353951860021110450 397826004246043561663868661760893185909104331823711878405159562245904130714725828956809892949130006230996144113160721334761779145492928750856111638644598610178575613749074802654200548856635850710006903073386344224176455207885619577291454613959942571299153868708008061456881163493296753316996079917928486740 366908303440570675621808226248924865806707928593302218965673769160255177402586312198450089036250920226549972028940875514627762002638552249352233229667057871115006212036899577988756549227709303416483226335362927823740001625690288682813479970860145544607516223227022188711229792647859501692766305860527165070 723569675117039333899944503871031907614415677230284260568900103590479521936866396585197843246447164792780525097713711750916396743118016895720173491891418236257586456444103535018743732220026387251690446987899659022398561675721047012825538675096261219188528926850155202294668418278257083256366344524287566125 924816298783994375056212734697753356963204685486460054316384808375373091653038723981374673785773430267680490972221964964008965443598993317424514348858089833562389648331263120606947666635330242436105561591916440596661223890328038826631100759325960430715361462249061171831939419947976111487100166558143689919 504707189288709579360744252689018846140507990205728916474909355522027113832424619504572304106427997491346068255353006739273364613331104103124982265057852311727737006201698361841015361316531830552327439857388516701209719464547898572160521281255042682015603630211247575852424078849563666878867754412791602231 618168381588640390356471480381093191980579235423552390540708102387454459444496884160880197500738822555373186044266021250063724170290152842105961017674395972105115500607899212316885677693732275021936883134619676158788699140026058530355914241251111703902627148059795178566951050668819717822801388898616865748 010031108665175587790160482257077517451890272801676649888942692873652296390812008229691740468145853395481262651757269581335396532363002512235384551430582498329643404745768832715201993702201878822889355256372014144557044629882097128792511593616442579871598524417107778442329530441700735412952982992267578707 523074783138355644475489675228240506685245016014601026946845542854666212691943606480488453900916181078653378207238763997677688072463590564870990724979341468311896135377030642146128952155719257255704567314489128612898192555034345313908476785883916819054506563319145069062856779259788011773078973648234227859 254713877946965871709300557378874029596767652004116417707034146432577450429044410531939229924295769680258009015474504849210148679321636365920592038392628249997076844035390220722761123402032715487085062297338739988261881816736440143872870223957185564986982954104374453092218399194538878304800935802347205042 060103772160674169680229620492702576527972340163609776761500407042896697481698309437428957715619149030999010010141578857685776820055755554911962264639881248353064297372633163473548820168126873919979038576621738249035732685118706916485178822781032938880755125331643155691873659819359509096701020947267541678 302067709279205506972803270409267768684693429871282858321713693449748489564110227518336472944595587225942160605061868956231055475080917937980709616116618762534647187126197093128752418770742105616689214378152006777563236039706547518997133833409406896876727006832736650532806448349038953356280856638654965703 764280688638768890950913530506839318388664265170864540141518077130479336454342600018378244101690370523029255875435195057705957275863422425059058886647515820145818003407117527597224960562926187888783833900258672630090570327078625737172854874592218892202471209754879726599223799511931993217498098542335370537 350671982595166418179106592819047280232120156990010755785567500294688244247555815454268293294808979675178975350846589093798708440683339922733397953059957161591798111728100777014166274666153679533764927361984710439454483663470255292378224760971766231138955776203519417955364299288680635848886170340607384428 275242388777283979016720678612918074723685874057421516643933215092227522152725087857228632485781508042164467240024618769474624440748538067677159857357145878868336574107526748183876369264522263481868556235837783284895027086956892081098910759669112326707631736883384109037397838868350773327800671513531206528 727535813443253240661756851090314416234492762503025339693371774418026289723265120922039026743629170499976353259850284290029420412386380747342760695326862059410444829570060376550212694892482517415874678170191515448633470133770188417523072328880887511720321251674182601148324130547341883777335929141101489449 428274003936330431908761397031998966722715042644212263769543853283884790702824467093492922983486026951732074676353065209114805850944558720577852378771799391313753566034373747977527775251945487952125626526893295358827359452369866790149331640883355979613208407874233332673392565138698194696782311738009712065 024438483068537044738632073530982095405467043080286336677745936810886593935368072146364870672449730867647196247088335029216681562333323717563467961248398509155706925356078079875115605519885914410562087551333958793676218682237918951532440382435070187277970930566157384741325024647368780471175272456649314322 367428157615322324359035775945603683144039278168800538074900762385594340628979743630062639984223127816606034576025221284124010718480556554787836052783435440272251969553867961294127526045217770719875190158177578163583604391536066763937210240974215221749796823137480319906041278196277986522191077736528168024 321662081051949078503152807465778173473896732809469245417120081783221564443886810359589100310695365933710640195003811162839829182248363002124511254822463142754717394388748261644054767687631881277142775826675184724660880906974466094481337568266666095797990510442937695947627136167991289066010445102640310535 537790825540658557341654980082344153326225567276304687095363326242378173729982760472563550551892122423626684109583603238440693825520763801056024687947196540922999629022649236391317056464089316540164129869360503113022545644167623126384513019890402445333206452118792494039415337160792573951102230379946098170 103517530613571516001320848133788341240607693571720514741268705199173770177359308008930375580417885870306434633500227476062932069284858978152644456267526599839282673004057254578536175120073227541214927151030158175964199445320260945815651493816350903904811147582626226341234646383197347943176746216337833937 315408301391025895304772269631533935160729524010578120445489063488610996805726097701739115523057300652161882321377141397789524092957001768607946214825548383923394901034220658165630402547777326845262984294180440033881273009624094072033477204581343259632822396404537215922649479100115135129136409509238080846 022124742734791991357881769411953719029010034483035492034702861981945231018756669440000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
  45. ⭐⭐⭐ MinRuby's context is plain Ruby objects genv, lenv, tree

    Marshalable Process Migration... Agent Ruby, Persistent Ruby... Linda eval... ࠷ޙͷ࿩୊ʂ.JO3VCZͷίϯςΩετ͸;ͭ͏ͷ3VCZΦϒδΣΫτ ͰγϦΞϥΠζՄೳͰ͢ɻͱ͍͏͜ͱ͸ϓϩηεͷҠૹ΍ΤʔδΣϯ τ΍ӬଓԽͰ͖ͦ͏ɻ͡Ό͋-JOEBFWBM࡞ΕΔΜ͡Όͳ͍͔ͳʔ
  46. Linda operations out, in, rd write, take, read (in Rinda)

    eval not implemented (in Rinda) -JOEBͷͭͷૢ࡞ͱ͸ɺPVU  JO  SE  FWBMͰ͢ɻ࠷ॳͷࡾͭ͸3JOEB Ͱ΋࣮૷͞Ε͍ͯͯ·͢ɻૢ࡞ͷ໊લ͸Θ͔Γ΍͘͢มߋ͠·ͨ͠ɻ ೉͍͠ͷ͸FWBMͰ͢ɻ͜Ε͸Ͳ͏ʹ΋࣮૷Ͱ͖·ͤΜͰͨ͠ɻʢͪͳ ΈʹSJOEB@FWBMͱ͍͏αϒηοτ͸͋Γ·͢ɻʣ
  47. Linda eval eval() creates processes for each argument collect the

    results and write a tuple Ҿ਺ͷܭࢉͷͨΊʹ৽͍͠ϓϩηε͕ੜ੒͞Ε·͢ɻͭ·Γ৽͍͠ ϓϩηεͰҾ਺Λܭࢉ͢Δͱ͍͏͜ͱͰ͢ɻFWBMΛݺͿଆͰҾ਺Λ ධՁͯ͠͸͍͚·ͤΜɻશͯͷ݁ՌΛूΊͯɺλϓϧΛҰͭॻ͖·͢ɻ ͜ͷλϓϧΛ଴ͭ͜ͱͰϓϩηεͷऴྃΛ଴ͭ͜ͱ͕Ͱ͖·͢ɻ eval("nq", # fork { "nq" } size, # fork { size } n - 1, # fork { n - 1 } nq(size, n - 1)) # fork { nq(size, n - 1)} # fork { wait all process; # then put a tuple # write("nq", size, n - 1, nq(size, n - 1)) }
  48. rinda_eval rinda_eval is subset of eval block and fork SJOEB@FWBM͸αϒηοτͷFWBMͰ͢ɻҾ਺ΛධՁ͠ͳ͍Ͱϝιο

    υΛݺͿͷ͸೉͍͠ͷͰɺϒϩοΫҾ਺Ͱදݱ͠·ͨ͠ɻͰ ΋ݩʑͷFWBMͷݟͨ໨ͱ͸૬౰ҧ͏΋ͷʹͳͬͯ͠·͍·͢ɻ ·ͨੜ੒͢Δϓϩηε΋Ұ౓ʹҰ͚ͭͩʹ੍ݶ͞Ε·͢ɻ Rinda::rinda_eval(ts) do |place| _, _, prev = place.read(['fact', x - 1, nil]) ['fact', x, prev * x] end
  49. Linda eval / Process migration ⭐⭐⭐ "func_call" without evaluating parameters

    (lazy evaluation??) hard to implement in Ruby because of special behavior Process Migration Dump the context, transfer, and load it. -JOEB FWBMΛ࣮૷͢ΔͨΊʹೋͭͷ໰୊͕͋Γ·͢ɻҾ਺ΛධՁ͠ ͳ͍ಛผͳGVOD@DBMM͕ඞཁɻͰ΋͜͏͍͏ৼΔ෣͍Λ3VCZͰ࡞Δ ͷ͸ࠔ೉ͳΜͰ͢Αɻ͋ͱ͸ϓϩηεͷҠૹɻ͜Ε͸ίϯςΩετΛ γϦΞϥΠζͯ͠సૹͯ͠ಡΈ௚͢ͷ͕Ͱ͖Ε͹͍͍ɻ
  50. add "quote_builtin" Ҿ਺ΛධՁͤͣ"45Λͦͷ··ूΊ·͢ɻ͋ͱͰධՁ͢Δͱ ͖ͷͨΊʹHFOW MFOWͱҰॹʹͯؔ͠਺Λݺͼग़͠·͢ɻ when "func_call" mhd = genv[tree[1]]

    if mhd[0] == "builtin" args = [] i = 0 while tree[i + 2] args[i] = evaluate(tree[i + 2], genv, lenv) i = i + 1 end minruby_call(mhd[1], args) elsif mhd[0] == "quote_builtin" args = [] i = 0 while tree[i + 2] args[i] = tree[i + 2] i = i + 1 end minruby_call(mhd[1], [genv, lenv, args]) else ...
  51. add "quote_builtin" HFOWʹ͸RVPUF@CVJMUJOͱͯؔ͠਺Λొ࿥͠·͢ genv = { "p" => ["builtin", "p"],

    "require" => ["builtin", "require"], "minruby_parse" => ["builtin", "minruby_parse"], "minruby_load" => ["builtin", "minruby_load"], "minruby_call" => ["builtin", "minruby_call"], "ts_load" => ["builtin", "ts_load"], "ts_result" => ["builtin", "ts_load"], "eval" => ["quote_builtin", "ts_eval"], "ts_do_eval" => ["builtin", "ts_do_eval"], "read" => ["builtin", "ts_read"], "take" => ["builtin", "ts_take"], "write" => ["builtin", "ts_write"] }
  52. my_place.rb require 'drb/drb' require 'rinda/tuplespace' def spawn_worker system("ruby -I. rinda_interp.rb

    &") end ts = Rinda::TupleSpace.new DRb.start_service('drbunix:/tmp/my_ts', ts) Thread.new do while true it = ts.take([:ts_eval, nil, nil, nil, nil]) it[0] = :ts_call ts.write(it) spawn_worker end end ts.take([:quit]) NZ@QMBDFSC͸5VQMF4QBDFαʔόʔͰ͢ɻUT@FWBMͰ࢝·Δλϓϧ Λ଴ͪଓ͚ɺ৽͍͠ϓϩηεΛੜ੒͠·͢ɻϓϩηεʹͯ͠΄͍͜͠ ͱΛ఻͑ΔͨΊʹɺUT@DBMMͷλϓϧΛॻ͖·͢ɻ
  53. rinda_interp.rb context = ts_load() if context value = evaluate(context[3], context[1],

    context[2]) ts_result(context[0], value) else str = minruby_load() tree = minruby_parse(str) genv = { ... } lenv = {} evaluate(tree, genv, lenv) end ΠϯλϓϦλ͸εΫϦϓτΛҾ਺Ͱ༩͑Δ௨ৗͷىಈํ๏ͷ ΄͔ʹɺλϓϧΛಡΜͰFWBMVBUF͢Δىಈํ๏Λ௥Ճ͠·͢ɻ
  54. my_rinda.rb UT@FWBM ͸RVPUF@CVJMUJOͷؔ਺Ͱ͢ɻ $ts = DRbObject.new_with_uri('drbunix:/tmp/my_ts') ... def ts_eval(genv, lenv,

    tree) new_tree = ["func_call", "ts_do_eval", ["lit", [genv, lenv, tree]]] $ts.write([:ts_eval, nil, genv, lenv, new_tree]) end def ts_load() if ARGV.size == 0 _, req, genv, lenv, tree = $ts.take([:ts_call, nil, nil, nil, nil]) [req, genv, lenv, tree] else nil end end def ts_result(req, value) if req $ts.write([:ts_done, req, value]) end end
  55. my_rinda.rb UT@MPBE ͸UT@DBMMͷλϓϧʹೖ͍ͬͯΔ.JO3VCZͷίϯςΩ ετͰ͋ΔHFOW  MFOWɺUSFFͱͦͷϦΫΤετͷࣝผࢠΛऔ Γग़͠·͢ɻࣝผࢠ͸FWBMVBUF ͷ݁ՌΛฦ͢ͷʹUT@SFTVMU Ͱ࢖༻͠·͢ɻ $ts

    = DRbObject.new_with_uri('drbunix:/tmp/my_ts') ... def ts_load() if ARGV.size == 0 _, req, genv, lenv, tree = $ts.take([:ts_call, nil, nil, nil, nil]) [req, genv, lenv, tree] else nil end end def ts_result(req, value) if req $ts.write([:ts_done, req, value]) end end
  56. simple server FWBMΛ࢖༻ͨ͠αʔόʔ͸͜Μͳ෩ʹॻ͖·͢ɻ def server() while true req = read("Q",

    nil, nil) value = do_it(req[2]) write("A", req[1], value) end end eval("s", server()) take("s", nil)
  57. fact.rb FWBMΛ࢖ͬͨGBDU write("fact", 1, 1) n = 2 while n

    <= 10 eval("fact", n, take("fact", n - 1, nil)[2] * n) n = n + 1 end p take("fact", 10, nil)
  58. Summary I enjoyed the extending of MinRuby I want to

    make Agent system Ruby makes me feel great .JO3VCZΛ֦ுָͯ͠͠Έ·ͨ͠ɻ"HFOU TZTUFN·Ͱ࡞Γ ͍ͨʢ3VCZ,BJHJʹ͸ؒʹ߹͍·ͤΜͰͨ͠ʣɻ 3VCZΛΩϝΔͱؾ͍͍࣋ͪ