Does Ruby perform Tail Call Optimization?

后端 未结 5 1124
-上瘾入骨i
-上瘾入骨i 2020-11-28 22:18

Functional languages lead to use of recursion to solve a lot of problems, and therefore many of them perform Tail Call Optimization (TCO). TCO causes calls to a function fro

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 22:44

    TCO can also be compiled in by tweaking a couple variables in vm_opts.h before compiling: https://github.com/ruby/ruby/blob/trunk/vm_opts.h#L21

    // vm_opts.h
    #define OPT_TRACE_INSTRUCTION        0    // default 1
    #define OPT_TAILCALL_OPTIMIZATION    1    // default 0
    

提交回复
热议问题