You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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:
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.
The text was updated successfully, but these errors were encountered:
nicolechalmers
changed the title
[Erlang] Implement new Concept Exercise: atoms
[v3] Implement new Concept Exercise: atoms
Jan 28, 2021
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
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:
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.
The text was updated successfully, but these errors were encountered: