Languages Features Calendar CSV Lists Blog About Sponsor Add Language
GitHub icon



Crystal is a pl created in 2014 by Ary Borenszweig.

#56on PLDB 8Years Old 26.7kUsers
5Books 6Papers 8kRepos

Try now: Web · Riju · TIO

In computer software programming languages, Crystal is a general-purpose, object-oriented programming language, designed and developed by Ary Borenszweig and Juan Wajnerman and more than 200 contributors. With syntax inspired by the language Ruby, it is a compiled language with static type-checking, but specifying the types of variables or method arguments is generally unneeded. Types are resolved by an advanced global type inference algorithm. Read more on Wikipedia...

Example from Compiler Explorer:
# Type your code here, or load an example. # compile with --prelude=empty fun square(num : Int32) : Int32 num &* num end
Example from Riju:
puts "Hello, world!"
Example from hello-world:
puts "Hello World"
Example from the Hello World Collection:
# Hello world in Crystal puts "Hello World"
Example from Linguist:
#!/usr/bin/env bin/crystal --run require "../../spec_helper" describe "Type inference: declare var" do it "types declare var" do assert_type("a :: Int32") { int32 } end it "types declare var and reads it" do assert_type("a :: Int32; a") { int32 } end it "types declare var and changes its type" do assert_type("a :: Int32; while 1 == 2; a = 'a'; end; a") { union_of(int32, char) } end it "declares instance var which appears in initialize" do result = assert_type(" class Foo @x :: Int32 end") { types["Foo"] } mod = result.program foo = mod.types["Foo"] as NonGenericClassType foo.instance_vars["@x"].type.should eq(mod.int32) end it "declares instance var of generic class" do result = assert_type(" class Foo(T) @x :: T end Foo(Int32).new") do foo = types["Foo"] as GenericClassType foo_i32 = foo.instantiate([int32] of Type | ASTNode) foo_i32.lookup_instance_var("@x").type.should eq(int32) foo_i32 end end it "declares instance var of generic class after reopen" do result = assert_type(" class Foo(T) end f = Foo(Int32).new class Foo(T) @x :: T end f") do foo = types["Foo"] as GenericClassType foo_i32 = foo.instantiate([int32] of Type | ASTNode) foo_i32.lookup_instance_var("@x").type.should eq(int32) foo_i32 end end it "declares an instance variable in initialize" do assert_type(" class Foo def initialize @x :: Int32 end def x @x end end ") { int32 } end end
Example from Wikipedia:
channel = Channel(Int32).new spawn do puts "Before first send" channel.send(1) puts "Before second send" channel.send(2) end puts "Before first receive" value = channel.receive puts value # => 1 puts "Before second receive" value = channel.receive puts value # => 2

Keywords in Crystal

abstract do if nil? self unless alias else in of sizeof until as elsif include out struct when as? end instance_sizeof pointerof super while asm ensure is_a? private then with begin enum lib protected true yield break extend macro require type case false module rescue typeof class for next return uninitialized def fun nil select union

Language features

Feature Supported Example Token
While Loops
File Imports
require "../../spec_helper"
Booleans true false
"Hello world"
Print() Debugging puts
# A comment
Line Comments
# A comment
Semantic Indentation ϴ
MultiLine Comments ϴ

Books about Crystal from ISBNdb

title authors year publisher
Crystal Clear: A Human-Powered Methodology for Small Teams: A Human-Powered Methodology for Small Teams Cockburn, Alistair and Paul Becker, Alistair 2004 Addison-Wesley Professional
Crystal Reports .net Programming Bischof and Brian 2004 Bischof Systems
Crystal Reports Professional Results Peck, George 2003 McGraw-Hill Education
Crystal Programming: A project-based introduction to building efficient, safe, and readable web and CLI applications Dietrich, George and Bernal, Guilherme 2022 Packt Publishing
Crystal Reports XI Official Guide Fitzgerald, Neil and et al. 2006 Sams Publishing

Publications about Crystal from Semantic Scholar

title authors year citations influentialCitations
Crystal engineering with DNA Christine R Laramy and Matthew N. O’Brien and C. Mirkin 2019 103 1
FOX: Modular Approach to Crystal Structure Determination from Powder Diffraction V. Favre-Nicolin and R. Černý 2004 34 0
Crystal Gazer Shoaib Akram and Jennifer B. Sartor and K. McKinley and L. Eeckhout 2019 7 0
Crystal Reference Manual Version 3.0 M. Jacquemin and J. A. Yang 1991 3 0
3DStructGen: an interactive web-based 3D structure generation for non-periodic molecule and crystal Pin Chen and Yu Wang and Hui Yan and Sen Gao and Zexin Xu and Yangzhong Li and Qing Mo and Junkang Huang and Jun Tao and Gechuanqi Pan and Jiahui Li and Yunfei Du 2020 2 0
Simulation of a micro-milling single crystal copper process based on crystal plastic constitutive theory Luan Yihan and Meng Xiangyue and Xue Liang and S. Liang and L. Xiaohong 2020 1 0
arduino.html · crystal.html · actionscript.html

View source

PLDB - Build the next great programming language · v2022 · Day 32 · Docs · Build · Acknowledgements · Traffic Today · Traffic Trends · Mirrors · GitHub ·