You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Another one is `binary_slice/2` in the `Kernel` module:
130
+
`binary_slice/2` (and `binary_slice/3` for completeness) has been added to the
131
+
`Kernel` module, that works with bytes and also support stepped ranges:
127
132
128
133
```elixir
129
134
binary_slice("Elixir", 1..5//2)
130
135
#=> "lx"
131
136
```
132
137
133
-
## Expression-based inspection
138
+
## Expression-based inspection and `Inspect` improvements
134
139
135
-
In Elixir, it's conventional to implement the `Inspect` protocol for structs so
136
-
that they're inspected with a syntax resembling this:
140
+
In Elixir, it's conventional to implement the `Inspect` protocol for opaque
141
+
structs so that they're inspected with a special notation, resembling this:
137
142
138
143
```elixir
139
144
MapSet.new([:apple, :banana])
@@ -151,7 +156,7 @@ and pasting it into an IEx session or similar.
151
156
Elixir v1.14 changes the convention for some of the standard-library structs.
152
157
The `Inspect` implementation for those structs is now a string with a valid
153
158
Elixir expression that recreates the struct itself if evaluated. In the
154
-
`Version` example above, this is what we have now:
159
+
`MapSet` example above, this is what we have now:
155
160
156
161
```elixir
157
162
fruits =MapSet.new([:apple, :banana])
@@ -160,12 +165,16 @@ MapSet.put(fruits, :pear)
160
165
```
161
166
162
167
The `MapSet.new/1` expression evaluates to exactly the struct that we're
163
-
inspecting.
168
+
inspecting. This allows us to hide the internals of `MapSet`, while keeping
169
+
it as valid Elixir code. This expression-based inspection has been
170
+
implemented for `Version.Requirement`, `MapSet`, and `Date.Range`.
164
171
165
-
This expression-based inspection has been implemented for `Version`,
166
-
`Version.Requirement`, `MapSet`, and `Date.Range`. Other data types (such as
167
-
`PID`) still use the `#name<...>` convention because generally there is no
168
-
Elixir expression that can deterministically recreate the data type.
172
+
Finally, we have also improved the `Inspect` protocol for structs so the
173
+
fields are inspected in the order they are declared in `defstruct`.
174
+
The option `:optional` has also been added when deriving the `Inspect`
175
+
protocol, giving developers more control over the struct representation.
176
+
See the updated documentation for `Inspect` for a general rundown on
177
+
the approaches and options available.
169
178
170
179
## v1.14.0-dev
171
180
@@ -179,22 +188,25 @@ Elixir expression that can deterministically recreate the data type.
179
188
#### Elixir
180
189
181
190
*[Calendar] Support ISO8601 basic format parsing with `DateTime.from_iso8601/2`
191
+
*[Code] Add `:normalize_bitstring_modifiers` to `Code.format_string!/2`
182
192
*[Code] Emit deprecation and type warnings for invalid options in on `Code.compile_string/2` and `Code.compile_quoted/2`
183
193
*[Code] Warn if an outdated lexical tracker is given on eval
184
194
*[Code] Add `Code.env_for_eval/1` and `Code.eval_quoted_with_env/3`
185
195
*[Code] Improve stacktraces from eval operations on Erlang/OTP 25+
186
196
*[Enum] Allow slicing with steps in `Enum.slice/2`
187
197
*[Float] Do not show floats in scientific notation if below `1.0e16` and the fractional value is precisely zero
188
198
*[Inspect] Improve error reporting when there is a faulty implementation of the `Inspect` protocol
189
-
*[Inspect] Allow `:optional` when deriving the Inspect protocol
190
-
*[Inspect] Inspect struct fields in the order they are defined
199
+
*[Inspect] Allow `:optional` when deriving the Inspect protocol for hiding fields that match their default value
200
+
*[Inspect] Inspect struct fields in the order they are declared in `defstruct`
191
201
*[Inspect] Use expression-based inspection for `Date.Range`, `MapSet`, and `Version.Requirement`
202
+
*[IO] Support `Macro.Env` and keywords as stacktrace definitions in `IO.warn/2`
192
203
*[Kernel] Allow any guard expression as the size of a bitstring in a pattern match
193
204
*[Kernel] Allow composite types with pins as the map key in a pattern match
194
205
*[Kernel] Print escaped version of control chars when they show up as unexpected tokens
195
206
*[Kernel] Warn on confusable non-ASCII identifiers
196
207
*[Kernel] Add `..` as a nullary operator that returns `0..-1//1`
197
-
*[Kernel] Implement Unicode Technical Standard #39 recommendations; in particular, we warn for confusable scripts and restrict identifiers to single-scripts or highly restrictive mixed-scripts
208
+
*[Kernel] Implement Unicode Technical Standard #39 recommendations. In particular, we warn for confusable scripts and restrict identifiers to single-scripts or highly restrictive mixed-scripts
209
+
*[Kernel] Automatically perform NFC conversion of identifiers
198
210
*[Kernel] Add `binary_slice/2` and `binary_slice/3`
199
211
*[Keyword] Add `Keyword.from_keys/2` and `Keyword.replace_lazy/3`
200
212
*[List] Add `List.keysort/3` with support for a `sorter` function
@@ -219,6 +231,7 @@ Elixir expression that can deterministically recreate the data type.
0 commit comments