<FromGitter>
<codenoid> mmm, why has not anyone written a book about crystal (about the crystal itself, not about ruby), like "Nim in Action" for the nim language, etc.
<FromGitter>
<codenoid> there was my friend asking about that 😄
snsei has quit [Read error: Connection reset by peer]
snsei has joined #crystal-lang
snsei1 has quit [Ping timeout: 240 seconds]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
DTZUZO has joined #crystal-lang
bmcginty has quit [Ping timeout: 260 seconds]
bmcginty has joined #crystal-lang
<FromGitter>
<fridgerator> anyone ever see a `Killed` error running a web server?
<FromGitter>
<fridgerator> nvmd, dmesg tells me i'm running out of memory
raz has quit [Ping timeout: 246 seconds]
raz has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
weston1 has joined #crystal-lang
<FromGitter>
<faustinoaq> Hi I just realize some people do like Null Errors 😅 ⏎ ⏎ > Sure, Kotlin has some nifty features, but it sacrifices readability for writing shorter code. Apply and run blocks are a good idea but in practice your code just looks very compressed and not easily readable. The forced null safety is also a bad thing [0] ⏎ ⏎ https://medium.com/@bramhaag/sure-kotlin
<FromGitter>
<marin117> hmm, I get some weird characters :(
<FromGitter>
<marin117> ??@ to be precise
<FromGitter>
<bararchy> Guess it was not suppose to be a string then
<FromGitter>
<bararchy> hahah
<FromGitter>
<bararchy> maybe it's in a specific Time format ?
<FromGitter>
<bararchy> not sure
<FromGitter>
<marin117> It is fun cause I write Time format in timestamp
<FromGitter>
<marin117> and as query result "this"
<FromGitter>
<marin117> :D
<FromGitter>
<crisward> @marin117 check the driver to make sure it has a time type. I implemented it in the Mysql Driver and it's binary there, with bytes for year, month, day etc... There is also a different format again for time spans, ie when you get the difference between two times. If it doesn't have a type parser within the driver, you may just be getting the raw bytes back.
<FromGitter>
<marin117> this could be the problem, yes, cause I really need time diff, not exact time, more like, I need sum of time diffs and it is little complicated
claudiuinberlin has joined #crystal-lang
mark_66 has joined #crystal-lang
claudiuinberlin has quit [Client Quit]
snsei has quit [Remote host closed the connection]
Groogy has quit [Disconnected by services]
Groogy_ is now known as Groogy
<Groogy>
Lol I just accidentally wrote a template in C++ like it was a Crystal generic
Groogy2 has joined #crystal-lang
<Groogy>
and was confused over the compilation errors
<Groogy>
YAML::Type is a union, I would guess the same applies to JSON?
<Groogy>
or wait it is result
claudiuinberlin has joined #crystal-lang
<Groogy>
result can from me reading the code be either Nil, { "success" => true , "data" => @@store[key].call(value.as(Hash)) } or {"success" => false, "data" => nil}
<Groogy>
that's why it is a union
claudiuinberlin has quit [Client Quit]
<Groogy>
and the type between the two Hashes are also two different types
claudiuinberlin has joined #crystal-lang
<FromGitter>
<bew> @ansarizafar why do your `Tools.json_param` returns some json types?
<FromGitter>
<ansarizafar> @bew Tools.json_param is extracting an object from context.request.body and returning it as a hash. I am trying to port my Graphql inspired data layer library from Nodejs.
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<ansarizafar> Is it possible to define a proc without defining the return type in advance but returning a value. This is important If we can't determine a return value in advance.
<FromGitter>
<bew> iirc you can say `def foo(&bar : String -> _)` to say that the block takes a `String` and return something, but it can be anything. However, if you want to store the proc (e.g: in a Hash), you'll need to know the return type if I remember correctly
<FromGitter>
<bew> although I don't why you need to know all the proc's types to store it..
<FromGitter>
<ansarizafar> Related question is it possible to define a hash without defining types
<FromGitter>
<bew> heee no
<FromGitter>
<bew> @ansarizafar here is your `Api.run` method a bit cleaner I think: ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Do whatever you want with this. From this you just need to fix the type problem and it should work [https://gitter.im/crystal-lang/crystal?at=59c8cc8fcfeed2eb65493e00]
<FromGitter>
<bew> you can remove `self.` from `self.new` (as it is called from a class method, it will automatically call other class methods), otherwise it looks ok!
<FromGitter>
<bew> you're making a singleton right?
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<imonmyown> I have a problem with it
<FromGitter>
<imonmyown> Yeah, a singleton
<FromGitter>
<bew> what problem?
<FromGitter>
<imonmyown> ```Can't infer the type of class variable '@@generator' of Generator```
<FromGitter>
<bew> oh right, you need to tell him the type of `@@generator`, in this case it's a `Generator`
<FromGitter>
<bew> just add `@@generator : Generator` somewhere in the class, to tell the compiler that this class variable has a specific type
<FromGitter>
<bararchy> but if it's not the "whole body" , then I guess you will need to extract and parse it out
<FromGitter>
<bararchy> via Regex or rules you decided uppon
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter>
<crisward> If you know the structure of the data, it's not a bad idea to create a class with JSON.mapping. You can the just `res = Myclass.from_json(response.body)` Which will give you an object for your response.
<FromGitter>
<marin117> @bararchy it is working, thank you :) ⏎ ⏎ @crisward I will consider that, it is good idea for sure
<FromGitter>
<marin117> (code design does not depend on me, so ...)
claudiuinberlin has joined #crystal-lang
<FromGitter>
<OldhamMade> Hey all. I'm trying to use the waterlink/mocks.cr library to mock Dir.glob so that it returns a fixed Array for testing, however I'm unable to actually get the mock to apply. Would anyone know the correct way to mock and call it so that I can control the result in my specs?
<FromGitter>
<OldhamMade> I've seen mocks work with File.exists?, but that only has one definition in the source. Dir.glob has 4, and the mocks I'm applying don't seem to match the way it's being called.
<FromGitter>
<bararchy> you can jusr redifine it in your spec
<FromGitter>
<bew> with `self.glob(*patterns) : Array(String)`
<FromGitter>
<OldhamMade> @bew thanks – I assumed it was something to do with the `*patterns` but I wasn't sure how to approach that.
<FromGitter>
<bew> don't miss the `*` @OldhamMade in you mock
<FromGitter>
<bew> ;)
<FromGitter>
<OldhamMade> is the `*` similar to python's `*args`? eg. collect all arguments
<FromGitter>
<bararchy> Thanks @bew
<FromGitter>
<bew> yes
<FromGitter>
<OldhamMade> perfect, that makes sense
<FromGitter>
<bew> yw!
<FromGitter>
<OldhamMade> so would this be the preferred approach, rather than using the `mock.cr` library?
<FromGitter>
<OldhamMade> and would it even be possible using that lib?
<FromGitter>
<bew> I think it should work yes
<FromGitter>
<OldhamMade> I'm going to write this up to help other people coming to Crystal from non-ruby backgrounds
<FromGitter>
<bararchy> It's better because it's clearer and less depends
<FromGitter>
<OldhamMade> I found that doing something like the following would fail to build: ⏎ ⏎ ```Mocks.create_mock Dir do ⏎ mock self.glob(*patterns) ⏎ end``` ⏎ ⏎ and `mock self.glob` failed to patch [https://gitter.im/crystal-lang/crystal?at=59c8f0a2bac826f054f7e9e6]
<FromGitter>
<bew> hmmm you're calling it with a block, that's different than calling it without, and the method signature is different, not sure how to mock a method with block with that library
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<OldhamMade> ah, I didn't realize that would have an effect
<FromGitter>
<bew> maybe you can simply mock `find_files` ?
<FromGitter>
<OldhamMade> find_files is the thing I want to test :)
<FromGitter>
<bew> not sure it's a good idea, but you could run it, and compare with a real call to Dir.glob? as it doesn't have side-effect, it should be ok I think
<FromGitter>
<OldhamMade> yeah, I considered creating some files within my specs dir to glob against, but I wanted a bit more control to fully exercise the function
<FromGitter>
<OldhamMade> I'm also taking it as an opportunity to properly learn how to mock correctly in Crystal :D
claudiuinberlin has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
<FromGitter>
<OldhamMade> ok, I've changed my impleme
<FromGitter>
<OldhamMade> would be nice to understand how to handle calling it with a block, to keep code terse in the future
rohitpaulk has joined #crystal-lang
<FromGitter>
<mverzilli> did you try `Dir.glob(patterns).each do [ etc...]`
<FromGitter>
<bew> no idea how to do that with the mock lib..
<FromGitter>
<bew> could also be written using `yield` https://carc.in/#/r/2ski (this is block forwarding)
<FromGitter>
<OldhamMade> @mverzilli not explicitly, but assigning to `files` first is pretty-much the same
snsei has joined #crystal-lang
<FromGitter>
<crisward> If you work out how to mock correctly in crystal, let me know. 😉
<FromGitter>
<OldhamMade> @bew thanks for those examples! I'm not from a Ruby background, so I'll have to get myself used to blocks
<FromGitter>
<OldhamMade> @crisward I think you'll get there way before I do!
<FromGitter>
<OldhamMade> right, back to the paying job. thanks @everyone for the assistance!
<FromGitter>
<crisward> @OldhamMade if you understand callbacks in node, blocks are the same, only you can't as easily pass the block around, though they can be converted to proc's to do that more easily. Think crystal book has something about it...
<FromGitter>
<crisward> BTW you from Oldham?
snsei has quit [Ping timeout: 246 seconds]
<FromGitter>
<sdogruyol> he's definitely from UK lol
bmcginty has quit [Ping timeout: 240 seconds]
<FromGitter>
<bew> (from somewhere 😂)
sasdsadasd has joined #crystal-lang
sasdsadasd has quit [Client Quit]
bmcginty has joined #crystal-lang
alex`` has joined #crystal-lang
alex`` is now known as alexherbo2
alexherbo2 is now known as alex``
rohitpaulk has quit [Ping timeout: 246 seconds]
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
claudiuinberlin has joined #crystal-lang
sz0 has joined #crystal-lang
hightower4 has joined #crystal-lang
<FromGitter>
<exts> how do you capture a block within a macro to be passed to a class method?
hightower3 has quit [Ping timeout: 255 seconds]
snsei has joined #crystal-lang
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<asterite> However in your example you don't need the macro at all, you can probably use a method
<FromGitter>
<exts> yeah I know, it's just an example that I wrote to be as simple as possible
<FromGitter>
<exts> ah well, guess I'll wait for that to get sorted.
ShalokShalom has quit [Ping timeout: 260 seconds]
salvor has joined #crystal-lang
claudiuinberlin has joined #crystal-lang
<FromGitter>
<imonmyown> Hey guys
<FromGitter>
<imonmyown> What code is generally put into `finalize`?
<FromGitter>
<bararchy> So crystal-tensorflow or tensorflow.cr ?
<FromGitter>
<bararchy> For repo name for Tensor flow lib binding
rohitpaulk has joined #crystal-lang
<FromGitter>
<bew> I like the last one
<FromGitter>
<imonmyown> tensorflow in crystal sounds interesting
<FromGitter>
<imonmyown> On my question above: I want to ensure some data is written to a file when an object is destroyed, do I use `finalize` for that purpose or there's a better and more idiomatic way?
<FromGitter>
<bararchy> def close .. f.sync .. f.close .. end
<FromGitter>
<imonmyown> @bew so there's no way to do that even with finalize?
<FromGitter>
<bararchy> And call close
<FromGitter>
<bew> `finalize` will not always run! It will run only when the GC is about to collect an object, but not when the program closes for example
<FromGitter>
<imonmyown> right, didn't think about that
<FromGitter>
<bew> @bararchy s/../;/g
<FromGitter>
<bararchy> Hahaha yeha , was just to show the overall idea
<FromGitter>
<imonmyown> I probably didn't succeed in providing a clear explanation of what I'm trying to do, let me hack up some code...
<FromGitter>
<mverzilli> @asterite sounds good to me :). I was just waiting for the work on YAML to end mainly because the work put on the original PR was insane and it'd be a pity to have it wait until 0.25
<FromGitter>
<asterite> :)
<FromGitter>
<asterite> Yeah, the YAML PR is pretty much done :-D
<oprypin>
i've been noticing that PRs get tagged as "Next" after they're merged
<oprypin>
why not add that tag to PRs that are wanted before the next release, before merging them
<FromGitter>
<asterite> But that's missing work, namely using `Random::Secure` instead of `Random::System`
<FromGitter>
<jwaldrip> I would love for the YAML PR to get in. It looks good to me as it stands. I think the next big step for YAML before 1.0 would be to support a native crystal parser.
<FromGitter>
<bew> @mverzilli can you add the mentioned issues to the `Next` milestone so we can better track when it will be done, and what needs work until next release?
<oprypin>
asterite, no it's not missing work
<FromGitter>
<asterite> @jwaldrip Why do we need a native crystal parser?
<FromGitter>
<jwaldrip> Why not?
<oprypin>
if u feel strongly about the name, u can change that yourself. and i guess you two do agree to that
<oprypin>
but really it's a separate change
<FromGitter>
<bew> ah oprypin I see we're thinking the same here about the Next milestone ^^
<oprypin>
the pull request does not change that name
<FromGitter>
<asterite> @jwaldrip Because it's bug-prone, more code to compile and more work on us
<FromGitter>
<asterite> @oprypin I see. Yes, we can always merge that and later do the rename, it will be easier to review too :-)
<Groogy>
might as well piggyback ride on someone dedicated to maintaining the parser
<FromGitter>
<mverzilli> @oprypin because most of the time we don't care if a PR gets in "current + 1" or "current + 2" release
<oprypin>
not sure about merging process, i'd like it to be squashed in a particular way
<FromGitter>
<jwaldrip> I would love to see crystal to move to being less dependent on libraries. If you look at the route Go took, it has made the language more portable. Right now getting a portable crystal binary is MUCH harder than getting a portable Go binary
<oprypin>
mverzilli, most of the time you don't, but you just said that this time you clearly do
<FromGitter>
<jwaldrip> Getting Crystal to run on alpine linux in a process. Where as with go, once built, it runs anywhere.
<FromGitter>
<asterite> Yes, but Go can compile a file into a binary. Crystal can't do that. So more code means more time to compile stuff.
<oprypin>
jwaldrip, it's a lot of work, u know
<FromGitter>
<mverzilli> yes, agree that in this case we could do that, just arguing against making it the general practice
<FromGitter>
<jwaldrip> What do you mean compile a file into a binary?
<Groogy>
it can't create object files
<FromGitter>
<mverzilli> because ideally we should be able to release more less monthly (and before you mention that, I'm aware we've failed to do so in the last 2 or 3 releases)
<Groogy>
it needs the entire context of all the code to generate the binary
<FromGitter>
<jwaldrip> Go "can" have library deps. It just doesnt in the standard library.
<FromGitter>
<bew> @jwaldrip in Go, you can have 1 file <=> 1 binary file. In Crystal it more all files <=> 1 binary file (iirc)
<FromGitter>
<jwaldrip> Im just saying, it would be ideal if the crystal standard library became all native, one day...
<FromGitter>
<asterite> And I'm just saying that if that happens one day, compiling a "Hello world" program would take 1 minute :)
<FromGitter>
<jwaldrip> Why would it take one minute?
<FromGitter>
<asterite> Because it would need to parse and type the whole program
<FromGitter>
<jwaldrip> What does that have to do with a YAML parser?
<oprypin>
nothing
<FromGitter>
<jwaldrip> Maybe I dont understand Crystal... The more source code in crystal the longer it will take for programs to compile?
<oprypin>
it's a separate discussion
<FromGitter>
<asterite> Well, you do `require "yaml"` and instead of taking 1 second to compile it would take 3 or 4 seconds
<oprypin>
oh nvm
<FromGitter>
<asterite> If we change EVERYTHING to be written in Crystal, every program that requires anything will take more time to compile
<FromGitter>
<asterite> Like, decoding dwarf stack frames is now done in Crystal, and compile times grew
<Groogy>
I can already notice it in my framework
<FromGitter>
<asterite> Printing floating points accurrately is now done in Crystal, and compile times grew again
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<asterite> And so on...
<Groogy>
including my framework and compile a simple application takes a few seconds
<oprypin>
basically, rewriting everything in crystal is not only something that can't be prioritized, but it also is kinda blocked by lack of incremental compilation
<FromGitter>
<jwaldrip> Okay... so isn't their work to also optimize the compiler?
<oprypin>
"their"?
<FromGitter>
<jwaldrip> there*
<FromGitter>
<jwaldrip> sorry
<Groogy>
It is like this because of a design choice in the language
<oprypin>
now that's incorrect xD
<Groogy>
Well we can't have incremental linkage because it needs the context of the code right?
DTZUZO has quit [Ping timeout: 252 seconds]
DTZUZU has quit [Ping timeout: 255 seconds]
<Groogy>
in order to generate the functions needed when you call the stuff
<Groogy>
so including a .a or .so file is kind of out the window
<oprypin>
no no, of course it has to be an intermediate representation
<FromGitter>
<sdogruyol> Rust followed the same path
<FromGitter>
<sdogruyol> they're far ahead though with MIR and so on
<FromGitter>
<jwaldrip> Regardless of the how, I hope that someday, the compiler will be optimized so that the frameworks that are being built are compiled quickly, but that will also help to support the cause of putting everything in Crystal. This CAN be done with a strong development community and as the language evolves.
mark_66 has quit [Remote host closed the connection]
<FromGitter>
<jwaldrip> So maybe YAML wont be native pre 1.0
<FromGitter>
<jwaldrip> But I hope for it to be someday.
<FromGitter>
<bew> 👍 I'd also love that
<FromGitter>
<asterite> I'm not sure. I don't think a strong development community can solve the halting problem, for example
<Groogy>
Well I would say only benefit of it really for majority of usage is if there's someone maintaining YAML parser next to the compiler, like as far as I remember the YAML parser for Ruby wasn't made by the Ruby team
DTZUZO has joined #crystal-lang
rohitpaulk has joined #crystal-lang
DTZUZU has joined #crystal-lang
<FromGitter>
<pawandubey> Hi 👋 ⏎ From the docs I understand that there is no way to change the receiver of the method calls inside a captured block. Is there an alternate way to mimic Ruby's `instance_eval` & `class_eval`?
<FromGitter>
<pawandubey> You have the `:` at the wrong place @ansarizafar I think
<FromGitter>
<bew> `{id: idn, name: fname}`
<FromGitter>
<pawandubey> ☝️
<FromGitter>
<bew> it's trying to call `name` with argment `:fname`
<FromGitter>
<pawandubey> @bew Ooh, I see a major coincidence. I am actually writing a PEG parser library in Crystal. I remember seeing `Astral` when I first searched for prior art. Lol.
<FromGitter>
<pawandubey> @bew I am along the way somewhere. https://github.com/pawandubey/pegasus ⏎ I have the DSL and everything but there is no polish (also this lazy-eval limitation was preventing me from supporting recursive grammars)
<FromGitter>
<bew> cool!
<FromGitter>
<pawandubey> @ansarizafar Your `fname` seems to be an `Int32` value while you declare the `data` array with both tuple values as string
<FromGitter>
<ansarizafar> Ya Fixed
<FromGitter>
<ansarizafar> Thanks
<FromGitter>
<bew> @pawandubey did you see the Wiki of Astral? this is my current task, gather ideas and stuff about parsing, needs, cool things, and dsls, didn't start anything else right now
<FromGitter>
<bew> Did you already planned some features? Or are you doing it as you feel the need?
sz0 has joined #crystal-lang
DTZUZO has quit [Ping timeout: 264 seconds]
DTZUZU has quit [Ping timeout: 260 seconds]
DTZUZU has joined #crystal-lang
DTZUZO has joined #crystal-lang
ShalokShalom_ is now known as ShalokShalom
Ven has joined #crystal-lang
Ven is now known as Guest72709
tilpner has joined #crystal-lang
tilpner has quit [Client Quit]
tilpner has joined #crystal-lang
Groogy2 has quit [Quit: WeeChat 1.9]
Guest72709 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter>
<OldhamMade> @crisward there's a Crystal book? I'll give that a google. And no, I'm not from Oldham, but actually not too far away.
<oprypin>
asterite, if i added type annotations to a lot of methods in crystal (when those help document the method), would you accept the PR?
<FromGitter>
<bew> it feels that it's missing the point of not having to write the types..
<oprypin>
sigh
<oprypin>
bew, you also don't have to write documentation, but people do, for some reason
<oprypin>
this is documentation but better
<FromGitter>
<bew> yeah I know, I don't know how to solve the documentation otherwize, but I'was just saying
<FromGitter>
<zyriuse75> hi
<FromGitter>
<zyriuse75> Do you know with what i can make a GUI in crystal ?
<FromGitter>
<asterite> @oprypin Definitely!
<FromGitter>
<asterite> I think the more type annotations we have, everywhere, the better. If later we have to change the language somehow to require these type annotations it will be easier to migrate :-)
<FromGitter>
<asterite> But they also help document everything better
<FromGitter>
<bararchy> @zyriuse75 we got QT5 bindings, also a few grphic engines
<FromGitter>
<zyriuse75> @bararchy thank man i going to see that now !!
<FromGitter>
<zyriuse75> do you know the others ?
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<charlie-hadden> Hey! I'm using crystal in a kind of weird environment where I'm not able to include the prelude. I've been able to get most of the stuff I need so far with the primitives, but I'm stuck on strings. Obviously I'm not going to get all of the methods on the class without including it, but is it possible to get access to the buffer? At the moment I have a workaround with macros but I'd like to do it a more
<FromGitter>
<charlie-hadden> Looks like the nodoc `HEADER_SIZE` is what I was after though. `Pointer(UInt8).new(address + STRING_HEADER_SIZE)` seems to work
<FromGitter>
<charlie-hadden> I need to get this project up on github soon. It's a little x86 kernel I'm working on just to see what's possible with low-level crystal
hightower4 has quit [Ping timeout: 252 seconds]
<FromGitter>
<charlie-hadden> So far, apart from a little bit of assembly for bootstrapping, everything I've wanted to be possible has been
<cerulean>
nice
<FromGitter>
<charlie-hadden> Mostly wanted to try it because I've seen a few people say it wasn't possible 🤷
<FromGitter>
<charlie-hadden> Well, that and that crystal is amazing to work with and the more I do with it the happier if makes me - thanks to all the contributors!
hightower4 has joined #crystal-lang
<FromGitter>
<bew> good job @charlie-hadden ;)
hightower4 has quit [Ping timeout: 240 seconds]
hightower4 has joined #crystal-lang
<FromGitter>
<uSide> How to delegate class method?