{"id":14624,"date":"2016-05-24T11:07:10","date_gmt":"2016-05-24T15:07:10","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=14624"},"modified":"2016-05-24T11:07:10","modified_gmt":"2016-05-24T15:07:10","slug":"recursive-tail-calls-and-trampolines-in-swift","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/05\/24\/recursive-tail-calls-and-trampolines-in-swift\/","title":{"rendered":"Recursive Tail Calls and Trampolines in Swift"},"content":{"rendered":"<p><a href=\"https:\/\/www.uraimo.com\/2016\/05\/05\/recursive-tail-calls-and-trampolines-in-swift\/\">Umberto Raimondi<\/a> (via <a href=\"https:\/\/twitter.com\/NatashaTheRobot\/status\/728976729713283072\">Natasha Murashev<\/a>):<\/p>\n<blockquote cite=\"https:\/\/www.uraimo.com\/2016\/05\/05\/recursive-tail-calls-and-trampolines-in-swift\/\"><p>In this post we&rsquo;ll see how the lack of predictable tail call elimination in Swift could be overcome using trampolines and a few alternatives to recursion will be described.<\/p>\n<p>[&#8230;]<\/p>\n<p>A trampoline is not much more than a loop that executes iteratively functions that can either return the next function in the sequence (in form of a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Thunk\">thunk<\/a> or continuation, a data structure that contains the information needed to perform a specific function call) or another kind of value (in this case the content of the accumulator) to signal the end of the iteration.<\/p>\n<p>[&#8230;]<\/p>\n<p>And even if this implementation [is] slower than the original one for all the code needed to operate the trampoline that was added, this version solves our biggest issue related to stack exhaustion[&#8230;]<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Umberto Raimondi (via Natasha Murashev): In this post we&rsquo;ll see how the lack of predictable tail call elimination in Swift could be overcome using trampolines and a few alternatives to recursion will be described. [&#8230;] A trampoline is not much more than a loop that executes iteratively functions that can either return the next function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[71,901],"class_list":["post-14624","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-programming","tag-swift-programming-language"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14624","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=14624"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14624\/revisions"}],"predecessor-version":[{"id":14625,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/14624\/revisions\/14625"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=14624"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=14624"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=14624"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}