Skip to content

Commit dced276

Browse files
authored
Update binaries-strings-and-charlists.md (#12850)
1 parent f2fe43e commit dced276

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/elixir/pages/getting-started/binaries-strings-and-charlists.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ iex> [?h, ?e, ?l, ?l, ?o]
239239
~c"hello"
240240
```
241241

242-
The `~c` sigil (we'll cover sigils later in the ["Sigils"](sigils.md) chapter)
243-
indicates the fact that we are dealing with a charlist and not a regular string.
242+
The `~c` sigil (we'll cover sigils later in the ["Sigils"](sigils.md) chapter) indicates the fact that we are dealing with a charlist and not a regular string.
244243

245244
Instead of containing bytes, a charlist contains integer code points. However, the list is only printed as a sigil if all code points are within the ASCII range:
246245

@@ -258,7 +257,14 @@ iex> heartbeats_per_minute = [99, 97, 116]
258257
~c"cat"
259258
```
260259

261-
You can convert a charlist to a string and back by using the `to_string/1` and `to_charlist/1` functions:
260+
You can always for charlists to be printed in their list representation by calling the `inspect/2` function:
261+
262+
```
263+
iex> inspect(heartbeats_per_minute, charlists: :as_list)
264+
"[99, 97, 116]"
265+
```
266+
267+
Furthermore, you can convert a charlist to a string and back by using the `to_string/1` and `to_charlist/1`:
262268

263269
```elixir
264270
iex> to_charlist("hełło")
@@ -271,7 +277,7 @@ iex> to_string(1)
271277
"1"
272278
```
273279

274-
Note that those functions are polymorphic - not only do they convert charlists to strings, they also operate on integers, atoms, and so on.
280+
The functions above are polymorphic, in other words, they accept many shapes: not only do they convert charlists to strings (and vice-versa), they can also convert integers, atoms, and so on.
275281

276282
String (binary) concatenation uses the `<>` operator but charlists, being lists, use the list concatenation operator `++`:
277283

0 commit comments

Comments
 (0)