XCODX |

Crystal Online Compiler & Interpreter

Select Language
Online Code Compiler
Full HTML IDE
Py main.py
Program Output Ready
  Welcome to XCODX Online Compiler

  Quick Start:
  Ctrl+Enter  Run code
  Ctrl+S      Save / Download
  Ctrl+L      Clear output

  Select a language and start coding.
Success
Operation completed

About Crystal

Crystal is a compiled, statically typed language created by Ary Borenszweig and the team at Manas Technology Solutions in Argentina, first appearing publicly around 2014. Its syntax is deliberately close to Ruby — many Ruby snippets run almost unchanged — but Crystal compiles to native code through LLVM and infers types instead of interpreting them, so you get Ruby-like ergonomics with performance nearer to C. There is no interpreter at runtime; the sandbox compiles your source to a native binary and runs it. Type inference means you rarely write annotations, yet mistakes are still caught at compile time. On XCODX you can explore that Ruby-flavored syntax and Crystal's standard library directly in the browser.

Hello World in Crystal

print "Enter your name: "
name = gets.to_s.chomp
print "Enter a number: "
n = gets.to_s.chomp.to_i
puts "Hi #{name}! Squares up to #{n}:"
(1..n).each do |i|
  puts "#{i} => #{i * i}"
end

When to use Crystal

Crystal appeals most to Ruby developers who want the same expressive syntax without the interpreter's runtime cost — web backends (with frameworks like Kemal or Lucky), CLI tools, and text processing are common targets. Choose it when readability matters and you still want a compiled, type-checked binary. Its concurrency model uses lightweight fibers, which suits IO-bound services. It is a weaker fit where you need a large, mature package ecosystem or first-class Windows support, and here specifically the Shards package manager is unavailable, so only the standard library is in reach.

Common questions

Can I use Shards to add libraries in this Crystal compiler?

No. The sandbox provides only Crystal's standard library, with no Shards, no network, and no persistent filesystem, so external shards cannot be fetched or installed. Stick to what requiring the built-in standard modules gives you.

How do I read input from the keyboard in Crystal?

Call `gets`, which reads one line from standard input and returns a `String?` (it can be `nil` at end of input), so a common pattern is `gets.to_s.chomp`. In the live terminal the program waits for you to type and press Enter; you can also feed the Stdin Box, and Ctrl+D closes the stream. Convert with `.to_i` or `.to_f` for numbers.

Is Crystal just compiled Ruby?

Not quite. The syntax is intentionally Ruby-like and much code looks identical, but Crystal is statically typed with compile-time type inference, has no runtime monkey-patching, and compiles to a native binary via LLVM rather than being interpreted. Some dynamic Ruby features are deliberately left out.

Why is gets returning nil in Crystal?

`gets` returns `nil` when there is no more input — for example when the stream is closed with Ctrl+D or the Stdin Box is empty. Guard it with `if line = gets` or convert defensively with `gets.to_s`. This nil-awareness is part of Crystal's null safety.

Can I build a web server in Crystal on XCODX?

You can write the code, but it will not accept outside connections — the sandbox has no network access and each run is isolated and temporary. Crystal's HTTP server lives in the standard library, so it compiles, but treat this as a syntax playground rather than a live host.

Which Crystal version runs here, and is it fast?

The runtime badge shows the exact version, typically a recent 1.x release. Because programs compile to native code before running, execution is quick, though you will see a short compile step first and there is an overall run timeout.

How Crystal runs on XCODX

Sandbox filename
main.cr
Entry point
single main source file
Editor grammar
ruby
Reading stdin
gets
Input delivery
live WebSocket stream
Prompt flushing
unbuffered automatically (STDOUT.sync = true is prepended on live runs)
Compile limit
10 s
Run limit
3 s batch · up to 3 min live
Memory
256 MB per stage
Max source
50,000 characters

Default program on this page

puts "Hello from Crystal!"
puts "Welcome to XCODX Online Compiler!"
message = "Crystal is fast!"
puts message