Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive function in local context #23

Open
epatrizio opened this issue Jul 13, 2024 · 0 comments
Open

Recursive function in local context #23

epatrizio opened this issue Jul 13, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@epatrizio
Copy link
Owner

Execution: OK

function fact(n)
  if n <= 1 then
    return 1
  else
    return n * fact(n-1)
  end
end
print(fact(5)) -- 120

Execution: KO! (The only difference is that function is local)
Error message: Interpretation error: Typing error: attempt to call a non function value

local function fact(n)
  if n <= 1 then
    return 1
  else
    return n * fact(n-1)
  end
end
print(fact(5))

The problem seems to come from the scope analysis

local v2 = function (v0)
 if v0<=1 then return 1
 else return v0*v1(v0-1) end
end

local v2 instead of local v1

@epatrizio epatrizio added the bug Something isn't working label Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant