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

All function arguments should receive a new placeholder #36

Closed
jiegillet opened this issue Oct 31, 2021 · 1 comment
Closed

All function arguments should receive a new placeholder #36

jiegillet opened this issue Oct 31, 2021 · 1 comment

Comments

@jiegillet
Copy link
Contributor

jiegillet commented Oct 31, 2021

All function arguments should receive a new placeholder, since local names take over global names.

Example input

def add(a, b), do: a + b
def combine(add, mult), do: fn x, y, z -> add(x, mult(y, z)) end

Desired result

  def(PLACEHOLDER_1(PLACEHOLDER_2, PLACEHOLDER_3)) do
    PLACEHOLDER_2 + PLACEHOLDER_3
  end
  def(PLACEHOLDER_4(PLACEHOLDER_5, PLACEHOLDER_6)) do
    fn PLACEHOLDER_7, PLACEHOLDER_8, PLACEHOLDER_9 -> PLACEHOLDER_5(PLACEHOLDER_7, PLACEHOLDER_6(PLACEHOLDER_8, PLACEHOLDER_9)) end
  end

Current result

  def(PLACEHOLDER_1(PLACEHOLDER_2, PLACEHOLDER_3)) do
    PLACEHOLDER_2 + PLACEHOLDER_3
  end
  def(PLACEHOLDER_4(PLACEHOLDER_1, PLACEHOLDER_5)) do
    fn PLACEHOLDER_6, PLACEHOLDER_7, PLACEHOLDER_8 -> PLACEHOLDER_1(PLACEHOLDER_6, PLACEHOLDER_5(PLACEHOLDER_7, PLACEHOLDER_8)) end
  end

Note that the argument add in combine/PLACEHOLDER_4 has been replaced by PLACEHOLDER_1 as assigned in add/PLACEHOLDER_1 but has no connection to it and should be called PLACEHOLDER_5 instead.

@jiegillet
Copy link
Contributor Author

I stand corrected, I read the documentation a bit more closely and it mentions (at the end)

It is important to note that all identical names must be replaced with the same placeholder, irrespective of scope.

I suppose it is important so we can comment on that very thing, for example: "you shouldn't shadow an existing variable name".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant