Created
June 7, 2021 18:04
-
-
Save BrooklinJazz/bbd545ffebcfeb4aff64d9f441ddccc6 to your computer and use it in GitHub Desktop.
Demonstrate elixir functions with different parameters
This file contains hidden or 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
| defmodule Greeting do | |
| def say_hello do | |
| "Hello" | |
| end | |
| def say_hello(name) do | |
| "Hello #{name}" | |
| end | |
| def say_hello(name1, name2) do | |
| "Hello #{name1}, Hi #{name2}" | |
| end | |
| end | |
| IO.puts Greeting.say_hello() # Hello | |
| IO.puts Greeting.say_hello("Bob") # Hello Bob | |
| IO.puts Greeting.say_hello("Bob", "Bill") # Hello Bob, Hi Bill | |
| IO.puts Greeting.say_hello("Bob", "Bill", "Billy") | |
| # (UndefinedFunctionError) function Greeting.say_hello/3 is undefined or private. Did you mean one of: | |
| * say_hello/0 | |
| * say_hello/1 | |
| * say_hello/2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment