Function

November 4, 2020 ยท View on GitHub

The Concept

In some languages, functions have their own type. This may or may not be a generic.

What to cover

  • How to define a function How to define a function. How to add functionality to a function. How does scoping the function work?
  • How to use function parameters How to define function parameters and how to use them.
  • How to return a value from a function How to return a value from a function. Does it require a specific keyword?
  • How to call a function How to call a function and pass arguments to it.

Exercises

Lasagna cooking

This exercise deals with cooking a lasagna dish in the oven. The reference implementation (F#) teaches:

  • How to define a function with one or two parameters.
  • How to use parameters in a function.
  • How to return a value from a function.
  • How to call a function.

Implementations

TrackExerciseChanges
C#lucians-luscious-lasagnaNone
F#basicsNone
Juliafunctions-introductionNone
RubybasicsNone
ElixirbasicsNone

Closure Maker

This exercise deals with creating set of functions which return functions that make use of closures.

  • How to define anonymous (lambda) functions.
  • How to return a function from a function.
  • How to use a variable in a closure.

Implementations

TrackExerciseChanges
ElixirbasicsNone