Movatterモバイル変換


[0]ホーム

URL:


GitHub RepositoryForumRSS-Newsfeed

Crystal

A language for humans and computers
Latest release:1.19.1
InstallGet StartedTry Online

Examples

Crystal is a general-purpose, object-oriented programming language.With syntax inspired by Ruby, it’s a compiled language with static type-checking.Types are resolved by an advanced type inference algorithm.

# A very basic HTTP serverrequire"http/server"server=HTTP::Server.newdo|context|context.response.content_type="text/plain"context.response.print"Hello world, got#{context.request.path}!"endaddress=server.bind_tcp(8080)puts"Listening on http://#{address}"# This call blocks until the process is terminatedserver.listen

Batteries included

Crystal’s standard library comes with a whole range of libraries that let you start working on your project right away.

require"http/client"require"json"response=HTTP::Client.get("https://crystal-lang.org/api/versions.json")json=JSON.parse(response.body)version=json["versions"].as_a.find!{|entry|entry["released"]?!=false}["name"]puts"Latest Crystal version:#{version||"Unknown"}"

Type system

The compiler catches type errors early. Avoids null pointer exceptions at runtime.

The code is still clean and feels like a dynamic language.

defadd(a,b)a+bendadd1,2# => 3add"foo","bar"# => "foobar"

Flow typing

The compiler tracks the type of variables at each point,and restricts types according to conditions.

loopdocasemessage=gets# type is `String | Nil`whenNilbreakwhen""puts"Please enter a message"else# In this branch, `message` cannot be `Nil` so we can safely call `String#upcase`putsmessage.upcaseendend

Concurrency Model

Crystal uses green threads, called fibers, to achieve concurrency.Fibers communicate with each other via channels without having to turn to shared memory or locks (CSP).

channel=Channel(Int32).new3.timesdo|i|spawndo3.timesdo|j|sleeprand(100).milliseconds# add non-determinism for funchannel.send10*(i+1)+jendendend9.timesdoputschannel.receiveend

C-bindings

Bindings for C libraries makes it easy to use existing tools.Crystal calls lib functions natively without any runtime overhead.

No need to implement the entire program in Crystal when there are alreadygood libraries for some jobs.

# Define the lib bindings and link info:@[Link("m")]libLibMfunpow(x:LibC::Double,y:LibC::Double):LibC::Doubleend# Call a C function like a Crystal method:putsLibM.pow(2.0,4.0)# => 16.0

Macros

Crystal’s answer to metaprogramming is a powerful macro system, which ranges from basic templating and AST inspection, to types inspection and running arbitrary external programs.

macroupcase_getter(name)def{{name.id}}@{{name.id}}.upcaseendendclassPersonupcase_getternamedefinitialize(@name:String)endendperson=Person.new"John"person.name# => "JOHN"

Dependencies

Crystal libraries are packed withShards, a distributed dependency manager without a centralised repository.

It reads dependencies defined inshard.yml and fetches the source code from their repositories.

name:hello-worldversion:1.0.0license:Apache-2.0authors:-Crys <crystal@manas.tech>dependencies:mysql:github:crystal-lang/crystal-mysqlversion:~>0.16.0

News

Crystal talk at FOSDEM 2026
Johannes Müller
Community#events#talk#community#foss#fosdem

Johannes is speaking about Crystal at FOSDEM 2026 in Brussels.

Wind of change (or maybe not)
Beta Ziliani
Community#people#team

Beta is stepping down from the lead position, which Johannes will take

Crystal Compass
Johannes Müller
Community#Crystal Compass#ecosystem#Manas.Tech

The team behind the language, on your team

Margret Riegert joins the Core Team
Beta Ziliani
Project#people#core-team

With great pleasure we announce that Margret Riegert (nobodywasishere) has joined theCrystal Core Team.

More newsFeedRelease notes

Sponsorship

Become a Crystal sponsor in only 3 simple steps via OpenCollective

Contribute
Enterprise support

Sponsoring Crystal creates a great springboard for your brand

Get Support
Hire us for your project

You can tap into the expertise of the very creators of the language to guide you in your implementation.

Hire Us

Top Sponsors

84codesManas.Tech
PlaceOS

Success stories

Section titled Success stories
84codesLavinMQ: Understanding code to get the best performanceBright SecurityCrystal: thelingua franca at BrightPlaceOSAutomating smart buildings with Crystal
More success storiesUsed in productionCrystal Compass

Found a typo, or want to help improve this page?Edit on GitHub orfile an issue.


[8]ページ先頭

©2009-2026 Movatter.jp