RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
flaviodesousa has quit [Quit: KVIrc 5.0.0 Aria http://www.kvirc.net/]
f1refly has quit [Ping timeout: 268 seconds]
<FromGitter> <bartimus-primed> Quick question, crystal noob here, is there a reason why crystal's type system doesnt allow Int as a type declaration and forces int8/16/32 ?
<FromGitter> <dscottboggs_gitlab> Because it's ambiguous depending on the platform
<FromGitter> <dscottboggs_gitlab> `Int` is allowed as a type restriction though
<FromGitter> <johnjansen> its also just plain ambiguous
<FromGitter> <johnjansen> if you want to use `Int` is that because you dont know the range you are dealing with?
<FromGitter> <bartimus-primed> true but, 32bit is pretty standard, unless using an embedded. kind of, looking at some encryption stuff, guess i can just use the max to ensure it doesnt hit limt
<FromGitter> <Blacksmoke16> `UInt64` 😎
<FromGitter> <johnjansen> @straight-shoota its totally true, and since either approach requires you know what is in the file first im inclined to seperate configurables from code in a better way
<FromGitter> <bartimus-primed> @Blacksmoke16 yeah, just wasn't sure if there was a reason why, guess i could typedef it maybe
<FromGitter> <johnjansen> @bartimus-primed i dont think being explicit (and the extra 2 chars) is that onerous, the advantage is that there is no ambiguity
<FromGitter> <dscottboggs_gitlab> and now you know why lol
f1refly has joined #crystal-lang
<FromGitter> <bartimus-primed> understood, was more of just wondering since i ran into the error a couple times :P
<FromGitter> <bartimus-primed> I do want to say thanks to everyone though, finally a newer language that kept the OOP constructs, Go and Nim had disappointed me.
<FromGitter> <Blacksmoke16> good to hear
lucasb has quit [Quit: Connection closed for inactivity]
ashirase has quit [Ping timeout: 250 seconds]
ashirase has joined #crystal-lang
f1refly has quit [Ping timeout: 268 seconds]
f1refly has joined #crystal-lang
chemist69 has quit [Ping timeout: 268 seconds]
chemist69 has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <Blacksmoke16> @girng what are you doing that requires you to still use `as_i` etc? If you are using the `JSON.mapping` or `JSON::Serializable` then it should just auto convert everything into an instance of that struct/class vs giving you a big object of `JSON::Any`?
<FromGitter> <Blacksmoke16> gotta love fixing older code after you think about it more
<FromGitter> <Blacksmoke16> `{% route_params = route_def[:path].split('/').select { |p| p.starts_with?(':') || (p.starts_with?("(:") && p.ends_with?(')')) }` to `{% route_params = route_def[:path].split('/').select { |p| p =~ /:(\w+)/ } %}`
<FromGitter> <Blacksmoke16> heh
<FromGitter> <Blacksmoke16> `{% route_params = route_def[:path].split('/').select &.=~(/:(\w+)/) %}` even better
<FromGitter> <Blacksmoke16> dont actually need capture group either
<FromGitter> <girng> https://forum.crystal-lang.org/t/how-to-detect-vertical-and-horizontal-lines-in-a-2d-array/594 If anyone has some free time please take a look, thanks!
DTZUZO has quit [Ping timeout: 272 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
ashirase has quit [Ping timeout: 255 seconds]
ashirase has joined #crystal-lang
DTZUZO has joined #crystal-lang
<Groogy> hmm how is parallelization going in Crystal? Been ages since I checked
<Groogy> looking into implementing SPH based fluid dynamics and solviing things concurrently would be good
<FromGitter> <dscottboggs_gitlab> There's concurrency for IO-type stuff but MT scheduling and high-level APIs are still indefinitely far off :( basically all we have is `fork do...rescue...end`
<Groogy> Hmm before I went on my hiatus there were tons of talk about it
<Groogy> oh well
<Groogy> Windows port probably more important
<FromGitter> <dscottboggs_gitlab> There is significant progress on that front
<FromGitter> <dscottboggs_gitlab> seems smart to me to get Windows support working in general first anyway. Would bring in more people who use it on the desktop, and if you're going for cross-platform you're gonna need to make your MT APIs work on Windows too, you know? ⏎ ⏎ Sad to me, though, I haven't used Windows for anything in years.
<Yxhuvud> groogy: there has been MT progress lately though, see https://github.com/crystal-lang/crystal/pull/7546 and https://github.com/crystal-lang/crystal/pull/7547. Neither are merged yet though, but there is more activity than in a long time
<Groogy> aaah nice
<Groogy> though I guess better I just try and implement it first before worrying about MT
<Groogy> since I've never done it before
lucasb has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
rid1984 has joined #crystal-lang
<rid1984> am I able to call a method from another method in that object? something like: def method2; if (@method1) ...
<rid1984> or: if (this.method1)
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org playground link would help
<rid1984> so with '@' I'm able to call instance variables from within a method, but I can't use it to call a method. There must be a way though...
<FromGitter> <Blacksmoke16> just type the name of the method?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6kip
<rid1984> wow, it really is that easy...
<rid1984> awesome, thank you!
<FromGitter> <Blacksmoke16> np
rid1984 has quit [Quit: leaving]
SerkanDevel[m]1 has joined #crystal-lang
<SerkanDevel[m]1> Is there anyone here who maintaines the Qt5 bindings?
<FromGitter> <r00ster91> @Papierkorb does
DTZUZO has quit [Quit: WeeChat 2.0]
<FromGitter> <dscottboggs_gitlab> @SerkanDevl[m]1 the Qt bindings are unmaintained. I've been "maintaining" it in that I've been fixing problems created by breaking changes in crystal to keep it working as it is now but TBH the bindgen project is a little beyond me.
<FromGitter> <dscottboggs_gitlab> So like I've been able to keep it running but not fix problems and whatnot
<FromGitter> <dscottboggs_gitlab> but @Papierkorb is not very active
<SerkanDevel[m]1> is it possible to use these bindings for writing a plasma mobile app in crystal?
<FromGitter> <dscottboggs_gitlab> If you can use the older QtWidgets APIs to create a plasma-mobile app, then yes.
<SerkanDevel[m]1> Is there a way to use kirigami with it?
<FromGitter> <dscottboggs_gitlab> if plasma-mobile is focused on QtQuick then I'm not sure if you can the bindings to create new QtQuick widgets
<FromGitter> <dscottboggs_gitlab> what's kirigami
<FromGitter> <dscottboggs_gitlab> oh I see
<SerkanDevel[m]1> but is it possible to use those bindings for that?
<FromGitter> <dscottboggs_gitlab> Yeah, so, I've never tried using Crystal to build a QML type. Its something I was looking into but I don't have time to do right now. It *is* possible, but it is not a currently supported feature by any means. If you look at the qt.yml (https://github.com/Papierkorb/qt5.cr/blob/master/qt.yml) file used to tell bindgen how to construct the bindings, you can see that the QtQuick interface is not yet
<FromGitter> ... configured at all. However, you could use the rest of the existing configuration as an example to add in the QtQuick APIs. This is not a small project, but it is doable.
<SerkanDevel[m]1> and for kirigami?
<SerkanDevel[m]1> probably might need to build on top of it
<FromGitter> <dscottboggs_gitlab> yeah...see you're wading into new territory here. I'd say it's possible... you're just going to be linking with another C or C++ library to provide the available QML types, but I don't know how that will work with the Crystal compilation process and the QtQuick build process. Perhaps it would be easiest to begin the project as a standard QML project and go back and add in any missing types by binding
<FromGitter> ... the Crystal to that as a C project, or perhaps create a C companion file which will be linked to by the Crystal compiler
<FromGitter> <dscottboggs_gitlab> ideally we could go the other way -- `#include`ing a Crystal lib from C rather than binding to C from Crystal but that concept is experimental and not supported.
<FromGitter> <j8r> Why `Array#includes?` is more efficient than `Set#includes?`
<FromGitter> <jgaskins> @j8r Efficient how?
<FromGitter> <jgaskins> Do you mean faster?
<FromGitter> <j8r> like, a lot faster
<FromGitter> <jgaskins> It's only faster if the array is small :-)
<FromGitter> <j8r> I've tested even large configurations
<FromGitter> <j8r> the difference is smaller, but still faster
<FromGitter> <jgaskins> Just ran a quick benchmark for 3- and 1M-element instances of an array and set: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c97bb7a6a3d2e230d1a7e77]
<FromGitter> <jgaskins> The execution time of `Set#includes?` doesn't change, but the array version does.
<FromGitter> <j8r> ho ok
<FromGitter> <j8r> I haven't my benchmark right then...
<FromGitter> <dscottboggs_gitlab> wow, that's a huge difference
<FromGitter> <jgaskins> Sometimes you have to assign the result to a variable to keep LLVM from optimizing the entire call out, which can be difficult to remember when benchmarking πŸ˜‚
<FromGitter> <j8r> @jgaskins thanks!
<z64> @j8r `Set#includes?` is implemented via `Hash#has_key?`, which of course, goes through hash API. array#includes? just iterates over each element, so its O(N)
<FromGitter> <jgaskins> I forgot it in the first run of this benchmark, too, and all of the Array calls were optimized out, making it look like no matter how big the array was it was still 1-2ns. Then I remembered LLVM is trying to be helpful. :-D
<FromGitter> <silmanduin66> hi there, if someone can help me with a custom function . i -m trying to do the following ( in crystal ) ⏎ ⏎ 100 -> 111 ⏎ 1010 -> 1111 ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5c97bca3f3dbbd230cada792]
<FromGitter> <j8r> yes I've seen that z64, but there is a still `while` iteration https://github.com/crystal-lang/crystal/blob/master/src/hash.cr#L1036
<FromGitter> <Blacksmoke16> `"100".gsub("0", "1")`?
<FromGitter> <jgaskins> @silmanduin66 How efficient do you need it to be?
<FromGitter> <Blacksmoke16> ^
<FromGitter> <dscottboggs_gitlab> @silmanduin66 `('1' * original.to_s.size).to_i` πŸ˜†
<FromGitter> <dscottboggs_gitlab> yeah that
<FromGitter> <silmanduin66> for the moment pure crystal but i want to do the same later in wasm
<FromGitter> <silmanduin66> so like assembly
<FromGitter> <Blacksmoke16> is the input a string or number?
<FromGitter> <jgaskins> Oh, I mean, are you okay with converting numbers to strings and back?
<FromGitter> <dscottboggs_gitlab> "being in assembly" doesn't make it automatically efficient haha
<FromGitter> <dscottboggs_gitlab> yeah what @jgaskins said
<FromGitter> <dscottboggs_gitlab> you can do it in math though...
<FromGitter> <silmanduin66> folling this idea i can 4 into 7, 10 into 15
<FromGitter> <dscottboggs_gitlab> idk man look into bitwise math, there might be a way to do it
<FromGitter> <jgaskins> If you're willing to incur the heap allocations by converting to strings, @Blacksmoke16's `gsub` example is the simplest β€”Β `number.to_s(2).gsub('0', '1')`. tbh, it's not WebScaleβ„’ but it's still fast.
<FromGitter> <Blacksmoke16> is the input a string or number? @silmanduin66
<FromGitter> <Blacksmoke16> im assuming the latter
<FromGitter> <silmanduin66> number in any case
<FromGitter> <silmanduin66> int
<FromGitter> <j8r> what do I forget? https://carc.in/#/r/6kjo
<FromGitter> <j8r> I would like to return the struct, not a Bool
<FromGitter> <dscottboggs_gitlab> You had it right
<FromGitter> <dscottboggs_gitlab> The problem is using the `&.` syntax
<FromGitter> <jgaskins> @j8r Order of operations :-) https://carc.in/#/r/6kjp
Groogy has quit [Quit: WeeChat 2.4]
<FromGitter> <dscottboggs_gitlab> https://carc.in/#/r/6kjr
<FromGitter> <dscottboggs_gitlab> yeah that
<FromGitter> <dscottboggs_gitlab> which, I would prefer if it didn't do that but ok
<FromGitter> <j8r> thanks1
<FromGitter> <silmanduin66> i found was i was looking for, thanks for your answers anyways. If anyone is interesting by the solution for C : i use that with u32 ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c97c8646a3d2e230d1ad3da]
<FromGitter> <Blacksmoke16> i have no idea what this is doing
<FromGitter> <Blacksmoke16> :p
<FromGitter> <Blacksmoke16> ```code paste, see link``` ⏎ ⏎ yey, this bug again :( [https://gitter.im/crystal-lang/crystal?at=5c97cb10d0133e21e50afd8a]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c97cb998aa66959b6646331]
<FromGitter> <Blacksmoke16> also getting this, yet `Param` parent class is abstract, so that should tell the compiler it should work
wuehlmaus has joined #crystal-lang
<FromGitter> <Blacksmoke16> switched to not using `record` macro and go around the `Param+` bug, but target defs is still a thing :/
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/issues?q=no+target+defs+is%3Aopen guess ill see if i can reproduce and file an issue
ashirase has quit [Ping timeout: 255 seconds]
ashirase has joined #crystal-lang
<FromGitter> <Blacksmoke16> 😒 `BUG: trying to downcast Athena::Routing::QueryParam(T) <- Athena::Routing::PathParam(Int32) (Exception)` i cant win ha
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6kkt
<FromGitter> <Blacksmoke16> filed some bugs that i reproduced
return0e has joined #crystal-lang
return0e_ has quit [Read error: Connection reset by peer]
<wuehlmaus> what's the best way having all numbers from 1 to 100_000_000 in a file? it's only a test but i seem to choose the wrong algorithm to do it. picolisp is interpreted and does it in 26 seconds while my version needs over 5 minutes in crystal.
<wuehlmaus> that's my stupid version and i am really not having a clue
<wuehlmaus> i am redirecting the output to a file
<FromGitter> <Blacksmoke16> with each number on its own line?
<wuehlmaus> that's what i test
<wuehlmaus> i always test speed, stupid little test of mine
<FromGitter> <johnjansen> whats the point of this, just to understand?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c97e3de8aa66959b66506b8]
<FromGitter> <Blacksmoke16> ```time ./test ⏎ ⏎ real0m2.671s ⏎ user0m2.020s ⏎ sys0m0.652s``` [https://gitter.im/crystal-lang/crystal?at=5c97e3e88aa66959b6650744]
<FromGitter> <Blacksmoke16> after building with --release
<FromGitter> <Blacksmoke16> er sec
<wuehlmaus> johnjansen: yes, just a stupid little test
<FromGitter> <Blacksmoke16> yea that should doit
<wuehlmaus> would parallel make it faster?
<FromGitter> <Blacksmoke16> :shrug;
<FromGitter> <johnjansen> @Blacksmoke16 why go into an IO::Memory before a file? … PS i havent thought this through at all, so just curious
<FromGitter> <Blacksmoke16> my thought was that it was cheaper/fast than doing actual writes to file
<FromGitter> <Blacksmoke16> but prob use more memory
<FromGitter> <johnjansen> did you benchmark it?
<FromGitter> <Blacksmoke16> let me try it
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c97e5fa9d9cc8114a159ed9]
<FromGitter> <Blacksmoke16> would be similar
<FromGitter> <Blacksmoke16> that takes same time as first example, now let me try another
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c97e6358126720abc38cf88]
<FromGitter> <Blacksmoke16> looks to be about the same, 2.6 sec vs 2.5sec hh
<FromGitter> <Blacksmoke16> not *super* familiar with this area, so id be open to alternatives that would be more optimal
<FromGitter> <johnjansen> i used to have a trick, but now i cant remember it … thats the trouble with being AWOL for a year
<wuehlmaus> i am so happy that it's so much faster now, thanks a lot for giving me a fast way :-)
<FromGitter> <Blacksmoke16> also be sure to build with `--release` when doing benchmarking stuff
<wuehlmaus> i know and do
<FromGitter> <Blacksmoke16> πŸ‘
<FromGitter> <j8r> try with `file << n << '\n'` instead of `file.puts`
<FromGitter> <j8r> every time you use `puts` it flush the buffer
<FromGitter> <Blacksmoke16> ~2.42 sec
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c97e9606a3d2e230d1bab80]
<wuehlmaus> that's faster on my slow system
<FromGitter> <johnjansen> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c97ebd72fb6800d80750d03]
<FromGitter> <j8r> it can't be faster
<FromGitter> <j8r> copying is less efficient
<FromGitter> <johnjansen> you’d think …
<FromGitter> <j8r> it's slower on my system
<FromGitter> <johnjansen> ok cool, rules that out
<FromGitter> <j8r> what we can play is eventually buffers https://crystal-lang.org/api/master/IO/Buffered.html
<FromGitter> <johnjansen> yep!
lucasb has quit [Quit: Connection closed for inactivity]