-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM crystallang/crystal:latest | ||
WOR | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
docker run --rm -it -w/opt -v$(pwd):/opt crystallang/crystal crystal $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"title": "Crystal Programming", | ||
"author": "Gabor Szabo", | ||
"description": "", | ||
"first_year": "2021", | ||
"copyright_name": "Gabor Szabo", | ||
"copyright_url": "https://szabgab.com/", | ||
"version": "0.01", | ||
"files": [ | ||
"introduction.md" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
x = 23 | ||
y = 19 | ||
z = x + y | ||
puts z # 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name = "Foo Bar" | ||
puts "Hello '#{name}'!" | ||
puts "Hello \"#{name}\"!" | ||
puts %(Hello "#{name}"!) # alternative quotes | ||
puts %{Hello "#{name}"!} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = "Foo Bar" | ||
puts "Hello " + name + "!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
name = "Foo Bar" | ||
puts "Hello #{name}!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
puts "Hello World!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
p! Math::PI | ||
p! Math::TAU | ||
p! Math::E |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Math::PI # => 3.141592653589793 | ||
Math::TAU # => 6.283185307179586 | ||
Math::E # => 2.718281828459045 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
x = -5.2 | ||
p! x.abs | ||
p! x.round | ||
# p! x.even? # Undefined method even? for Float64 | ||
|
||
age = 42 | ||
p! age.even? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name = "Foo Bar" | ||
puts typeof(name) # String | ||
p! typeof(name) # typeof(name) => String | ||
|
||
age = 42 | ||
puts typeof(age) # Int32 | ||
p! typeof(age) # typeof(age) => Int32 | ||
|
||
pi = 3.14 | ||
puts typeof(pi) # Float64 | ||
p! typeof(pi) # typeof(pi) => Float64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Introduction | ||
{id: introduction} | ||
|
||
## Crystal Language | ||
{id: crystal-language} | ||
|
||
* [Crystal lang](https://crystal-lang.org/) | ||
* Similar to Ruby | ||
|
||
|
||
## Docker on Linux | ||
{id: docker-on-linux} | ||
|
||
* [Docker Crystal](https://hub.docker.com/r/crystallang/crystal) | ||
* Install Docker | ||
* Create a file called `crystal` with the following content: | ||
|
||
 | ||
|
||
* Make it executable by running `chmod +x crystal` | ||
* Run `./crystal examples/hello_world.cr` | ||
|
||
## Hello World (puts) | ||
{id: hello-world} | ||
{i: puts} | ||
|
||
 | ||
|
||
* `puts` stands for "put string" | ||
|
||
|
||
## Hello Name (variables) | ||
{id: hello-name} | ||
|
||
 | ||
|
||
## Hello Name with interpolation | ||
{id: hello-name-interpolation} | ||
|
||
 | ||
|
||
## Escaping - Alternative delimiters | ||
{id: escaping} | ||
|
||
 | ||
|
||
|
||
## Add numbers | ||
{id: add-numbers} | ||
|
||
 | ||
|
||
## Types | ||
{id: types} | ||
{i: String} | ||
{i: Int32} | ||
{i: Float64} | ||
{i: p!} | ||
|
||
 | ||
|
||
|
||
## Numeric Operators | ||
{id: numeric-operators} | ||
|
||
|
||
``` | ||
+ | ||
- | ||
* | ||
** (exponent) | ||
/ | ||
// (floor division) | ||
% (modulus) | ||
``` | ||
|
||
## Comparision Operators | ||
{id: comparision-operators} | ||
|
||
* ==, <, > <=, >= | ||
|
||
* Spaceship operator <=> returns -1, 0, or 1 | ||
|
||
|
||
## Math | ||
{id: math} | ||
|
||
 | ||
 | ||
|
||
|
||
## Other | ||
{id: other} | ||
|
||
* Single quotes vs double quotes | ||
|
||
No type-checking? | ||
|
||
x = "one" | ||
x = 1 | ||
p! x | ||
p! typeof(x) |