Permalink
Browse files

Deprecate record default-based generated functions

  • Loading branch information...
1 parent 8df8034 commit 9b3d851a9c438cc5de5efca13d622e359312de49 @josevalim josevalim committed Dec 1, 2012
View
@@ -15,6 +15,7 @@
* deprecations
* [Enum] `Enum.qsort` is deprecated and `List.sort` in favor of `Enum.sort`
* [ExUnit] `assert left in right` is deprecated in favor of `assert left inlist right`
+ * [Record] Record default-based generated functions are deprecated
* [Typespec] Enhacements and deprecations to the `@spec/@callback` syntax
# v0.7.1 (2012-11-18)
@@ -68,7 +68,7 @@ defmodule EEx.Compiler do
else
key = length(state.dict)
placeholder = '__EEX__(' ++ integer_to_list(key) ++ ');'
- { current ++ placeholder ++ new_lines ++ chars, state.prepend_dict([{key, buffer}]) }
+ { current ++ placeholder ++ new_lines ++ chars, state.update_dict([{key, buffer}|&1]) }
end
end
View
@@ -1354,7 +1354,7 @@ defmodule Kernel do
## Examples
- defrecord FileInfo, atime: nil, mtime: nil
+ defrecord FileInfo, atime: nil, accesses: 0
The line above will define a module named `FileInfo` which
contains a function named `new` that returns a new record
@@ -1371,36 +1371,17 @@ defmodule Kernel do
inspect FileInfo.new, raw: true
#=> { FileInfo, nil, nil }
- ## Extensions
-
- Besides defining readers and writers for each attribute. Elixir will
- define extensions functions for each attribute. By default, it will
- define an `update_#{attribute}` function to update the value. Such
+ Besides defining readers and writers for each attribute, Elixir also
+ defines an `update_#{attribute}` function to update the value. Such
functions expect a function as argument that receives the current
- value and must return the new one:
-
- file_info.update_atime(fn(_old) -> now() end) #=> Updates the value of atime
-
- Besides, Elixir may define new functions depending on the default value.
- For example, ExUnit defines a record which keeps track of how many tests
- were executed and the failures that happened. The record definition is
- similar to:
-
- defrecord Config, counter: 0, failures: []
-
- Since `counter` is an integer, Elixir automatically defines a helper
- named `increment_counter` that will increase the counter value:
-
- Config.new.increment_counter.counter #=> 1
-
- `increment_counter` also accepts a number of increment as argument:
+ value and must return the new one. For example, every time the file
+ is accessed, the accesses counter can be incremented with:
- Config.new.increment_counter(10).counter #=> 10
+ file_info.update_accesses(fn(old) -> old + 1 end)
- Besides, if the default is a list, Elixir will define two helpers:
+ Which can be also written as:
- * `merge_field` - Receives keywords and merge it into the current value;
- * `prepend_field` - Receives another list and prepend its values;
+ file_info.update_accesses(&1 + 1)
## Documentation
@@ -1526,7 +1507,7 @@ defmodule Kernel do
false ->
quote do
result = unquote(thing)
- is_tuple(result) and tuple_size(result) > 1 and
+ is_tuple(result) and tuple_size(result) > 1 and
:erlang.element(2, result) == :__exception__
end
end
@@ -123,7 +123,7 @@ defmodule Kernel.CLI do
end
defp process_shared(['-e',h|t], config) do
- process_shared t, config.prepend_commands [eval: h]
+ process_shared t, config.update_commands [{:eval,h}|&1]
end
defp process_shared(['-pa',h|t], config) do
@@ -139,14 +139,14 @@ defmodule Kernel.CLI do
defp process_shared(['-r',h|t], config) do
h = list_to_binary(h)
config = Enum.reduce File.wildcard(h), config, fn path, config ->
- config.prepend_commands [require: path]
+ config.update_commands [{:require,path}|&1]
end
process_shared t, config
end
defp process_shared(['-pr',h|t], config) do
h = list_to_binary(h)
- process_shared t, config.prepend_commands [parallel_require: h]
+ process_shared t, config.update_commands [{:parallel_require,h}|&1]
end
defp process_shared([erl,_|t], config) when erl in ['--erl', '--sname', '--remsh', '--name'] do
@@ -170,7 +170,8 @@ defmodule Kernel.CLI do
defp process_argv(['-S',h|t], config) do
exec = System.find_executable(h)
if exec do
- { config.prepend_commands([require: list_to_binary(exec)]), t }
+ bin = list_to_binary(exec)
+ { config.update_commands([{:require,bin}|&1]), t }
else
IO.puts(:stderr, "Could not find executable #{h}")
System.halt(1)
@@ -182,8 +183,8 @@ defmodule Kernel.CLI do
'-' ++ _ ->
shared_option? list, config, process_argv(&1, &2)
_ ->
- h = list_to_binary(h)
- { config.prepend_commands([require: h]), t }
+ bin = list_to_binary(h)
+ { config.update_commands([{:require,bin}|&1]), t }
end
end
@@ -202,15 +203,15 @@ defmodule Kernel.CLI do
end
defp process_compiler(['--no-docs'|t], config) do
- process_compiler t, config.merge_compiler_options(docs: false)
+ process_compiler t, config.update_compiler_options([{:docs,false}|&1])
end
defp process_compiler(['--no-debug-info'|t], config) do
- process_compiler t, config.merge_compiler_options(debug_info: false)
+ process_compiler t, config.update_compiler_options([{:debug_info,false}|&1])
end
defp process_compiler(['--ignore-module-conflict'|t], config) do
- process_compiler t, config.merge_compiler_options(ignore_module_conflict: true)
+ process_compiler t, config.update_compiler_options([{:ignore_module_conflict,true}|&1])
end
defp process_compiler([h|t] = list, config) do
@@ -220,12 +221,12 @@ defmodule Kernel.CLI do
_ ->
h = list_to_binary(h)
pattern = if File.dir?(h), do: "#{h}/**/*.ex", else: h
- process_compiler t, config.prepend_compile [pattern]
+ process_compiler t, config.update_compile [pattern|&1]
end
end
defp process_compiler([], config) do
- { config.prepend_commands([compile: config.compile]), [] }
+ { config.update_commands([{:compile,config.compile}|&1]), [] }
end
# Process commands
Oops, something went wrong.

0 comments on commit 9b3d851

Please sign in to comment.