{"id":34821097,"url":"https://github.com/tompng/no_sltd","last_synced_at":"2025-12-25T14:31:15.096Z","repository":{"id":56885751,"uuid":"84102185","full_name":"tompng/no_sltd","owner":"tompng","description":"Simple way to avoid stack level too deep","archived":false,"fork":false,"pushed_at":"2017-03-07T19:08:13.000Z","size":25,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-11T02:04:25.767Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tompng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-06T17:36:37.000Z","updated_at":"2025-06-01T10:55:40.000Z","dependencies_parsed_at":"2022-08-21T00:20:46.537Z","dependency_job_id":null,"html_url":"https://github.com/tompng/no_sltd","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tompng/no_sltd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompng%2Fno_sltd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompng%2Fno_sltd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompng%2Fno_sltd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompng%2Fno_sltd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tompng","download_url":"https://codeload.github.com/tompng/no_sltd/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompng%2Fno_sltd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28031181,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-25T02:00:05.988Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby"],"created_at":"2025-12-25T14:31:15.018Z","updated_at":"2025-12-25T14:31:15.088Z","avatar_url":"https://github.com/tompng.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# No Stack Level Too Deep\n\n[![Build Status](https://travis-ci.org/tompng/no_sltd.svg?branch=master)](https://travis-ci.org/tompng/no_sltd)\n\nSimple way to avoid `stack level too deep`\n\n## Installation\n\n```ruby\n# Gemfile\ngem 'no_sltd'\n```\n\n```sh\n$ gem install no_sltd\n```\n\n## Usage\n\n```ruby\ndef my_recursive_func\n  ...\nend\n\n# ↓ just add `no_sltd` before `def`\n\nrequire 'no_sltd'\nno_sltd def my_recursive_func\n  ...\nend\n```\n\nor\n\n```ruby\ndef my_recursive_func\n  ...\n  my_recursive_func\n  ...\nend\n\n# ↓ wrap the recursive function call with `no_sltd { }`\n\nrequire 'no_sltd'\ndef my_recursive_func\n  ...\n  no_sltd { my_recursive_func }\n  ...\nend\n```\n\n### examples\n\n```ruby\ndef sum_up n\n  return 1 if n == 1\n  sum_up(n-1) + n\nend\nsum_up 100000 #=\u003e stack level too deep\n\n# ↓↓↓↓\n\nno_sltd def sum_up n\n  return 1 if n == 1\n  sum_up(n-1) + n\nend\nsum_up 100000 #=\u003e 5000050000\n```\n\n```ruby\ndef fibonacci a, memo={0 =\u003e 0, 1 =\u003e 1}\n  return memo[a] if memo[a]\n  memo[a] = fibonacci(a-1, memo) + fibonacci(a-2, memo)\nend\nfibonacci 100000 #=\u003e stack level too deep\n\n# ↓↓↓↓\n\nno_sltd def fibonacci a, memo={0 =\u003e 0, 1 =\u003e 1}\n  return memo[a] if memo[a]\n  memo[a] = fibonacci(a-1, memo) + fibonacci(a-2, memo)\nend\nfibonacci 100000 #=\u003e 2597406934722172......\n```\n\n```ruby\nfact = lambda do |n|\n  n.zero? ? 1 : n * fact.call(n-1)\nend\nfact.call 10000 #=\u003e stack level too deep\n\n# pass the proc to `no_sltd`\nfact = no_sltd -\u003e(n) {\n  n.zero? ? 1 : n * fact.call(n-1)\n}\nfact.call 10000 #=\u003e 2846259680917054......\n\n# or wrap the recursive call with `no_sltd { }`\nfact = lambda do |n|\n  n.zero? ? 1 : n * no_sltd { fact.call(n-1) }\nend\nfact.call 10000 #=\u003e 2846259680917054......\n```\n\n### Pros\n- simple \u0026 easy\n\n### Cons\n- memory eater\n- slow\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompng%2Fno_sltd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftompng%2Fno_sltd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompng%2Fno_sltd/lists"}