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 takes Ruby's famously pleasant syntax and compiles it to fast native code with static type checking and full type inference, so most programs need no type annotations at all. The language hit 1.0 in 2021 and its stable 1.x releases now power real infrastructure, including LavinMQ and AMQProxy from 84codes and the Invidious video frontend. Rubyists often describe it as the performance upgrade that does not make them rewrite their brain. On this page Crystal runs inside a genuine interactive terminal: the compiler builds your file, the binary executes live, and gets pauses for whatever you type, all without installing LLVM or the toolchain yourself.

Hello World in Crystal

def fibonacci(n : Int32) : Int64
  a, b = 0_i64, 1_i64
  n.times { a, b = b, a + b }
  a
end

print "Enter your name: "
name = gets
puts "Hello, #{name.try &.strip}!"

print "How many Fibonacci numbers? "
count = (gets || "5").strip.to_i

count.times do |i|
  puts "fib(#{i}) = #{fibonacci(i)}"
end

When to use Crystal

Crystal appeals to Ruby developers who need speed for API servers, message brokers, and CLI tools without giving up expressive blocks and method chaining. It is a strong teaching vehicle for static typing, because union types and compile-time nil checks surface bugs that Ruby would only reveal at runtime. Teams evaluating a Rails-to-compiled migration prototype endpoints in frameworks like Kemal, and open source users of Invidious or LavinMQ read and test snippets of the codebase here to understand how production Crystal looks.

Common questions

Does gets accept live keyboard input here?

Yes. The embedded terminal is wired directly to your program's stdin, so gets suspends execution and waits for you to type. Note that gets returns String | Nil in Crystal, so idiomatic code handles the nil case with .try, .not_nil!, or a default via (gets || "fallback"), just like the example above.

How is Crystal different from Ruby if the syntax looks the same?

Crystal is compiled ahead of time with static types inferred by the compiler, so it catches type and nil errors before the program runs and executes orders of magnitude faster than interpreted Ruby. The tradeoffs are compile time, no runtime eval or dynamic method definition, and a smaller ecosystem of shards versus gems.

Can I add shards or run multi-file projects in this sandbox?

No. Each run compiles a single file, and shard dependencies cannot be fetched because the sandbox has no network access. Crystal's standard library is extensive, covering HTTP, JSON, YAML, regular expressions, and concurrency via spawn and channels, so most algorithms, exercises, and learning experiments work without any external code.

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