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

[v3] Implement new Concept Exercise: atoms #441

Open
gwaerondor opened this issue Apr 9, 2020 · 0 comments
Open

[v3] Implement new Concept Exercise: atoms #441

gwaerondor opened this issue Apr 9, 2020 · 0 comments

Comments

@gwaerondor
Copy link
Contributor

This issue describes how to implement the atoms concept exercise for the Erlang track.

Getting started

Please please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time. So, before diving into the implementation, please read up on the following documents:

Please also watch the following video:

Goal

The goal of this exercise is to teach the student how atoms work in Erlang. We will teach this through the use of pattern matching on different atoms, and ensuring that conventional tuples with result and data is returned.

Learning objectives

  • Know of the existence of atoms.
  • Understand that atoms are constant and literal.
  • Understand that module names and function names are atoms.
  • Understand the usefulness of atoms when pattern matching:
    • In function heads
    • In case clauses
  • Understand some of the conventional return values in Erlang, signifying success or failure.
    • ok | {error, Reason}
    • {ok, Result} | {error, Reason}

Out of scope

Concepts

  • atoms

Prerequisites

  • pattern-matching
  • tuples
  • numbers

Resources to refer to

Atoms

After

No resource in particular, but it should mention naming rules for atoms (single quotes, or lower-case letter followed by alphanumerics, @ or _).

Representer

Analyzer

Implementing

The best fit, using already existing resources, I think would be to re-use the "Valentine's day" exercise used for example in F#'s discriminated unions exercise. Instead of using discriminated unions, atoms would be used.
Atoms would be pattern matched either alone, for example if the activity is board_game,
or they would be pattern matched in a tuple together with some value, for example, {walk, 5} or {restaurant, turkish}.

The student can pattern match on these activities similar to how it's done in the F# example implementation.

However: this is much simpler to do in Erlang than in F# since no unions need to be defined. The first four instructions (defining different types of discriminated unions) would be unnecessary, and only the fifth and last instruction would need implementation.

Since most of the exercise would be removed, this could be compensated by adding some other instruction to teach the student about the conventional return values of ok | {error, Reason} and {ok, Result} | {error, Reason}. This would ensure that the student learns to create their own atoms, and not just pattern match on atoms that are in the input arguments to their function.

Another idea to extend the exercise would be to accept different units of length for the walk activity. The student would, by pattern matching on the atom representing the unit, convert from different units to kilometers. For example, the three function calls below would be roughly equivalent:

rate_activity({walk, {5000, m}}).
rate_activity({walk, {5, km}}).
rate_activity({walk, {3.107, mi}}).

Help

If there's another pre-existing exercise that would be a better fit to port, I'd love to know about it. Also it would be nice to have some better and more fun theme than "convert units". All ideas welcome.

@nicolechalmers nicolechalmers changed the title [Erlang] Implement new Concept Exercise: atoms [v3] Implement new Concept Exercise: atoms Jan 28, 2021
@nicolechalmers nicolechalmers transferred this issue from exercism/v3 Jan 28, 2021
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