Crystal 详细介绍

转自:https://www.oschina.net/p/crystal-lang

Crystal 详细介绍

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 + 1true)
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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值