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

(COMPLETE) Questions on card counting and warning messages... #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BigSpaces
Copy link
Owner

Hello @BrooklinJazz,

I wonder if we can translate Elixir Compiles into Newbie English Compiles...

warning: variable "acc" is unused (there is a variable with the same name in the context, use the pin operator (^) to match on it or prefix this variable with underscore if it is not meant to be used)
  Documents/GitHub/beta_curriculum/exercises/card_counting.livemd#cell:9

I would be quite sure, looking at the code, that I have indeed used acc... but I am sure there is a reason behind the message.

Thank you!

Copy link

@BrooklinJazz BrooklinJazz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment about the acc warning. Otherwise, this looks great! Way to apply your new knowledge of reduce to a previous problem.


cond do
card < 7 -> acc = acc - 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We encountered this today. Remember that we don't rebind the accumulator, the next accumulator will be the return value of our function.

The warning warning: variable "acc" is unused (there is a variable with the same name in the context, use the pin operator (^) to match on it or prefix this variable with underscore if it is not meant to be used) Documents/GitHub/beta_curriculum/exercises/card_counting.livemd#cell:9 occurs because we have bound acc = acc in the return value of our cond statement. We don't then use the bound variable, so Elixir let's us know we are probably doing something wrong.

Try changing the cond statement to resolve the issue.

cond do
  card < 7 -> acc + 1
  card > 9 -> acc - 1
  true -> acc
end

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved! Thank you :)

@BigSpaces BigSpaces changed the title Questions on card counting and warning messages... (COMPLETE) Questions on card counting and warning messages... Oct 7, 2022
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

Successfully merging this pull request may close these issues.

2 participants