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

How to control using CPU cores [Crystal]

I tried to run the same program on both Ruby and Crystal. In the program, there is no code which controls threads. As for Ruby, Only 1 core is used and the usage is 100% through the program as following screen shot indicates and the report of time…
elgoog
  • 77
  • 5
0
votes
1 answer

Crystal If doesn't work

I have the following function def fcn(lst) if (lst.size == 0) return [] of Int32 end lc = lst.map{|a| a[1]} end When doing: lst = [] of Int32 puts(fcn(lst)) I get: Error in line 8: instantiating 'fcn(Array(Int32))' in line 5:…
user3166747
  • 284
  • 4
  • 11
0
votes
1 answer

Failing to send multiple files with curl to send-anywhere.com

I was trying to build a CLI tool in Crystal to use send-anywhere.com from the command line. Sending multipart is not builtin in Crystal but before writing my own I thought I would try to use cURL to see how exactly I should make it but I can't even…
ItsASecret
  • 2,589
  • 3
  • 19
  • 32
0
votes
1 answer

Errors when running Crystal Play

I have check and libevent is installed, GCC is installed. LLVM is updated. Running Crystal Play works and then crashes with the below error. I can see the localhost output. But it will try to run the code then it will crash. Configured with:…
codedownforwhat
  • 173
  • 2
  • 14
0
votes
1 answer

Can variable type in Crystal lang be restricted to classes that inherit from one class

I mean: class Foo; end class Bar < Foo; end class Cux < Foo; end Is it possible to restrict type of the variable to classes inheriting from Foo without unions, something like x : Foo+?
ClassyPimp
  • 715
  • 7
  • 20
0
votes
1 answer

why is the assignment of instance variables to local variables is need in crystal?

In Crystal compiler source code I've seen such code def dirname filename = @filename if filename.is_a?(String) File.dirname(filename) else nil end end def original_filename case filename = @filename when String filename …
Oleh Devua
  • 364
  • 6
  • 12
0
votes
1 answer

Split string into array with regex but without removing the matches

In python I can do: import re re.split('(o)', 'hello world') and get: ['hell', 'o', ' w', 'o', 'rld'] With crystal: "hello world".split(/(o)/) I get: ["hell", " w", "rld"] But I want to keep the matches in the array like in the python example.…
xd1le
  • 182
  • 2
  • 8
-1
votes
1 answer

How to return self in Crystal

I'm a newbie in Crystal. I'm trying to return self in Crystal, like in this Python: class Something: def some_method(): # do something return self
bichanna
  • 954
  • 2
  • 21
-1
votes
1 answer

How would i extract bits in crystal

How would i extract bits of a hex number in crystal lang which is mostly like ruby because i am able to extract a byte but i cannot extract 4 bits of one cause that is what i need to do here is what I want to extract. 0x0312FCFC ------^^(the 1 and…
xd-sudo
  • 1
  • 1
-1
votes
1 answer

How to create a tuple using constructor inside macro in crystal lang

I am trying to create a empty tuple inside macro but getting error - Error: undefined macro method 'TypeNode#new' {% empty_tuple = Tuple.new %} Here is link to crystal play - https://play.crystal-lang.org/#/r/8mxf If i can't do this way, please…
Ujjwal Kumar Gupta
  • 2,308
  • 1
  • 21
  • 32
-1
votes
1 answer

How to use Rollbar.com with in Crystal Lang

I would like to use rollbar.com in my Crystal project. I can not find crystal integration with rollbar.com or any other error trackers. Is there a shard for the Rollbar or similar services (error tracking)?
-1
votes
1 answer

Issue inferring type for generic

I have a c library that I bind to, which has many structs that hold data of different types. @[Link("foo")] lib LibFoo struct IntStruct data : LibC::Int end struct DoubleStruct data : LibC::Double end fun get_int_struct(n :…
user3483203
  • 50,081
  • 9
  • 65
  • 94
-1
votes
2 answers

Method argument of an unknown type

I'm trying to write a utility library which tries to call a method on an arbitrary object type. In ruby, I'd do something like: def foo(object) object.public_send(:bar) rescue NoMethodError raise "Method not defined on…
Daniel Westendorf
  • 3,375
  • 18
  • 23
-2
votes
1 answer

context.response.print doesnt print the output

is there any something wrong with dynamic hash definition ?, why the response print doesnt give me the output, but when i give a comment to the first line, the response print sending a output res.headers.each { |k, v| context.response.headers[k] = v…
jihantoro
  • 33
  • 1
  • 4
-3
votes
1 answer

.get method for hash in Crystal language

I have this Python code: # some_dic is a dictionary value = some_dic.get(var_name, None) How can I do the same in Crystal?
bichanna
  • 954
  • 2
  • 21
1 2 3
43
44