Title here
Summary here
Crystal has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.
# Strings, which can be added together with `+`.
puts "crystal" + "lang"
# Integers and floats.
puts "1+1 = #{1 + 1}"
puts "7.0/3.0 = #{7.0 / 3.0}"
# Booleans, with boolean operators as you'd expect.
puts true && false
puts true || false
puts !true
To run the program, save it in a file with a .cr
extension and use the crystal
command:
$ crystal values.cr
crystallang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false
Crystal is a compiled language, but it also provides a way to run scripts directly. For larger programs, you might want to compile them into binaries:
$ crystal build values.cr
$ ./values
crystallang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false
This demonstrates basic value types and operations in Crystal. The syntax is quite similar to Ruby, but with static typing. Notice how Crystal uses string interpolation (#{...}
) for embedding expressions inside strings, which is a convenient feature for formatting output.