RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.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
DTZUZO has quit [Ping timeout: 272 seconds]
<FromGitter> <fridgerator> lol
<FromGitter> <asterite> But then you have `elements = [1, 2, 3]; if elements.includes?(...)` which is grammatically wrong. I guess `include?` isn't that bad after all, or, well, depending on how you name your variable it will work or not. Actually... for String it's also `include?` in Ruby, and that's maybe why it's problematic. It should be `includes?` for String and `include?` for Array and collections in general
<FromGitter> <fridgerator> how is `includes?` gramatically wrong for collections?
<FromGitter> <Timbus> Yeah its not, he's just trying to stir the pot :P
<FromGitter> <Timbus> But the sentence 'if elements include'
<FromGitter> <Timbus> is better
<FromGitter> <Timbus> "if my bag of apples includes a red one" hmmmm
<FromGitter> <asterite> `if (this array of) elements.includes?` :-)
cyberarm has quit [Ping timeout: 256 seconds]
_whitelogger has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 272 seconds]
Raimondii is now known as Raimondi
DTZUZO has joined #crystal-lang
<FromGitter> <kolyaio> I currently reading the whole documentation as ebook that I published here earlier. I wonder how it could be more accessible to beginners. Also I think there are concepts that are based on Ruby but they weren’t explained properly as if it assumed people know Ruby 😢 ⏎ ⏎ I know I’m weird but I didn’t like Ruby but I do love crystal 😊
<FromGitter> <kaukas_gitlab> I am sorry for repeating my question: https://play.crystal-lang.org/#/r/4psw ⏎ Is there a way to achieve automatic type expansion (e.g. with `forall`) without writing a macro?
<FromGitter> <kaukas_gitlab> I ended up using a macro but it's a bomb in terms of compilation time: https://github.com/kaukas/crystal-cassandra/blob/master/src/cassandra/dbapi/types/decoders.cr#L314
DTZUZO has quit [Ping timeout: 244 seconds]
<FromGitter> <kaukas_gitlab> @asterite, why couldn't we have aliases to support both `include?` and `includes?`
<FromGitter> <MrSorcus> https://gist.github.com/MrSorcus/9d357829283fd7f70dc3998e12bbf6e7 ⏎ Problems with TLS in Crystal?
<FromGitter> <bararchy> no shared cipher (OpenSSL::SSL::Error)
<FromGitter> <bararchy> it's an OpenSSL error
<FromGitter> <bararchy> the client and server does not share a cipher suite
<FromGitter> <j8r> Does the goal of a programming language is to be grammatically correct in a spoken language? ⏎ Expressiveness in more important, please don't reproduce the English inconsistencies - Crystal isn't English, but a programming language as itself πŸ˜„
<FromGitter> <kaukas_gitlab> I think there's a spectrum between expressiveness and confusion (think Perl vs Go). Ruby wants to make developers happy, and that is a good goal for Ruby. Having both `include?` and `includes?` to make the DSL read more natural in English certainly would make for less unhappy developers. Whether this goal applies to Crystal, I don't know.
<FromGitter> <MrSorcus> > the client and server does not share a cipher suite ⏎ ⏎ But no any problems if i uses this certificate in nginx...
<FromGitter> <j8r> I don't see the point of this `s` really. You are free to create how much aliases you want, but multiply them in the stdlib doens't add value
<FromGitter> <j8r> I can write "bad english" and this will be valid crystal, but invalid english like `elements.includes` or `collection.include`
<FromGitter> <j8r> For now I consider, `Object.includes`, rather than the underlying variable name. `Object` can be `Array`, `Hash` or whatever
<FromGitter> <MrSorcus> > the client and server does not share a cipher suite ⏎ ⏎ https://gist.github.com/MrSorcus/bd4d52696a6c002051f089fbb7dd2b1e openssl s_client with -debug option.
<FromGitter> <kaukas_gitlab> It's certainly about personal preferences. It annoys me a tiny bit every time I have to write `MyClass.include?(MyModule)`. It's 98% close to readable but not quite there yet. I would certainly enjoy having an option to use the form that makes most sense in the given situation. There are examples of such 100% fluid DSLs out there so I don't think they are totally useless. But it's a personal preference,
<FromGitter> ... of course.
<FromGitter> <MrSorcus> @bararchy, no ideas why it's happens?
<FromGitter> <bararchy> `New, (NONE), Cipher is (NONE)`
<FromGitter> <bararchy> that's the issue
<FromGitter> <bararchy> i'm not sure why it happenes, maybe you didn't configure an SSL Context?
<FromGitter> <Timbus> I just find that 'includes' is right more often than 'include', and thus I (and my coworkers), are happy for it. ⏎ Also, you can add `include` all you want if you support my extension method proposal :p
alex`` has joined #crystal-lang
<FromGitter> <Timbus> Hm that's an odd issue with forall btw @kaukas_gitlab . There's some cases where it works, and some where it doesn't
<FromGitter> <Timbus> Also there's a Hash.zip() class method that you might find usefful
hightower4 has joined #crystal-lang
<FromGitter> <kaukas_gitlab> @Timbus, I did not know about `Hash.zip`, thank you! In my case `Array` was just for simplicity, eventually I went with `Iterator`s.
<FromGitter> <kaukas_gitlab> Although, when I think about it, `Hash.zip` *should* work with `Iterator`s, not `Array`s.
<FromGitter> <Timbus> Yeaah probably.
<FromGitter> <MrSorcus> > i'm not sure why it happenes, maybe you didn't configure an SSL Context? ⏎ ⏎ It's just example from Kemal documentation. http://kemalcr.com/guide/
moei has quit [Quit: Leaving...]
<FromGitter> <Timbus> So `forall` works if you have an array that contains the entire superset of all the types you expect to pass.. Does that work for you? It's kind of a hack
<FromGitter> <Timbus> Maybe it's something I can try to patch. Good motivation to better learn the compiler
<FromGitter> <Timbus> Or maybe that's just how it's supposed to work, now that I think about it. Hm. ⏎ Anyway, consider: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5b7140f95b07ae730aafa2ab]
hightower4 has quit [Remote host closed the connection]
<FromGitter> <bew> @kaukas_gitlab why not do that ? https://play.crystal-lang.org/#/r/4q0w
<FromGitter> <bew> ah nvm, `Hash.zip` is good too
<FromGitter> <kaukas_gitlab> @bew, as I mentioned I ended up using Iterators https://github.com/kaukas/crystal-cassandra/blob/master/src/cassandra/dbapi/types/decoders.cr#L299 to avoid creating an intermediate array. The suggestion to unspecify the subtype is interesting though. Is there a way to do that and still win if: ⏎ ⏎ 1) I am using Iterators instead of Arrays and ⏎ 2) Sometimes there might be no items (how do I return
<FromGitter> ... the Hash of the right type still?) [https://gitter.im/crystal-lang/crystal?at=5b7146a05b07ae730aafc0cb]
<FromGitter> <Timbus> You'll find it errors similarly with different collection types
<FromGitter> <kaukas_gitlab> I don't see a way to `peek` an iterator to get the first element.
<FromGitter> <Timbus> No but, you see, `zip` uses.. forall
<FromGitter> <bew> You can also use Hash.zip but with Iterator (it's just a copy/paste away ~
<FromGitter> <Timbus> you're just pushing the problem down a layer
<FromGitter> <MrSorcus> @bararchy, maybe problem with ECC certificates?
<FromGitter> <bew> an iterator has a type, event if it's empty
<FromGitter> <MrSorcus> @bararchy, hmm... With RSA certificate no problem. Only with ECC i think.
<FromGitter> <bew> @kaukas_gitlab using iterators: https://carc.in/#/r/4q10
<FromGitter> <kaukas_gitlab> @bew, that only works because your arrays have a single type. My arrays have multiple possible types: https://carc.in/#/r/4q11
<FromGitter> <sekkr1> I found a weird issue, what do you think about it? https://play.crystal-lang.org/#/r/4q13
<FromGitter> <bew> @kaukas_gitlab you'll have to simplify your types somehow
<FromGitter> <kaukas_gitlab> I'd be very happy to if anyone had any suggestions :-)
ashirase has quit [Ping timeout: 244 seconds]
ashirase has joined #crystal-lang
<FromGitter> <sekkr1> Seems like this issue started in 0.20.5
<FromGitter> <sekkr1> 1) 20.3 works as intended
<FromGitter> <kaukas_gitlab> crystal-db allows me to specify the exact type it should return out of a query: https://crystal-lang.org/docs/database/#query, e.g. `Hash(String, Float64)`. I don't know of a way to make this work except to return a union of all possible types and allow the user to choose the one wanted.
<FromGitter> <bew> who is the user?
<FromGitter> <kaukas_gitlab> The developer calling crystal-db and my driver
<FromGitter> <Timbus> @kaukas_gitlab have you tried printing the typeof(return_value) after running your macro
<FromGitter> <Timbus> does it actually do what you expect
<FromGitter> <bew> i guess the dev is supposed to use rs.read by itself, and specify the types he needs
<FromGitter> <kaukas_gitlab> @Timbus the macro works, yes. It creates a cartesian product of all possible types. So then the runtime chooses the one that fits the given types at runtime.
<FromGitter> <kaukas_gitlab> @Timbus my expectation was that `def to_hash(keys : Array(K), vals : Array(V)) : Hash(K, V) forall K, V` would actually do the same.
<FromGitter> <bew> it doesn't choose anything at runtime
<FromGitter> <bew> the methods are decided at compile time
<FromGitter> <Timbus> Is that really any different than a cartesian product inside the collection though..
<FromGitter> <kaukas_gitlab> Ok, so I guess it sees the `.as(Hash(..., ...))` and chooses the right method.
<FromGitter> <kaukas_gitlab> @Timbus `Hash(String | Int32, String | Int32)` fails with `.as(Hash(String, Int32))` if that's what you mean.
<FromGitter> <bew> by the way, what are you trying to do? (the more high level objective)
<FromGitter> <Timbus> Guess that is what I meant
moei has joined #crystal-lang
<FromGitter> <kaukas_gitlab> @bew I am trying to construct a hash of primitives, and return the exactly typed hash as a result of a Cassandra query. The exact type of a hash is chosen at runtime, e.g. for `map<int, string>` it should return `Hash(Int32, String)`.
<FromGitter> <bew> i fear you can't do that, as the type must be known at compile time, and that `map<int, string>` is a runtime information only
<FromGitter> <bew> and why do you want the same type?
<FromGitter> <kaukas_gitlab> @bew because that's what crystal-db allows you to do, specify the exact type with `.as(exact-type)`.
<FromGitter> <kaukas_gitlab> @bew I can do that, with the macro. Trouble is that macro bombs the compile times.
<FromGitter> <kaukas_gitlab> I'd love it to work with `forall` to avoid the macro. And I had a secret hope that it would not stress the compiler as much.
<FromGitter> <bew> no time to dig into that rightnow, sry
<FromGitter> <kaukas_gitlab> @bew, no problem! That's for the participation :-)
<FromGitter> <MrSorcus> @bararchy https://www.openssl.org/docs/manmaster/man3/SSL_accept.html `LibSSL.ssl_accept` return -1, but i don't know why. X-)
<FromGitter> <Timbus> I can't see how forall can do what you want, unfortunately. It doesn't loop 'for all' of the types to a single method call. `some_forall_method(1||'b'||"c")` will instantiate a method that takes Int32|Char|String . The more I think about this the more confused I get. ⏎ Maybe asking for the shape of the data upfront can get you where you want? Like a `mappable`
<FromGitter> <Timbus> `mapping` *
<FromGitter> <kaukas_gitlab> @Timbus, is there any example I could check? Do you mean https://github.com/crystal-lang/crystal-db/blob/master/src/db/mapping.cr#L3? How would it help me in this case?
<FromGitter> <Timbus> At this point I can only say it feels like.. Relying on the user to cast the type *after* you fetched it is the main issue? A mapping (or something similar) means you can compose the data into the type the user provided. ⏎ Will it help? I dunno. I haven't tried to design a library like yours unfortunately.
<FromGitter> <kaukas_gitlab> @Timbus, yeah, it seems like crystal-db wants me to provide all possible combinations of types upfront, and then the user chooses afterwards.
<FromGitter> <Timbus> But on the other hand, JSON wants the opposite (so it can avoid wrapping all types with JSON::Any)
<FromGitter> <Timbus> Oh, right you have to conform to the crystal-db interface yeah
<FromGitter> <kaukas_gitlab> I am sorry, I don't know enough about JSON yet. I am rather new to Crystal, this is my first bigger toe dip. I do know that somehow JSON::Any is going to be relevant because recursive aliases have been removed, and JSON uses structs while crystal-db still uses aliases (https://github.com/crystal-lang/crystal-db/blob/28b17b7dba820d7e4810493aaf0a99e368849ec6/src/db.cr#L76) which prevents me from
<FromGitter> ... implementing recursive nested data structures (https://github.com/kaukas/crystal-cassandra/blob/master/src/cassandra/dbapi.cr#L16).
alex`` has quit [Ping timeout: 248 seconds]
<FromGitter> <Timbus> Oof. I see.
<FromGitter> <Timbus> You know, @anykeyh might have the knowledge to guide you, if you ping him (and if he's willing). He's very familiar with all of these concepts.
<FromGitter> <kaukas_gitlab> @Timbus was that enough of a ping already? :-P Or should I ask some other way?
<FromGitter> <Timbus> Mebbe, otherwise drop him a privmsg I guess? Might be a busy guy
<FromGitter> <kaukas_gitlab> @Timbus, thank you for all the help! I might try the #crystal-db channel first.
<FromGitter> <Timbus> Seems fair. Although I don't really know that I helped =<
<FromGitter> <kaukas_gitlab> @Timbus, at least you confirmed my current understanding, and I am very grateful for it.
Jenz has joined #crystal-lang
<Jenz> Ah, lots of stuff has happened in the crystal world
<Jenz> Im glad
<FromGitter> <MrSorcus> https://github.com/kemalcr/kemal/issues/480 - can someone help? Thanks.
<FromGitter> <straight-shoota> @MrSorcus this is probably not a kemal issue but with openssl or it's Crystal binding
<FromGitter> <MrSorcus> @straight-shoota reopen in Crystal repo?
<FromGitter> <straight-shoota> yeah, try to reproduce it with using `HTTP::Server` directly
<FromGitter> <MrSorcus> @straight-shoota https://gist.github.com/MrSorcus/b9069d8e4af850e43744a2caaa407260 - ok?
<FromGitter> <MrSorcus> @straight-shoota https://github.com/crystal-lang/crystal/issues/6534 - here issue.
<FromGitter> <Timbus> Isn't that usually the error you get when the cipher isn't setup/selected properly or what have you. I recall a similar error someone else had
<FromGitter> <Timbus> What if you do this before starting the server: `tls.ciphers = "HIGH+kEECDH+AESGCM:HIGH+kEECDH:HIGH+kEDH:HIGH:!aNULL"`
Jenz has quit [Quit: leaving]
alex`` has joined #crystal-lang
DTZUZO has joined #crystal-lang
kmctown has joined #crystal-lang
alex`` has quit [Ping timeout: 240 seconds]
francisl has joined #crystal-lang
alex`` has joined #crystal-lang
alex`` has quit [Client Quit]
alex`` has joined #crystal-lang
kmctown has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
francisl has quit [Ping timeout: 260 seconds]
francisl has joined #crystal-lang
akaiiro has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
kmctown has joined #crystal-lang
marius has quit [Quit: baj]
marius has joined #crystal-lang
thews has quit [Ping timeout: 256 seconds]
akaiiro has joined #crystal-lang
kmctown has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kmctown has joined #crystal-lang
<FromGitter> <MrSorcus> > What if you do this before starting the server: `tls.ciphers = "HIGH+kEECDH+AESGCM:HIGH+kEECDH:HIGH+kEDH:HIGH:!aNULL"` ⏎ ⏎ Nothing changed.
Jenz has joined #crystal-lang
<Jenz> Why doesn't this work?: https://play.crystal-lang.org/#/r/4q3h
<Jenz> I get using `forall` is a terrible idea
<Jenz> Im just trying to figure out how it works
<z64> Jenz: Array.is_a?(Array(Int32)) #=> false
<z64> actual type restrictions behave differently than just an .is_a? check, and allow you to specify just `Array`
<Jenz> So, only `Array`, will never return true for any other type than the pure type `Array`
<Jenz> (Using #is_a?)
<Jenz> Thanks z64, @j8r
kmctown has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Jenz> What about this then?: https://play.crystal-lang.org/#/r/4q3y
<z64> Jenz: `case` compares with `===`; https://play.crystal-lang.org/#/r/4q48
<z64> (i don't follow the semantics of `===`, but that is whats happening)
<FromGitter> <j8r> https://play.crystal-lang.org/#/r/4q49 πŸ˜„
<Jenz> Haha
<z64> yeah that ^ would be the way
<FromGitter> <j8r> that's uglier
<Jenz> Indeed
<z64> seperating by an overload is probable better in this case :p https://play.crystal-lang.org/#/r/4q4f
kmctown has joined #crystal-lang
<Jenz> That seems a bit verbose though
<z64> in example, sure. i imagine in actual application code you would be doing more with T than just checking if it is of Array. (you can just do `def foo(arg : Array); true` and `def foo(arg); false` if you really just want that)
<Jenz> z64: Surely, you forgot to put `end`?
<Jenz> Or does that actually work
<z64> i didn't forget, just lazy to type out
<z64> :)
<Jenz> So it doesn't work?
* Jenz XD
* Jenz Β―\_(ツ)_/Β―
<Jenz> And ... how come line 8, but not 7 fails here?: class Foo(V)
<Jenz> end
<Jenz> V
<Jenz> def self.get
<Jenz> end
<Jenz> pp! Foo(1).get
<Jenz> pp! Foo(:oo).get
<Jenz> Oh damn, I didn't mean to post the program
<Jenz> I meant to post the link, i.e.: https://play.crystal-lang.org/#/r/4q53
<Jenz> (Just ignore the random lines of code I posted here)
<Jenz> I know StaticArray uses this (e.g. `StaticArray(String?, 16).new`), but when it works with integers, why shouldn't it with other types as well?
<Jenz> Oh, it works with floats as well apparentely, I'll change it to: why won't it work with non-numerals as well?
<z64> no idea ;( it was my understanding that NamedTuple and StaticArray had special generic notation, unlike other types.
* Jenz Β―\_(ツ)_/Β―
<Jenz> Oh wow, I never realized NamedTuples syntax was like that, yet, I've used it many times...
<Jenz> I mean, I never realized it was special
<FromGitter> <rishavs> How do I get a db query as a specific class? For example, I want to do something like this; ⏎ ` postObj = Cove::DB.query_one? "select unqid, title, content, link, author_id, author_nick from posts where unqid = $1", postid, ⏎ ⏎ ``` as: Cove::Models::User```` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5b71a1c9937eee242310a93f]
kmctown has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<Jenz> @rishavs, see: http://crystal-lang.github.io/crystal-db/api/0.5.0/DB.html#mapping(properties%2Cstrict%3Dtrue)-macro
<FromGitter> <rishavs> Thanks Jenz. Thats exactly what I was looking for
* Jenz :)
<Jenz> I guess, even *my* feeble knowledge can help at times XD
kmctown has joined #crystal-lang
<Jenz> z64: On second thought, NamedTuple *is* a primitive, but StaticArray is not, so NamedTuple having special syntax... wouldn't really be special, would it?
* Jenz XD
<z64> well, sure lol.
Raimondii has joined #crystal-lang
<FromGitter> <bew> StaticArray is also a special type
<Jenz> No way?
<Jenz> How so?
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<Jenz> s/way?/way/
<Jenz> now im super intrigued
<Jenz> Oh, I probably use that word wrongg
<Jenz> (last one)
<FromGitter> <bew> ^^ checkout the code in `src/static_array.cr` look for the new & initialize methods, you'll see for example that the ivar `@buffer` is never manually initialized, and that the `new` method is implemented using a StaticArray (good luck doing that if it's not special)
<FromGitter> <bew> It's special because there no public way to allocate a fixed size buffer on the stack, this is done by the compiler when needed when you use a StaticArray
<Jenz> It wouldn't be possible using LibC?
<FromGitter> <bew> No
* Jenz O_o
<Jenz> Ok thanks a ton
<FromGitter> <bew> It's not what LibC is for
<Jenz> Im very very far from being a low level expert
<Jenz> Gtg
<Jenz> Thanks all
Jenz has quit [Quit: leaving]
return0e_ has quit [Quit: Leaving...]
return0e has joined #crystal-lang
<FromGitter> <Michionlion> Is there any way to access the value of a generic in a macro?
<z64> @Michionlion do you mean something like https://carc.in/#/r/4q6m ? or could you provide a (failing) example of what you're trying to do exactly?
<FromGitter> <Michionlion> Something like
<FromGitter> <Michionlion> `GenericClass(T + N)` where N is the generic of another class
<FromGitter> <bcardiff> @Michionlion for me it's not clear what you expect from `T + N`. Can you show slightly bigger example of what you are trying to solve?
<FromGitter> <Michionlion> something like https://carc.in/#/r/4q6n
<FromGitter> <Michionlion> essentially constructing the generics of another class based on the generics of the first
<FromGitter> <Michionlion> there's a work around in hardcoding all possible `Matrix(N,M)` types with concrete numbers, but then compile time goes through the roof because code is generated for generic versions that aren't used
<FromGitter> <Michionlion> Generics are CONSTs, and so are known at compile time
<FromGitter> <Michionlion> but you can't specify a compile-time CONST as a generic
<FromGitter> <Michionlion> or rather I guess the result of a computation at compile time, in a macro
<FromGitter> <Michionlion> The use case here is a linear algebra math library where vectors and matrices are structs and have their dimensions encoded with generics so that `StaticArray` can be used to put the values on the stack
<FromGitter> <Michionlion> since you need a literal or generic to pass to `StaticArray` as the size
<FromGitter> <rishavs> > *<Jenz>* @rishavs, see: http://crystal-lang.github.io/crystal-db/api/0.5.0/DB.html#mapping(properties%2Cstrict%3Dtrue)-macro ⏎ ⏎ I have hit an issue here. On using ⏎ ⏎ ```code paste, see link``` ... [https://gitter.im/crystal-lang/crystal?at=5b71ce355762ee4fe56fa15e]
<FromGitter> <bcardiff> @Michionlion The methods will still be generated per each combination in LLVM if you get to use macro to do the math between generic types.
<FromGitter> <bew> @Michionlion something like that? https://carc.in/#/r/4q6r
<FromGitter> <Michionlion> hmmm
<FromGitter> <Michionlion> was that added recently? Because I was unable to replicate things like that when I was working on this a few weeks ago
<FromGitter> <Michionlion> maybe this is just a failing of putting both macros and forall together
<FromGitter> <bew> not really new, no
<FromGitter> <bcardiff> when using `{{ }}` inside a method you will need a `{% begin %} / {% end %}` to parse the content as macro. maybe you was missing that in your privious experiments
<FromGitter> <Michionlion> that was probably it
<FromGitter> <Michionlion> wow that was a lot of work potentially wasted on my part
akaiiro has quit [Remote host closed the connection]
<FromGitter> <rishavs> ok, this is weird. Any where in my code i can use my DB constant as a namespaced constant `Cove::DB` and it works. but mapping will only work with a `DB` constant. Wonder if the macro is expecting a hardcoded constant name
<FromGitter> <bcardiff> Probably the top level `::DB` of crystal-db is hidden by the local `Cove::DB`. Probably some `::` needs to be added
hightower4 has joined #crystal-lang
<hightower4> Hey, if I have an array like [ "one", "two", "three" ], how do I convert it to a Hash with contents { "one" => 1, "two" => 1, "three" => 1 }
<hightower4> I'm having a hard time doing it with map{} since saying map{ |x| { x => 1 }} gives me an array of hashes, not hash with those keys
<FromGitter> <Michionlion> `Array#index_by` does the opposite of what you're thinking of, but it doesn't look like there is anything that does that out of the box
<FromGitter> <Michionlion> the easiest way is probably just to create a hash and iterate over the array, adding things to the hash
<hightower4> ok done so thanks
<FromGitter> <rishavs> > Probably the top level `::DB` of crystal-db is hidden by the local `Cove::DB`. Probably some `::` needs to be added
<FromGitter> <rishavs> thanks. will check for that
<FromGitter> <Michionlion> you could do it with ⏎ ⏎ ```(["one", "two", "three"].map { |v| {v, 1} }).to_h``` ⏎ ⏎ output: https://carc.in/#/r/4q6z [https://gitter.im/crystal-lang/crystal?at=5b71d364179f842c9732e10c]
<FromGitter> <Michionlion> `Array#to_h` converts an array with indexable elements to a hash mapping the first value of each entry to the second
akaiiro has joined #crystal-lang
return0e has quit [Quit: Leaving]
<FromGitter> <Michionlion> one more question on generics though, is it possible to get the value of a CONST in a macro? To do things like ⏎ ⏎ ```{% for i in (1..CON)%} ⏎ ``` [https://gitter.im/crystal-lang/crystal?at=5b71d58b67eb9f60fed69187]
<FromGitter> <Michionlion> rather, is there a way to convert a constant to a numberliteral
<FromGitter> <Michionlion> https://carc.in/#/r/4q79
<oprypin> Michionlion, constant.resolve
<FromGitter> <Michionlion> Thanks!
<FromGitter> <Michionlion> hmm... `NumberLiteral` should probably define `#resolve` and return itself
<oprypin> prob
<oprypin> hightower4, `%w[one two three].each_with_object(1).to_h`
<hightower4> oprypin, nice one as always thanks!
<FromGitter> <Michionlion> that's a better version :)
<FromGitter> <Michionlion> One more question for you crystal experts: is there a way to set a constant at compile-time from the command line? something like -Dvalue=5?
<hightower4> If I want to save/load logger severity from YAML file, is there a better way than saving severity as a string, then doing "case severity; when "debug": Logger::Severity::DEBUG" and so on for all 6 levels?
<z64> @hightower4 Severity is an enum, so `Logger::Severity.parse("debug") #=> Logger::Severity::DEBUG". it will raise ArgumentError if it fails to find a match
<FromGitter> <bew> You can do `Logger::Severity.parse?(severity)`
<hightower4> awesome!
<FromGitter> <bew> Ah there you go :)
<oprypin> Michionlion, https://crystal-lang.org/api/0.25.1/Crystal/Macros.html#env%28name%29%3AStringLiteral%7CNilLiteral-instance-method may be your best bet
<hightower4> How do I turn a file name into an open file descriptor for writing?
<FromGitter> <Michionlion> thanks @oprypin
<oprypin> hightower4, why not search for it
<FromGitter> <MisterBianco> What's the best place to ask a crystal question? Is it here or in an issue on GitHub?
<oprypin> well definitely not issue
<FromGitter> <MisterBianco> I am looking at getting the ascii table hex code of a char... I found the ord modifier for a char but I can't seem to find a viable way to convert to the hex code on the table like 'a' #=> 61 & 'A' #=> 41
snapcase has quit [*.net *.split]
hplar has quit [*.net *.split]
daemonwrangler has quit [*.net *.split]
<oprypin> p 'a'.ord.to_s(16)
<hightower4> oprypin, doh, thanks :)
<oprypin> https://crystal-lang.org/api/0.25.1/IO/FileDescriptor.html#fd%3AInt32-instance-method where is this : Int32 coming from??
hplar has joined #crystal-lang
Raimondi has quit [Quit: WeeChat 2.2: Β‘Chau!]
kmctown has quit [Quit: Textual IRC Client: www.textualapp.com]
return0e has joined #crystal-lang
<FromGitter> <Prutheus> Hello. Someone using crecto? How can I set up an id field with auto increment? I have in my databse table the id field set as primary key with AUTO_INCREMENT and I do not set it at my model class in any way, i just have a `field data, String` line in my `schema` .... how ti properly use autoincrement id, because like I have setup everything the id is always NULL, i think this comes from crecto which tries to
<FromGitter> ... set the id to nil ... ?
<FromGitter> <Prutheus> ``` user = User.new ⏎ user.email = "fred@test.com" ⏎ DB.insert(user)``` ⏎ ⏎ I get the entry in my table: ⏎ ID EMAIL ... ⏎ NULL fred@.... [https://gitter.im/crystal-lang/crystal?at=5b71e6de937eee2423125912]
<FromGitter> <Prutheus> How to fix automatic ID count-up ?
<FromGitter> <fridgerator> use `id INTEGER NOT NULL PRIMARY KEY` instead
<FromGitter> <fridgerator> https://www.sqlite.org/autoinc.html
<FromGitter> <Prutheus> does not work, is still null
<FromGitter> <Prutheus> oh no sorry
<FromGitter> <Prutheus> works
<FromGitter> <Prutheus> thanks!
alex`` has quit [Ping timeout: 240 seconds]
akaiiro has quit [Ping timeout: 248 seconds]
Raimondi has joined #crystal-lang
thews has joined #crystal-lang
francisl has quit [Quit: francisl]
ashirase has quit [Ping timeout: 240 seconds]
ashirase has joined #crystal-lang
<RX14> does anyone know of any tools to debug memory leaks in crystal?
<RX14> or do I have to figure out my own
<FromGitter> <fridgerator> I think @sdogruyol has used Instruments (on mac) before
<FromGitter> <fridgerator> so.... buy a mac? lol
<RX14> how can instruments debug memory leaks? that doesn't make sense
<RX14> unless it has special bdwgc integration which I doubt
<RX14> and even then how would it know the type of the objects?
<RX14> sorry that doesn't add up
<FromGitter> <fridgerator> maybe it was just general profiling
<RX14> yes, it can do profiling
<RX14> memory leak detection is an entirely different beast
<RX14> you can do that on linux with perf/callgrind
<RX14> as in you can do profiling with perf/callgrind
<RX14> memory leak detection has to be crystal-specific
hightower4 has quit [Ping timeout: 272 seconds]
<FromGitter> <jwoertink> I've never done any memory leak detection, but maybe https://github.com/KDE/heaptrack could work with some sort of integration?
<FromGitter> <bcardiff> @RX14, I've only used valgrind in linux (but with C++). http://valgrind.org/ . Probably you already know about it. I am not sure if it would work from a llvm generated binary directly.
<RX14> but valgrind isn't a leak debugger
<RX14> to debug a memory leak you really need to know what objects are on the heap and where they come from
<RX14> no non-crystal-specific tool will be able to know what crystal type an allocation is
<RX14> even then surely all your tool would tell you was that all the memory was allocated by __crystal_malloc
<RX14> which is helpfulβ„’
<FromGitter> <jwoertink> ^ that sounds like the perfect use case for something to be built and added to stdlib. I mean, realistically it's probably super difficult, and how would you know you're leaking memory if the thing that's leaking memory is the thing built with the thing that's leaking memory πŸ˜‚
<FromGitter> <jwoertink> but that would be pretty badass to say crystal had a built-in debugger thing of some sort.
<RX14> i've been thinking how to do that
<RX14> but
<RX14> there's no way to iterate GC allocated objects
<RX14> and I really don't want to register a finalizer on *all* objects
<RX14> I must conclude that crystal will have no way to debug memory leaks until we get a custom GC
<FromGitter> <Timbus> Doesn't libgc offer anything
<FromGitter> <Timbus> http://www.hboehm.info/gc/leak.html eh, kinda
francisl has joined #crystal-lang
<RX14> no, thats for leak-checking C programs
<RX14> it's a leak-checker for finding leaks in programs which are supposed to always call free
<RX14> and crystal uses the GC as a GC
<RX14> and doesn't call free
<FromGitter> <Timbus> Ah. Right, guess that makes some sense
<FromGitter> <bew> What do you mean by "debug memory leaks"? What are you expecting the tool to do?
<RX14> at least show me the composition of the heap by object type
<RX14> hopefully show me what's keeping each object alive
<RX14> and ideally show me where objects are being allocated in the source
<RX14> and I can't even work out how to do the former
<RX14> there's no way to inspect the heap
<RX14> at all
<RX14> this is the point where people who want to use crystal give up
<RX14> they have a memory leak in their first production app and the next step is...
<RX14> give up
<RX14> thats their only choice
<FromGitter> <bew> Hmm I see, that sure would be a nice tool
<RX14> in java i'd fire up a heap profiler and debug it but while we're using libgc we don't even seem to have the option to build such a tool
<FromGitter> <bew> Would it be possible to do that same as libgc when it's scanning the heap?
<RX14> we don't have access to the libgc data structures they're all private
<FromGitter> <Timbus> So, immix gc when
<FromGitter> <Timbus> Oof wait you can't have a moving gc can you
<RX14> im not sure immix is moving
<RX14> or at least it doesnt have to be