Skip to content

Commit 9b3d851

Browse files
author
José Valim
committed
Deprecate record default-based generated functions
1 parent 8df8034 commit 9b3d851

File tree

11 files changed

+85
-191
lines changed

11 files changed

+85
-191
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* deprecations
1616
* [Enum] `Enum.qsort` is deprecated and `List.sort` in favor of `Enum.sort`
1717
* [ExUnit] `assert left in right` is deprecated in favor of `assert left inlist right`
18+
* [Record] Record default-based generated functions are deprecated
1819
* [Typespec] Enhacements and deprecations to the `@spec/@callback` syntax
1920

2021
# v0.7.1 (2012-11-18)

lib/eex/lib/eex/compiler.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ defmodule EEx.Compiler do
6868
else
6969
key = length(state.dict)
7070
placeholder = '__EEX__(' ++ integer_to_list(key) ++ ');'
71-
{ current ++ placeholder ++ new_lines ++ chars, state.prepend_dict([{key, buffer}]) }
71+
{ current ++ placeholder ++ new_lines ++ chars, state.update_dict([{key, buffer}|&1]) }
7272
end
7373
end
7474

lib/elixir/lib/kernel.ex

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,7 +1354,7 @@ defmodule Kernel do
13541354
13551355
## Examples
13561356
1357-
defrecord FileInfo, atime: nil, mtime: nil
1357+
defrecord FileInfo, atime: nil, accesses: 0
13581358
13591359
The line above will define a module named `FileInfo` which
13601360
contains a function named `new` that returns a new record
@@ -1371,36 +1371,17 @@ defmodule Kernel do
13711371
inspect FileInfo.new, raw: true
13721372
#=> { FileInfo, nil, nil }
13731373
1374-
## Extensions
1375-
1376-
Besides defining readers and writers for each attribute. Elixir will
1377-
define extensions functions for each attribute. By default, it will
1378-
define an `update_#{attribute}` function to update the value. Such
1374+
Besides defining readers and writers for each attribute, Elixir also
1375+
defines an `update_#{attribute}` function to update the value. Such
13791376
functions expect a function as argument that receives the current
1380-
value and must return the new one:
1381-
1382-
file_info.update_atime(fn(_old) -> now() end) #=> Updates the value of atime
1383-
1384-
Besides, Elixir may define new functions depending on the default value.
1385-
For example, ExUnit defines a record which keeps track of how many tests
1386-
were executed and the failures that happened. The record definition is
1387-
similar to:
1388-
1389-
defrecord Config, counter: 0, failures: []
1390-
1391-
Since `counter` is an integer, Elixir automatically defines a helper
1392-
named `increment_counter` that will increase the counter value:
1393-
1394-
Config.new.increment_counter.counter #=> 1
1395-
1396-
`increment_counter` also accepts a number of increment as argument:
1377+
value and must return the new one. For example, every time the file
1378+
is accessed, the accesses counter can be incremented with:
13971379
1398-
Config.new.increment_counter(10).counter #=> 10
1380+
file_info.update_accesses(fn(old) -> old + 1 end)
13991381
1400-
Besides, if the default is a list, Elixir will define two helpers:
1382+
Which can be also written as:
14011383
1402-
* `merge_field` - Receives keywords and merge it into the current value;
1403-
* `prepend_field` - Receives another list and prepend its values;
1384+
file_info.update_accesses(&1 + 1)
14041385
14051386
## Documentation
14061387
@@ -1526,7 +1507,7 @@ defmodule Kernel do
15261507
false ->
15271508
quote do
15281509
result = unquote(thing)
1529-
is_tuple(result) and tuple_size(result) > 1 and
1510+
is_tuple(result) and tuple_size(result) > 1 and
15301511
:erlang.element(2, result) == :__exception__
15311512
end
15321513
end

lib/elixir/lib/kernel/cli.ex

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ defmodule Kernel.CLI do
123123
end
124124

125125
defp process_shared(['-e',h|t], config) do
126-
process_shared t, config.prepend_commands [eval: h]
126+
process_shared t, config.update_commands [{:eval,h}|&1]
127127
end
128128

129129
defp process_shared(['-pa',h|t], config) do
@@ -139,14 +139,14 @@ defmodule Kernel.CLI do
139139
defp process_shared(['-r',h|t], config) do
140140
h = list_to_binary(h)
141141
config = Enum.reduce File.wildcard(h), config, fn path, config ->
142-
config.prepend_commands [require: path]
142+
config.update_commands [{:require,path}|&1]
143143
end
144144
process_shared t, config
145145
end
146146

147147
defp process_shared(['-pr',h|t], config) do
148148
h = list_to_binary(h)
149-
process_shared t, config.prepend_commands [parallel_require: h]
149+
process_shared t, config.update_commands [{:parallel_require,h}|&1]
150150
end
151151

152152
defp process_shared([erl,_|t], config) when erl in ['--erl', '--sname', '--remsh', '--name'] do
@@ -170,7 +170,8 @@ defmodule Kernel.CLI do
170170
defp process_argv(['-S',h|t], config) do
171171
exec = System.find_executable(h)
172172
if exec do
173-
{ config.prepend_commands([require: list_to_binary(exec)]), t }
173+
bin = list_to_binary(exec)
174+
{ config.update_commands([{:require,bin}|&1]), t }
174175
else
175176
IO.puts(:stderr, "Could not find executable #{h}")
176177
System.halt(1)
@@ -182,8 +183,8 @@ defmodule Kernel.CLI do
182183
'-' ++ _ ->
183184
shared_option? list, config, process_argv(&1, &2)
184185
_ ->
185-
h = list_to_binary(h)
186-
{ config.prepend_commands([require: h]), t }
186+
bin = list_to_binary(h)
187+
{ config.update_commands([{:require,bin}|&1]), t }
187188
end
188189
end
189190

@@ -202,15 +203,15 @@ defmodule Kernel.CLI do
202203
end
203204

204205
defp process_compiler(['--no-docs'|t], config) do
205-
process_compiler t, config.merge_compiler_options(docs: false)
206+
process_compiler t, config.update_compiler_options([{:docs,false}|&1])
206207
end
207208

208209
defp process_compiler(['--no-debug-info'|t], config) do
209-
process_compiler t, config.merge_compiler_options(debug_info: false)
210+
process_compiler t, config.update_compiler_options([{:debug_info,false}|&1])
210211
end
211212

212213
defp process_compiler(['--ignore-module-conflict'|t], config) do
213-
process_compiler t, config.merge_compiler_options(ignore_module_conflict: true)
214+
process_compiler t, config.update_compiler_options([{:ignore_module_conflict,true}|&1])
214215
end
215216

216217
defp process_compiler([h|t] = list, config) do
@@ -220,12 +221,12 @@ defmodule Kernel.CLI do
220221
_ ->
221222
h = list_to_binary(h)
222223
pattern = if File.dir?(h), do: "#{h}/**/*.ex", else: h
223-
process_compiler t, config.prepend_compile [pattern]
224+
process_compiler t, config.update_compile [pattern|&1]
224225
end
225226
end
226227

227228
defp process_compiler([], config) do
228-
{ config.prepend_commands([compile: config.compile]), [] }
229+
{ config.update_commands([{:compile,config.compile}|&1]), [] }
229230
end
230231

231232
# Process commands

0 commit comments

Comments
 (0)