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
6
votes
1 answer

Crystal pass variable by reference or value

How do I choose how to pass a variable by value or reference using Crystal ? Exemple : I would like to pass a Struct by reference and not by Value ( the documentation explains that it is passed by Value while classes are passed by reference ).
6
votes
2 answers

Crystal multi line comment

Are there any multi line comments in Crystal ? Such as Ruby does : =begin this is a multiline comment in Ruby =end This will simply give me an error in Crystal : unexpected token: =
6
votes
1 answer

Crystal Lang Compiler Speed

I was just wondering about the compiler speed of the Crystal programming language. It feels relatively slow: ➜ ~/Code/crystal/crystal_scheduler (master ✘)✹✭ ᐅ time crystal build --release src/crystal_scheduler.cr 34.64s user 1.10s system 93% cpu…
tpei
  • 671
  • 9
  • 26
6
votes
1 answer

Crystal C bindings: return type char*

I have a function with this signature: const char* get_version(); My declaration is: fun get_version(): LibC::Char* And to use it: version = MyLib.get_version() puts version # how to convert to String? How can I manage the return string? Do I…
Mat
  • 2,156
  • 2
  • 16
  • 29
6
votes
1 answer

Convert hex string to int in Crystal

I want to convert an hex string value in a variable to int. This works for a literal: "#{0xFF}".to_i But with a var...? Not working test (interpolation error): _myvar = "FF" "#{0x_myvar}".to_i
Mat
  • 2,156
  • 2
  • 16
  • 29
6
votes
2 answers

Increase maximum virtual memory size above 256gb

I'm running a program which allocates 8mb stacks using mmap. While testing to see how many stacks I could allocate (aiming for 100,000), I see virtual memory size rise quickly as expected, and reserved size stay small (less than 1gb). The program…
Stephie
  • 3,135
  • 17
  • 22
6
votes
1 answer

Would one be able to use Ruby gems with Crystal?

Developers say that Crystal follows Ruby language syntax. So can I (or would I, in the future) just require a Ruby gem and it magically builds and properly working and so on?
Vlad Faust
  • 542
  • 6
  • 18
6
votes
1 answer

Shorthand block syntax in Crystal

Is it possible to use a shorthand for blocks in Crystal, e.g. my_array.sort_by(&:size) This attempt returns an error: ... expected a function type, not Symbol
Charlie Egan
  • 4,878
  • 6
  • 33
  • 48
6
votes
1 answer

Crystal lang, is it possible to explicitly dispose (free) of instance (object) without waiting for GC?

The title says it all. Maybe there's a method can be called like def destruct; delete self;end?
ClassyPimp
  • 715
  • 7
  • 20
6
votes
1 answer

Crystal language: what to use instead of runtime String::to_sym

I am trying to convert a Ruby program to Crystal. And I am stuck with missing string.to_sym I have a BIG XML file, which is too big to fit in memory. So parsing it all is out of question. Fortunately i do not need all information, only a portion of…
jsaak
  • 587
  • 4
  • 17
6
votes
1 answer

How to create Procs with variable arguments in Crystal?

I want to pass arguments to a Proc like using splat, but it returns an error wrong number of block arguments (1 for 0) $callbacks = {} of String => Array(->) def add_callback(event, &block) begin $callbacks[event.to_s] << block rescue …
Hugo Abonizio
  • 84
  • 1
  • 2
5
votes
3 answers

How to handle application level redirects in Nginx with Reverse Proxy

I am writing an Nginx configurations for Crystal-Lang based application to send all the traffic http://example.com/videos/ to http://0.0.0.0:3000 via reverse proxy. I have written the following config which is not working and I'm heading over the…
Mujtaba
  • 349
  • 1
  • 4
  • 17
5
votes
1 answer

How to read a file in Crystal?

I recently picked up on Crystal after being a Rubyist for a while, and I can't seem to find anything about the File class. I want to open and read a file, but it gives me an error. file = File.open("ditto.txt") file =…
tequila
  • 69
  • 4
5
votes
1 answer

Cycling between Fibers with no IO

As far as I know, crystal cycles Fibers with io, meaning that if one fiber is waiting for io, crystal will switch to an another fiber. What if we spawn two fibers but one of them does constant computation/loop with no io? For example, with the code…
Oguz Bilgic
  • 3,392
  • 5
  • 36
  • 59
5
votes
1 answer

Crystal-lang: why is the LLVM "hello.bc" not the same if generated by Crystal or by clang?

this is my first Stackoverflow question :-) My background: 2 years Python experience 2 months crystal-lang experience ( websites running with Amber framework ) 1 month into C, C++ , assembly Facts: - crystal-lang is compiling and running…
silmanduin
  • 53
  • 3
1 2
3
43 44