Skip to content

Commit

Permalink
Update introduction.md for language corrections for the library-of-lu…
Browse files Browse the repository at this point in the history
…ton exercise (#571)
  • Loading branch information
rjpgt authored Jan 3, 2024
1 parent 7f4b233 commit 2680987
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions exercises/concept/library-of-luton/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Char

`Char` is a data type in Crystal that represents a 32-bit [Unicode][unicode] code point.
Their size makes so they are memory efficient, and also gives it certain properties that Strings don't have.
Their size makes them memory efficient, and also gives them certain properties that Strings don't have.
They are created using single quotes (`'`) and do only allow for one Unicode code point to be placed inside.

```crystal
'a' # => 'a'
'a'.class # => Char
```

When working with Strings in Crystal is it quite common to work with Chars, since quite a few methods in the String class return Chars or takes Chars as arguments.
For example, the [`String#[]`][index] method returns a Char, or the [`String#chars`][chars] method returns a collection of Chars.
When working with Strings in Crystal it is quite common to work with Chars, since quite a few methods in the String class return Chars or takes Chars as arguments.
For example, the [`String#[]`][index] method returns a Char, and the [`String#chars`][chars] method returns a collection of Chars.

## Incrementing / Decrementing

Due to char being a 32 Unicode point do they support incrementing and decrementing, this makes it so if you have `'a'` so can you get `'b'` by adding one.
Due to Char being a 32 Unicode point it supports incrementing and decrementing. For example, if you have `'a'` you can get `'b'` by adding one.

```crystal
'a' + 5
Expand All @@ -36,8 +36,8 @@ There is also a method called [`Char#succ`][succ] which will return the next cha

## concatenation

Since Chars is only meant to represent a 32-bit Unicode, can't 2 chars be concatenation.
Thereby Chars can only be concatenated with Strings.
Since a Char is only meant to represent a single 32-bit Unicode point, concatenation of 2 Chars is not allowed.
Chars can only be concatenated with Strings.

```Crystal
'a' + "bc"
Expand All @@ -47,7 +47,7 @@ Thereby Chars can only be concatenated with Strings.
# => error: expected argument #1 to 'Char#+' to be Int or String, not Char
```

## Properties methods
## Properties, methods

Crystal has a few methods that can be used to get information about a Char, like if it is a number or a letter, or if it is uppercase or lowercase.
Here is a list of some of the methods, for a full list see the [Char API][char-api]:
Expand All @@ -65,7 +65,7 @@ Here is a list of some of the methods, for a full list see the [Char API][char-a

### Converting between code points and Chars

Since Chars is a 32-bit Unicode point, so can you convert between Chars and code points (Int).
Since Chars is a 32-bit Unicode point, you can convert between Chars and code points (Int).
This can be done using the [`Char#ord`][ord] method which will return the code point of the Char, or the [`Int#chr`][chr] method which will return the Char of the code point.

```crystal
Expand All @@ -78,8 +78,8 @@ This can be done using the [`Char#ord`][ord] method which will return the code p

### Converting between types

As with other data types so does Chars have a few methods that can be used to convert between types.
The most common one is the `Char#to_s` method which will convert the Char to a String, but there is also the `Char#to_i` method which will convert the Char to an Int, And the `Char#to_f` method which will convert the Char to a Float.
As with other data types, Chars have a few methods that can be used to convert between types.
The most common one is the `Char#to_s` method which will convert the Char to a String. There is also the `Char#to_i` method which will convert the Char to an Int, and the `Char#to_f` method which will convert the Char to a Float.

```crystal
'a'.to_s
Expand Down

0 comments on commit 2680987

Please sign in to comment.