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
7
votes
2 answers

Timers/Intervals in Crystal Lang

Is there a timer or interval function in Crystal? I checked the docs for a timer, interval, and under the Time class, but did not see anything. Something like setInterval() or setTimeout() from JavaScript?
dkimot
  • 2,239
  • 4
  • 17
  • 25
7
votes
1 answer

How to check if a constant is defined in Crystal

I need to verify if a constant is defined to do a conditional. I was trying this but "defined" method not exists on this language: if defined(constant) value = :foo else value = :bar end
Osmond
  • 345
  • 4
  • 9
7
votes
1 answer

Recursive Proc in Crystal

Is recursive proc posible in Crystal? Something like lambda in Ruby I'm trying to do a y-combinator in Crystal,something like Ruby one: puts -> { fact_improver = ->(partial) { -> (n) { n.zero? ? 1 : n * partial.(n-1) } } y = ->(f) { …
Faustino Aguilar
  • 823
  • 6
  • 15
7
votes
1 answer

Crystal C binding, simple hello world example.

I’m trying to figure out how c bindings in crystal work. For starters I’m wondering how I would include a simple hello world c function into crystal. Always good to start with the basics right? Here’s the function I’d like to include: #include…
Jake
  • 248
  • 2
  • 11
7
votes
3 answers

How to execute a shell script in Crystal while capturing output?

I want to execute a shell script while handling stdout and stderr output. Currently I execute commands using Process.run, with shell=false and three pipes for stdin, stdout and stderr. I spawn fibers to read from stdout and stderr and log (or…
Sod Almighty
  • 1,768
  • 1
  • 16
  • 29
7
votes
1 answer

Is it possible to create Crystal binds for Ruby?

I'm creating a m3u8 generator/parser for crystal, yet I want to use it later with ruby. Is that possible/easy to do it?  
Marcelo Boeira
  • 860
  • 8
  • 22
7
votes
2 answers

How to specify the data types for JSON parsing?

I have a JSON response which is an Array of Hash: [{"project" => {"id" => 1, "name" => "Internal"}, {"project" => {"id" => 2, "name" => "External"}}] My code looks like this: client = HTTP::Client.new(url, ssl: true) response =…
Kris
  • 19,188
  • 9
  • 91
  • 111
7
votes
2 answers

Crystal convert the idea behind Thread pool to Fibers/spawn

I'm having some hard time learning the idea behind Fibers\coroutines and the implementation in Crystal. I hope this is the right place to ask this, I'll totally accept a "not here" answer :) This is my usual way of handling multi-threading in…
Ba7a7chy
  • 1,471
  • 4
  • 14
  • 29
6
votes
1 answer

Crystal-lang Accessing Serial port

I want to access the serial port using Crystal lang. I have following code in python. I want to write the equivalent Crystal-lang code for a pet project. import serial def readSerData(): s = ser.readline() if s: print(s) …
girish946
  • 745
  • 9
  • 24
6
votes
1 answer

How to free memory allocated for some structure in Crystal - manually?

I have a Kemal-based RESTful web service that returns "very big" (from 10 to 17M in size) chunks of JSON data, which is produced by to_json method from the "big" Hash structure. According to GC warning messages my code "may lead to memory leaks"…
drvtiny
  • 705
  • 3
  • 13
6
votes
2 answers

How to concatenate bytes in Crystal

I'm testing about serialization with bytes or slices, just learning and trying. I would like to bind 3 parameters in a single 10 bytes field, but I don't now how to concatenate them in Crystal or whether it is possible. I know I can achieve this by…
Samuel
  • 105
  • 6
6
votes
3 answers

What is a proc in Crystal Lang?

I read the documentation on Procs in the Crystal Language book on the organizations’s site. What exactly is a proc? I get that you define argument and return types and use a call method to call the proc which makes me think it’s a function. But why…
dkimot
  • 2,239
  • 4
  • 17
  • 25
6
votes
1 answer

Crystal equivalent to algebraic data types

What is the idiomatic way to write the equivalent of an algebraic data type in Crystal? E.g. In Haskell I might have data Stage = StageInitial String | StageFinished String So I want to have two stages, each which has a string payload. Later on I…
Sebastian
  • 2,249
  • 17
  • 20
6
votes
2 answers

Starting crystal in production mode

I've been running my Crystal webapp by building it, and then running the executable. However, it always listens on port 3000. How do I build/run Crystal webapps listening on 80 and 443? I'm using Kemal as well. Here is my sample app. require…
Tyler
  • 19,113
  • 19
  • 94
  • 151
6
votes
1 answer

How to Deploy an Amber App on Ubuntu?

Just discovered Amber...looks nice! How can I deploy a sample App on an Ubuntu Server? Should it be done just like Rails, routing the path to public? Or some other part of the structure? Thanks for your advice.
Werner
  • 139
  • 10
1
2
3
43 44