Ruby中递归层数好像有限制,如函数
def test(a)
if a==1
1
else
a*test(a-1)
end
end
puts test(780)
输出:84972392897964072098249533940415832032901226147549483885937628906393387016759749166779390912108512193770727396731176148684817099219862241070518329897737419790700834153338358789804054247254662503406001643932256413944181262536626134781963753899870200241216683120301369375204827350328695627459108294334206019027913654171970749305552969884823232609436511764040695691647958710090181422374514248844937618454949350242415512115167050621676322866110695044767187626021475743251277035950696737988473189355598223688184822894258942937354547600827689072340880783574157611601536909313655637665907495308227315772813753604514703047972667545052382993341295609886125445821680344472136291787954204104578202488733326674486963013530280156726975853827440416172311405531398732685573114934257635906047009853269995109193159402626590282423997495520628272375213203911332399362264123774789131108251376802391556145557618075940012872003438523613025838162437433166091728438034202592564763334170361422871174553523479072202135150477947497462319792004248488747067669226929977889728474667753117513554197181549148693463434107347395476738175071015937790196691810903035212156632705787120639270121315037723516623976522946189161132382463371686857543746042274574224547052957738646625809966919808812294116127379399188579075359032740380579901160073141745025441935558361164158736914927029701136227557285045299271693750581590882877670856450852068994081414494717924806473008367067880435766156267541200120373117672789242005510204657433232442062443350842731528466220850546079536126591907570634996939687881634634077903962785409702209303560414980140946811644475359177263347973998479963954822343870777236845722878913093643097703061981548194975005332841862304172509388532508262400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
而
puts test(781)
输出:
E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `*': stack level too deep (SystemStackError)
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
... 727 levels...
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:5:in `test'
from E:/eclipse-SDK-3.2M6-win32/workspace/testruby/Test5.rb:9
posted on 2006-04-07 13:06 黄金时代已过 阅读(950) 评论(1) 编辑 收藏 所属分类: Ruby