Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (55 sloc) 1.71 KB


Crystal is a programming language that compiles to native code. It has a syntax strongly inspired by Ruby:

  • No need to declare types: everything is inferred.
  • Classes and Modules can be opened: at compile time everything is mixed together
  • String interpolation
  • Regular expression interpolation
  • Instance variables start with @
  • Global variables start with $
  • Constants start with Capital Letters
  • Functions can be evaluated at compile time as long as they are assigned to a Constant.

How to run it in your machine

Clone, run bundle, but ruby-llvm should be version 2.9.2. Now, that version was not released and is not in RubyGems, you can get it from here:

The only problem is... the native extensions don't seem to compile anymore. So if anyone finds a solution for this: very, very welcome! :-)

Then you'll have five executables:

  • bin/compile => compiles a given down to machine down
  • bin/dump => shows the unoptimized llvm file for a a given
  • bin/icr => interactive crystal shell
  • bin/interpret => interprets a given
  • bin/ll => shows the optimized llvm file for a given file.ll


Hello World

puts "Hello World"


def fib n
  if n <= 2
    fib(n - 1) + fib(n - 2)

Value = fib 6
puts Value

Compiles to...

puts 8

Constants as arguments

def static N, x
  if N == 1
    2 * x
    3 * x

puts static(2, 6)

Compiles to...

def static_2 x
 3 * x

puts static_2(6)
Something went wrong with that request. Please try again.