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

Take-a-number needs a named function example #1486

Merged
merged 2 commits into from
May 26, 2024

Conversation

angelikatyborska
Copy link
Member

Partially addresses #1482

In take-a-number, it was difficult to figure out how to pass a named function to spawn. The example in the introduction used an anonymous function, and we actually don't teach anywhere how to use the capture operator to pass named functions as arguments. The only place this is mentioned, is the anonymous function's concept's "about" page, which most people will never see (rendered only if you browse the concept after learning it). None of the concept introductions mention how to use the capture operator for named functions.

Copy link
Contributor

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

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

Small increment, but worth doing, thank you.

Don't forget to make the same change in the original into/about files.

Copy link
Contributor

Thank you for contributing to exercism/elixir 💜 🎉. This is an automated PR comment 🤖 for the maintainers of this repository that helps with the PR review process. You can safely ignore it and wait for a maintainer to review your changes.

Based on the files changed in this PR, it would be good to pay attention to the following details when reviewing the PR:

  • General steps

    • 🏆 Does this PR need to receive a label with a reputation modifier (x:size/{tiny,small,medium,large,massive})? (A medium reputation amount is awarded by default, see docs)
  • Any exercise changed

    • 👤 Does the author of the PR need to be added as an author or contributor in <exercise>/.meta/config.json (see docs)?
    • 🔬 Do the analyzer and the analyzer comments exist for this exercise? Do they need to be changed?
    • 📜 Does the design file (<exercise>/.meta/design.md) need to be updated to document new implementation decisions?
  • Concept exercise changed

    • 🌲 Do prerequisites and practices in config.json need to be updated?
    • 📖 Does the concept introduction provide all necessary information to solve this exercise?
  • Concept changed

    • 👤 Does the author of the PR need to be added as an author or contributor in <concept>/.meta/config.json (see docs)?
    • 📖 Does the concept introduction provide all necessary information to solve this exercise?

Automated comment created by PR Commenter 🤖.

@angelikatyborska angelikatyborska merged commit dc47840 into main May 26, 2024
9 of 10 checks passed
@angelikatyborska angelikatyborska deleted the take-a-number-named-func branch May 26, 2024 14:03
@angelikatyborska
Copy link
Member Author

A bit late, but I noticed now that the exemplar solution doesn't even use function capturing 🙃 I'm afraid this change might have added even more confusion...

defmodule TakeANumber do
  def start() do
    spawn(fn -> loop(0) end)
  end

  defp loop(state) do
    receive do
      {:report_state, sender_pid} ->
        send(sender_pid, state)
        loop(state)

      {:take_a_number, sender_pid} ->
        state = state + 1
        send(sender_pid, state)
        loop(state)

      :stop ->
        nil

      _ ->
        loop(state)
    end
  end
end

angelikatyborska added a commit that referenced this pull request Aug 10, 2024
angelikatyborska added a commit that referenced this pull request Aug 29, 2024
* Revert "Take-a-number needs a named function example (#1486)"

This reverts commit dc47840.

* The first step does not require starting a receive loop

* Format
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