Crystal (programming language): Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 2:
 
==Description==
Although resembling the Ruby programming language in syntax, Crystal compiles to much more efficient native code using an [[LLVM]] backend, at the cost of disallowing the dynamic aspects of Ruby. Recent benchmarks have demonstrated that Crystal has a performance broadly similar to [[C (programming language)|C]] for a wide range of computing tasks.<ref>[https://github.com/kostya/benchmarks Some benchmarks of different languages]</ref><ref>[https://github.com/kostya/crystal-benchmarks-game Crystal implementations for The Computer Language Benchmarks Game]</ref><ref>[https://github.com/smarr/are-we-fast-yet/tree/master/benchmarks/Crystal Are We Fast Yet?]</ref> The language has automated garbage collection and currently offers a [[Boehm garbage collector|Boehm collector]]. Crystal possesses a macro system and supports generics and method and operator overloading. Crystal's concurrency model is inspired by [[Communicating sequential processes|communicating sequential processes]] (CSP), and implements light-weight fibers and channels (for communicating between fibers) inspired by the [[Go (programming language)|Go programming language]].
 
== Examples ==
Line 42:
puts "Listening on http://0.0.0.0:8080"
server.listen
</syntaxhighlight>
 
===Concurrency===
 
Channels can be used to communicate between fibers, which are initiated using the 'spawn' keyword.
 
<syntaxhighlight lang="ruby">
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
</syntaxhighlight>