Crystal 是一个编译型的编程语言。特性:
语法类似 Ruby Ruby-inspired syntax.
无需指定变量类型和方法参数类型 Never have to SPEcify the type of a variable or method argument.
可以调用 C 代码 Be able to call C CODE by writing BINDings to it in Crystal.
编译时代码模拟和生成 Have comPILe-time evaLuation and geneRATion of code, to avoid Boilerplate code.
编译成高效的本机代码 Compile to efficIEnt native code.
示例代码:
# Compute prime numbers up to 100 with the Sieve of Eratosthenes
max = 100
sieve = Array.new(max + 1, true)
sieve[0] = false
sieve[1] = false
(2...max).each do |i|
if sieve[i]
(2 * i).step(max, i) do |j|
sieve[j] = false
end
end
end
sieve.each_with_index do |prime, number|
puts number if prime
end
发布于 2015-09-21 01:22:14 | 175 次阅读
发布于 2015-05-01 23:58:59 | 166 次阅读