像许多其他人一样,我总是认为"对于Ruby来说,纯粹的编译器永远不会存在,因为这种语言对于静态编译器来说太过动态了."
但我最近偶然发现了这些:
这两个项目似乎都非常有趣.它们可以为我们提供本机编译语言的速度(以及编译语言的商业需求,混淆代码),同时保留Ruby的所有(或大部分)优雅和灵活性.添加一个好的支持库(或者更可能是访问现有C++库的可能性),你可以很容易地理解为什么这些东西会很有趣.
有人试过Crystal语言吗?(我还没有,因为ruby-llvm的编译问题)
这是他/她对此的感受?
您是否认为,鉴于这些设计选择,实际上是否可以为Ruby开发本机代码(机器代码)编译器(在合理的时间内合理努力)?它会有意义吗?
我已经阅读了教程中的"C绑定",但我是C的新手.
有人可以告诉我,如果一个Crystal程序可以构建为一个静态库来链接,如果可以的话,请你提供一个简单的例子吗?
我非常想知道究竟是什么让Crystal比Ruby更快,而代码非常相似.简短的回答可能是它被编译,Ruby被解释,但我想更多地了解语言规范.
当我尝试按照debian安装说明将其添加到源时,我收到此错误.我猜这意味着它没有手臂包.
无法获取https://dist.crystal-lang.org/apt/dists/crystal/InRelease 无法在发布文件中找到预期的条目'main/binary-armhf/Packages'(错误的sources.list条目或格式错误的文件)
我猜我可能需要从源代码安装它.我怎么会用arm cpu做这件事?当我检查并运行时,make
我收到错误:
你需要在你的道路上有一个水晶可执行文件!Makefile:113:目标'.build/crystal'的配方失败make:***[.build/crystal]错误1
任何建议将不胜感激.
我是水晶语言的新手.我想知道Crystal中是否存在类似Ruby的Pry的调试器?
这意味着您可以在此行的程序停止执行时输入类似"binding.pry"的代码,并让您控制变量.
我正在用Crystal编写一个程序,我打算编译并移动到其他系统执行.理想情况下,它应该没有依赖关系,因为目标系统将是linux的全新安装.
遗憾的是,我无法绕过libc依赖,所以我可能必须在拥有我希望定位的最低版本libc的系统上编译可执行文件.我认为它应该是向前兼容的.
但是,我对libssl有困难.Debian Wheezy的默认安装似乎没有附带libssl,因此运行我的可执行文件时出现此错误:
error while loading shared libraries: libssl.so.1.0.0:
cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我认为这种依赖存在,因为我require "http/client"
在我的源代码中.但是,我没有进行与ssl相关的调用,因为我只使用它连接到不安全的网站.
我显然也有依赖libevent-2.0.so.5
.据推测,所有Crystal程序都可以.谁知道Crystal有多少其他依赖?
我的可执行文件必须在新安装的Linux系统上运行.那么,如何生成没有依赖项的Crystal可执行文件?我认为除了libc之外.
我和Jennifer.cr在Amber框架上有一个水晶项目,我在我的控制器上收到了这个错误:
Can't infer the type of instance variable '@companies' of CompanyController
@companies = Company.all
Run Code Online (Sandbox Code Playgroud)
控制器是:
class CompanyController < ApplicationController
def index
@companies = Company.all
render("index.slang")
end
end
Run Code Online (Sandbox Code Playgroud)
当我尝试以这种方式解决问题时:
class CompanyController < ApplicationController
def index
@companies : Array(Company) = Company.all
render("index.slang")
end
end
Run Code Online (Sandbox Code Playgroud)
我有另一个错误:
instantiating 'CompanyController#index()'
in src/controllers/company_controller.cr:7: declaring the type of an instance variable must be done at the class level
@companies : Array(Company) = Company.all
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个"简单"问题?
我很难学习Fibers\coroutines背后的想法和Crystal中的实现.
我希望这是一个正确的问题,我完全接受"不在这里"的答案:)
这是我在Ruby中处理多线程的常用方法:
threads = []
max_threads = 10
loop do
begin
threads << Thread.new do
helper_method(1,2,3,4)
end
rescue Exception => e
puts "Error Starting thread"
end
begin
threads = threads.select { |t| t.alive? ? true : (t.join; false) }
while threads.size >= max_threads
puts 'Got Maximum threads'
sleep 1
threads = threads.select { |t| t.alive? ? true : (t.join; false) }
end
rescue Exception => e
puts e
end
end
Run Code Online (Sandbox Code Playgroud)
这样我打开一个新的线程,通常是传入的连接或其他东西,将线程添加到线程数组,然后检查我没有更多的线程,然后我想要的.
使用spawn\channels\fiber等在Crystal中实现类似功能的好方法是什么?
我正在为水晶创建一个m3u8生成器/解析器,但我想稍后使用ruby.这可能/容易吗?
我不确定这是不是一个bug.但我一直在玩,big
我不明白为什么这段代码以这种方式工作:
码
require "big"
x = BigInt.new(1<<30) * (1<<30) * (1<<30)
puts "BigInt: #{x}"
x = BigFloat.new(1<<30) * (1<<30) * (1<<30)
puts "BigFloat: #{x}"
puts "BigInt from BigFloat: #{x.to_big_i}"
Run Code Online (Sandbox Code Playgroud)
产量
BigInt: 1237940039285380274899124224
BigFloat: 1237940039285380274900000000
BigInt from BigFloat: 1237940039285380274899124224
Run Code Online (Sandbox Code Playgroud)
首先,我认为BigFloat需要更改 BigFloat.default_precision
为更大的数字.但是从这段代码看起来它只在尝试输出#to_s
值时才有意义.
与BigFloat的精度设置为1024(https://carc.in/#/r/2w98)相同:
产量
BigInt: 1237940039285380274899124224
BigFloat: 1237940039285380274899124224
BigInt from BigFloat: 1237940039285380274899124224
Run Code Online (Sandbox Code Playgroud)
BigFloat.to_s
用途LibGMP.mpf_get_str(nil, out expptr, 10, 0, self)
.GMP在哪里说:
mpf_get_str (char *str, mp_exp_t *expptr, int base, size_t n_digits, const mpf_t op)
将op转换为基数中的数字字符串.基本参数可以在2到62之间或从-2到-36之间变化.最多将生成n_digits数字.不返回尾随零.不会产生比op准确表示的数字更多的数字. …