@@ -201,12 +201,16 @@ defmodule Kernel.SpecialForms do
201
201
202
202
We can solve this by explicitly tagging it as a binary:
203
203
204
- <<102, rest :: binary>>
204
+ iex> rest = "oo"
205
+ iex> <<102, rest :: binary>>
206
+ "foo"
205
207
206
208
The type can be integer, float, bitstring/bits, binary/bytes,
207
209
utf8, utf16 or utf32, e.g.:
208
210
209
- <<102 :: float, rest :: binary>>
211
+ iex> rest = "oo"
212
+ iex> <<102 :: float, rest :: binary>>
213
+ <<64, 89, 128, 0, 0, 0, 0, 0, 111, 111>>
210
214
211
215
An integer can be any arbitrary precision integer. A float is an
212
216
IEEE 754 binary32 or binary64 floating point number. A bitstring
@@ -298,9 +302,11 @@ defmodule Kernel.SpecialForms do
298
302
Size and unit can also be specified using a syntax shortcut
299
303
when passing integer values:
300
304
301
- << x :: 8 >> == << x :: size(8) >>
302
- << x :: 8 * 4 >> == << x :: size(8)-unit(4) >>
303
- << x :: _ * 4 >> == << x :: unit(4) >>
305
+ iex> x = 1
306
+ iex> << x :: 8 >> == << x :: size(8) >>
307
+ true
308
+ iex> << x :: 8 * 4 >> == << x :: size(8)-unit(4) >>
309
+ true
304
310
305
311
This syntax reflects the fact the effective size is given by
306
312
multiplying the size by the unit.
0 commit comments