Comments (2)
Yep! Perfect sense thank you. It doesn't cover both /3 options, and d will be the default value of 2 unless you supply all four arguments, because elixir matches to the left. I have a Ruby background so this is in line with my assumptions. Thanks for your help!
from elixir-in-action.
Good question! The best way to be sure is to verify it ;) Let's change the function to print each args:
defmodule MyModule do
def fun(a, b \\ 1, c, d \\ 2) do
IO.puts "a = #{a}"
IO.puts "b = #{b}"
IO.puts "c = #{c}"
IO.puts "d = #{d}"
end
end
$ iex test.exs
iex> MyModule.fun(:arg_1, :arg_2, :arg_3)
a = arg_1
b = arg_2
c = arg_3
d = 2
If you think about it, it makes sense. If a single default arg is omitted when calling a fun, then the right-most arg with a default (in our case the arg d
) will have the default value.
Does that make sense?
from elixir-in-action.
Related Issues (16)
- A minor type in the book (chapter 9) HOT 1
- race condition in chapter 5's registered TODO server HOT 5
- unnecessary plus one for :erlang.phash() HOT 3
- proper_registry_supervisor why have init function? HOT 2
- unnecessary setting in the ets example HOT 1
- Benchmark in section 10.1 returning strange values HOT 6
- Reference to MyProject.start without introducing it first on page 61 HOT 2
- database cannot replicated via Elixir 1.9.2 version
- Error running `:observer.start()` command (macOS) HOT 1
- [ch09] - ProcessRegistry restarts crash the App
- Ch-05 Correction in Listing 5.12 (todo_server.ex)
- SimpleRegistry links to itself? HOT 2
- update readme to reflect your on elixir 1.3 HOT 1
- Bump Elixir version numbers in `mix.exs` HOT 2
- Great book! HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elixir-in-action.