Created
November 15, 2018 05:50
-
-
Save fay-jai/a343c3d0adc3ccdfbc4f5430d3adb9f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to invoke an anonymous function in Elixir | |
greet = fn (name) -> "Hello, #{name}" end | |
greet.("Willson") # Notice the dot right after variable name but before the opening parentheses | |
# How to invoke a named function in Elixir | |
defmodule Greeter do # This is an Elixir module, and for the purposes of this example, it's simply a container for named functions | |
def greet(name), do: "Hello #{name}" # Here we're defining a new named function `greet` | |
end | |
Greeter.greet(name) # And here we're invoking the named function. Notice that there isn't a dot right after the function name and before the opening parentheses |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment