Questions tagged [crystal-lang]

Crystal is a programming language with a Ruby inspired syntax but statically type checked and compiled to native and efficient code.

Links

Projects

660 questions
33
votes
2 answers

Anybody tried the Crystal Programming Language (machine-code compiled Ruby)?

Like many others, I always hold true that "A pure compiler will never exist for Ruby because the language is far too dynamic for a static compiler to work." But I recently stumbled upon these: The Crystal programming language at GitHub Statically…
AlexBottoni
  • 2,237
  • 20
  • 24
24
votes
1 answer

Why is Crystal faster than Ruby?

I would very much like to know what exactly makes Crystal faster than Ruby while code is so similar. The short answer could be that it is compiled, and Ruby is interpreted, yet I would like to understand more about the language specifications.
Marcelo Boeira
  • 860
  • 8
  • 22
20
votes
1 answer

Can a Crystal library be statically linked to from C?

I've read through the "C bindings" in the tutorial but I'm a novice at C stuff. Could someone please let me know if a Crystal program can be built as a static library to link to, and if so could you please provide a simple example?
Lye Fish
  • 2,538
  • 15
  • 25
18
votes
1 answer

How do I install crystal-lang on rapsberry pi?

When I try to add it to sources as per debian install instructions I get this error. I'm guessing this means that there are no arm packages for it. Failed to fetch https://dist.crystal-lang.org/apt/dists/crystal/InRelease Unable to find expected…
isaacsloan
  • 885
  • 6
  • 18
18
votes
2 answers

Is there an equivalent to Pry for Crystal?

I am very new in crystal language. I would like to know if a debugger like Ruby's Pry exists in Crystal? It means that you can put in code something like 'binding.pry' at program stop execution at this line and let you control of variables.
Voldemar Duletskiy
  • 981
  • 1
  • 11
  • 30
15
votes
6 answers

ld: library not found for -lssl

I installed crystal with homebrew brew install crystal-lang. I was able to compile and run a "Hello World!" program, but when I try to compile the example http server (with one slight modification) I get an error. HTTP server: require…
Jones
  • 1,154
  • 1
  • 10
  • 35
13
votes
2 answers

How can I produce a Crystal executable with no dependencies?

I'm writing a program in Crystal, that I intend to compile and move to other systems for execution. Ideally, it should have no dependencies, as the target systems will be fresh installations of linux. Sadly, I can't get around the libc dependency,…
Sod Almighty
  • 1,768
  • 1
  • 16
  • 29
11
votes
1 answer

How to convert a String to an Integer or Float in Crystal?

In Crystal, how can I convert a String to an Integer or Float? Using Python I can simply do the following: >>> nb = "123" >>> int(nb) 123 >>> nb = "1.23" >>> float(nb) 1.23 Are there any similar tools in Crystal?
Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
9
votes
1 answer

Why BigFloat.to_s is not precise enough?

I am not sure if this is a bug. But I've been playing with big and I cant understand why this code works this way: https://carc.in/#/r/2w96 Code require "big" x = BigInt.new(1<<30) * (1<<30) * (1<<30) puts "BigInt: #{x}" x = BigFloat.new(1<<30) *…
Ihor Tsykalo
  • 133
  • 1
  • 4
9
votes
1 answer

Read a single char from stdin without pressing enter

How can I read a single char from the console without pressing enter / return? In ruby I would just use: require 'io/console' input = STDIN.getch
Leonard Schütz
  • 517
  • 1
  • 7
  • 16
9
votes
1 answer

How do I create a class instance from a string name in Crystal?

I want the Crystal equivalent of this: clazz = 'ExampleClass'.constantize # Rails clazz = Object.const_get('ExampleClass') # pure Ruby obj = clazz.new
Alan Willms
  • 459
  • 1
  • 5
  • 7
8
votes
2 answers

Declare type of instance variable on controller

I have a crystal-lang project on Amber framework with Jennifer.cr and I'm getting this error on my controller: Can't infer the type of instance variable '@companies' of CompanyController @companies = Company.all The controller is: class…
Osmond
  • 345
  • 4
  • 9
7
votes
2 answers

Is there a way to see what a Crystal macro expands to?

I've a macro that refuses to work as expected and I was wondering if there was a way to see what it expands to, is there something like macroexpand-1 from lisp in Crystal? If so, how do I use it? Thanks!
Sunder
  • 1,445
  • 2
  • 12
  • 22
7
votes
3 answers

How to do user input in Crystal

puts "Input a number" A = gets.try(&.to_i) || 0 puts "Ok now another number" B = gets.try(&.to_i) || 0 def main puts "Value of multiplication is #{A} * #{B}, Which equals = #{A * B}" puts "Value of addition is #{A} + #{B}, Which equals =…
learncodes123
  • 371
  • 3
  • 16
7
votes
2 answers

When to use a class vs. module extending self in Crystal?

In Crystal, there's two different ways to achieve similar results: Creating a class... class Service def self.get # ... end end or a module extending self: module Service extend self def get # ... end end Both can invoke the…
vinibrsl
  • 6,563
  • 4
  • 31
  • 44
1
2 3
43 44