RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.0 | 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
<FromGitter> <bew> Hey guys doing some crystal again (at 1am, I just got a crazy idea x) )
<FromGitter> <Blacksmoke16> oh?
<FromGitter> <bew> I'm having a weird error that I don't reproduce in carc.in with the following code
<FromGitter> <bew> ```struct Value ⏎ record Array ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c49020195e17b45259d4244]
<FromGitter> <bew> it crashes while requiring the prelude, when expanding a macro in the stdlib, involving `Array` (the stdlib' one)
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/62r8 this?
<FromGitter> <bew> ah perfect x) I only tried in carcin
<FromGitter> <Blacksmoke16> np :p
<FromGitter> <bew> ok nvm carcin also crashes now ><
<FromGitter> <bew> but this works, whyyy https://carc.in/#/r/62r7
<FromGitter> <bew> aaah it's because I'm overriding the stdlib's `Value`
<FromGitter> <bew> forgot about that one
<FromGitter> <Blacksmoke16> glad to help
<FromGitter> <Blacksmoke16> :p
laaron- has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
sagax has joined #crystal-lang
<FromGitter> <bew> yesss it's working :P I did Rust's multi-type enums in crystal https://carc.in/#/r/62rb
<FromGitter> <bew> time to sleep now..
<FromGitter> <Blacksmoke16> id like if you could have an enum with other values than ints
<FromGitter> <bew> I did something like that above :) I'm not sure we could call it an enum though, and how it could play with current enums
<FromGitter> <Blacksmoke16> ;) fair enough
<FromGitter> <Blacksmoke16> workaround for that currently is module with constants
<FromGitter> <Blacksmoke16> wouldnt really get much over having it in an enum, besides the `?` query methods
<sagax> hi all
<FromGitter> <Blacksmoke16> o/
<FromGitter> <bew> well those constants would not be of the type of the module, and they won't work well in case statement for example (mine does)
<FromGitter> <Blacksmoke16> true
<FromGitter> <Blacksmoke16> in a perfect world then :p
<FromGitter> <Blacksmoke16> its really annoying when you have something like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c491c80cb47ec3000912c07]
<FromGitter> <Blacksmoke16> when `struct IsAdmin < Filter
<FromGitter> <Blacksmoke16> > _<
<FromGitter> <Blacksmoke16> er
<FromGitter> <Blacksmoke16> i forgot the new, nvm in that example :p
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c491ce00a491251e345e9cb]
<FromGitter> <Blacksmoke16> like that too
<FromGitter> <Blacksmoke16> and cant use `of` or `.as`
<FromGitter> <Blacksmoke16> hrm
<FromGitter> <bew> yea that, why not?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c491d3aba355012a489ec24]
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c491d42f780a1521f5beb1d]
<FromGitter> <Blacksmoke16> should be `of Filter | LogicOperator` but same outcome
<FromGitter> <bew> what is matchers?
<FromGitter> <Blacksmoke16> tuple
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/62rf
<FromGitter> <Blacksmoke16> from a splat param
<FromGitter> <bew> maybe a custom `Tuple#to_a` and macro magic could make it work
<FromGitter> <Blacksmoke16> :/
<FromGitter> <Blacksmoke16> I'll have to play around with it I guess
<FromGitter> <bew> yes, no easy fix for that i feat
<FromGitter> <bew> fear
<FromGitter> <bew> lol looks like my crazy idea was already done in #2787 ^^
<FromGitter> <ilanusse> Any reason why there's no `gsub!` in stlib?
<FromGitter> <ilanusse> Only `gsub`
<FromGitter> <girng> @Blacksmoke16 WOW LOL thanks! that's awesome.
<FromGitter> <girng> @mps, thanks
<Yxhuvud> ilanusse: Yes, strings are immutable.
DTZUZO_ has quit [Ping timeout: 250 seconds]
<FromGitter> <j8r> Is there a way to have stack-allocated strings? There are symbols, but we can't create new ones at runtime
<FromGitter> <j8r> I guess slices
<FromGitter> <bew> Slices are not on the stack (not their content at least)
<FromGitter> <yxhuvud> @j8r: to have stack allocated strings, you'd have to know the size at compile-time.
<FromGitter> <j8r> If I assign a string to a constant?
ashirase has quit [Ping timeout: 245 seconds]
<FromGitter> <bew> The strings known at compile time are embedded in a special read only section of the program
<FromGitter> <bew> There is no allocation cost when using them
<FromGitter> <bew> Why do you want them on the stack specifically?
ashirase has joined #crystal-lang
<FromGitter> <j8r> I just want to know more about them :)
<FromGitter> <bew> Did you read the string constructors yet? :)
<FromGitter> <bew> Like what is the data model behind a String object
<FromGitter> <j8r> I see in the big picture what the String is
<FromGitter> <j8r> I was wondering about alternatives and special uses cases like constants
<FromGitter> <bew> Constants are not special, or i don't understand what you mean
<FromGitter> <proyb6> Anyone have experiment websocket with your benchmark?
<FromGitter> <j8r> @bew I don't know, sometimes things are inlined
<FromGitter> <j8r> *I didn't know
[spoiler] has quit [Ping timeout: 246 seconds]
[spoiler] has joined #crystal-lang
<FromGitter> <bew> Sorry but i don't know what you're referring to, can you give an example? @j8r
<FromGitter> <j8r> I was working on the struct passed by value thing
<FromGitter> <j8r> if there are nested, sometimes they are inlined
<FromGitter> <j8r> So i was wondering if constants have optimizations, that's it
DTZUZO_ has joined #crystal-lang
<FromGitter> <j8r> anyway i got the answer, thanks
<FromGitter> <vladfaust> Is it possible to trigger multiple channel subscribers, i.e. https://carc.in/#/r/62tc print `true` exactly two times?
<FromGitter> <Blacksmoke16> @girng 😎
<z64> @vladfaust no; a channel doesn't really have a concept of "subscribers" - that would be a higher level concept, i.e.: `@subscribers = Array(Channel(T))`, `@subscribers.each(&.send(t))`
laaron- has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <kinxer> @Blacksmoke16 You have a 5Ghz processor? :O
<FromGitter> <vladfaust> @z64 alright, I see
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> @kinxer normally runs at 4 to 4.5, but can give it a bit extra when i need it to get it to 5
<FromGitter> <Blacksmoke16> is a nice chip
laaron has quit [Client Quit]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/62ux <_<
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> well thats a bad example
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/62v1
<FromGitter> <Blacksmoke16> that should totally work since, am even type restricting the splat, so welp
<FromGitter> <matthewmcgarvey> Just assignment doesn't work https://play.crystal-lang.org/#/r/62ve
<FromGitter> <Blacksmoke16> normally you could do `of GrandParent`
<FromGitter> <Blacksmoke16> but that doesnt work in this case
<FromGitter> <iambudi> in crystal-db how to use WHERE IN clause and use the args ? ⏎ `db.query “SELECT x FROM y WHERE x.z IN ?”, {1,2}`
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
jemc has joined #crystal-lang
sagax has quit [Ping timeout: 272 seconds]
jemc has quit [Quit: WeeChat 2.2]
jemc has joined #crystal-lang
<FromGitter> <ilanusse> Oh, right, I forgot strings are immutable in Crystal, mb
<FromGitter> <ilanusse> I spent an hour or so porting a number NLP to Crystal just to find out that someone had done that already haha
<FromGitter> <ilanusse> So I just blew up my repo, I liked their code more
<FromGitter> <ilanusse> I'm feeling like porting Chronic 👌 NLPs are fun
<FromGitter> <bew> @Blacksmoke16 https://play.crystal-lang.org/#/r/62wc
<FromGitter> <Blacksmoke16> ❤️
<FromGitter> <Blacksmoke16> @bew you think its intended that it doesn't work out of the box? or is that something that could be a bug?
<FromGitter> <bew> The type restriction doesn't ensure the type of the splat tuple, if you want a tuple with only Grandparent
<FromGitter> <bew> GrandParent types, you have to cast it so the compiler handle it like you want
<FromGitter> <bew> Not a bug
<FromGitter> <Blacksmoke16> shouldnt it just work due to inheritance? like a `Parent` should *be* a `GrandParent` since it inherits from it?
<FromGitter> <Blacksmoke16> i see where you're coming from, is just a pain point for me :shrug:
<FromGitter> <bew> It is, but the binary representation of array of parent could be different from the one for array of grandparent
<FromGitter> <bew> The compiler don't want to guess i guess^^
<FromGitter> <Blacksmoke16> oh well, i can work with that
<FromGitter> <j8r> @ilanusse if you really need to you can modify a string but that's unsafe
<FromGitter> <j8r> and not recommended
<FromGitter> <yxhuvud> .. unless it is stored in the DATA region, which I think all strings created at compile time is.
<FromGitter> <asterite> yup, that will crash the program immediately
<FromGitter> <bew> Definitely not recommended, more like "technically you can, but it's your problem if it doesn't work" ^^ (and yes if you ever try to modify a String in the data segment (a constant String, known at compile time) it'll segfault on you right away)
<FromGitter> <j8r> how can I get the object where I execute a macro?
<FromGitter> <j8r> https://carc.in/#/r/62x0
<FromGitter> <j8r> I need a macro because I use `__LINE__` and `__FILE__`
<FromGitter> <Blacksmoke16> https://carc.in/#/r/62x2 ?
<FromGitter> <j8r> Hoyes indeed, thanks @Blacksmoke16
<FromGitter> <Blacksmoke16> np
<FromGitter> <j8r> @Blacksmoke16 @bew WDYT https://carc.in/#/r/62x5
<FromGitter> <j8r> I'm working on a library with error without stack unwinding, or panics
<FromGitter> <Blacksmoke16> hmm, what would this be used for?
<FromGitter> <j8r> mainly if you want efficient error handling, without each time unwind the stack
<FromGitter> <j8r> for example a web server
<FromGitter> <j8r> instead of raising on 403, 503, which is expensive and someone can use this to DOS your server
rohitpaulk has joined #crystal-lang
<FromGitter> <j8r> do you know if there is a way to know on which method the call is?
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <matthewmcgarvey> You could use the things in Pseudo Constants but it doesn't provide method name https://crystal-lang.org/reference/syntax_and_semantics/constants.html
<FromGitter> <j8r> To know the method where the macro is called
<FromGitter> <Blacksmoke16> hmm, like sec
<FromGitter> <j8r> https://carc.in/#/r/62z3
<FromGitter> <Blacksmoke16> oh thats easy
<FromGitter> <j8r> This is to simulate the `.. myapp.cr in 'mymethod'` of the stack tracw
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/62z8
<FromGitter> <Blacksmoke16> tada
<FromGitter> <j8r> Awesome, you are really the king of macros @Blacksmoke16 😮
<FromGitter> <Blacksmoke16> i try :p
<FromGitter> <Blacksmoke16> those are the only 2 fancy accessors
<FromGitter> <Blacksmoke16> `@type` and `@def`
<FromGitter> <Blacksmoke16> credit goes to @bew for informing me of the def one
<FromGitter> <j8r> So now I can have full featured efficient backtraces :D
<FromGitter> <Blacksmoke16> well there you go
<FromGitter> <j8r> The only thing that is missed is the column number, that's not a big deal
<FromGitter> <Blacksmoke16> yea meh
<FromGitter> <j8r> I don't like raising a previously raises message, that was previously raised etc...
<FromGitter> <j8r> Abusing panics for "normal" errors :/
<FromGitter> <codenoid> hi
<FromGitter> <Blacksmoke16> o/
<FromGitter> <j8r> Hi
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <girng> hi
<FromGitter> <girng> how are you all doing today
<FromGitter> <Blacksmoke16> Fine
<FromGitter> <girng> @Blacksmoke16 you gonna stick with 7700k, or get the new ryzen 2? i heard the new ryzen 2 chips are gonna be amazing. but the 7700k will prob still yield higher GHz
<FromGitter> <Blacksmoke16> if anything id get a new i9
<FromGitter> <Blacksmoke16> 8 core 5ghz
<FromGitter> <girng> yah nice
<FromGitter> <girng> damn
<FromGitter> <Blacksmoke16> but dont really need a new one yet
Creatornator has joined #crystal-lang
<FromGitter> <girng> i've stopped listening to music recently. i think it increases my productivity. i feel more focused
<FromGitter> <Blacksmoke16> 😱
<FromGitter> <fridgerator> Have you ever tried white noise?
<FromGitter> <girng> @fridgerator nope but i did buy my mom a white noise machine to help her sleep. but i havn't tried it in my room
<FromGitter> <noahlh> related to white noise, anyone try coding to this: https://brain.fm/
<FromGitter> <noahlh> the 'focus' tracks have a weird effect -- i can't say for sure they're better, but i def feel different than when coding to normal music or white/brown noise
<FromGitter> <girng> looks interesting
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> Is there any way to do something like this? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c4a121f20b78635b67829a9]
<FromGitter> <dscottboggs_gitlab> I don't see any way to get the values of T in macros, even though it's known at compile-time
<FromGitter> <Blacksmoke16> mmm
<FromGitter> <Blacksmoke16> sec
<FromGitter> <dscottboggs_gitlab> damn it, I'm just trying to shove an any type into things, I should just require a type annotation somehow
<FromGitter> <dscottboggs_gitlab> I'm an idiot! hahaha
<FromGitter> <dscottboggs_gitlab> ``````
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <dscottboggs_gitlab> oh actually that doesn't do what I wanted it to do now that I think about it
<FromGitter> <Blacksmoke16> you want an array of like `[Int32, String]`?
<FromGitter> <Blacksmoke16> i.e. T.class
<FromGitter> <dscottboggs_gitlab> yeah
<FromGitter> <dscottboggs_gitlab> or I could just not overcomplicate things in the first step and leave that for later haha
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/630r
<FromGitter> <Blacksmoke16> how about that?
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <dscottboggs_gitlab> wtf lol
<FromGitter> <Blacksmoke16> `{{"[#{@type.type_vars.first.type_vars.splat}]".id}}` can get rid of the map`
<FromGitter> <Blacksmoke16> want an explanation? :p
<FromGitter> <dscottboggs_gitlab> a bit
<FromGitter> <dscottboggs_gitlab> haha
<FromGitter> <Blacksmoke16> so `@type.type_vars` returns an array literal the of the types in `T`
<FromGitter> <Blacksmoke16> which in this case is an `[Tuple(Int32, String)]`
<FromGitter> <Blacksmoke16> so `.first` selects that tuple
<FromGitter> <dscottboggs_gitlab> oh, that's what I need!
<FromGitter> <Blacksmoke16> then the other `type_vars` selects the generics from the tuple
<FromGitter> <Blacksmoke16> then splat plops them down as comma separated values
<FromGitter> <Blacksmoke16> `{{@type.type_vars.first.type_vars}}` thats prob the better way now that i look at it again
<FromGitter> <Blacksmoke16> 💯
<FromGitter> <dscottboggs_gitlab> that's what I got too https://play.crystal-lang.org/#/r/6311 :D thanks for your help!
<FromGitter> <Blacksmoke16> 👍
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Creatornator has joined #crystal-lang
<FromGitter> <matthewmcgarvey> Looks like that adds nil to the union though
<FromGitter> <matthewmcgarvey> https://play.crystal-lang.org/#/r/6312
<FromGitter> <dscottboggs_gitlab> yeah, it does.
<FromGitter> <dscottboggs_gitlab> here's what I actually ended up using: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c4a1ae635350772cf83e22a]
<FromGitter> <dscottboggs_gitlab> shit, actually, I wrote that when I was gonna use an array, it doesn't make any sense to have a Channel of a Channel
JuanMiguel has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> yeah forget the whole thing
<FromGitter> <Blacksmoke16> :3
JuanMiguel has quit [Quit: Saliendo]
Creatornator has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <Blacksmoke16> man i want to name my new shard something with `Spec` in it, but it conflicts so much with the stdlib `Spec` and gives wrong idea its about testing :/
<FromGitter> <Blacksmoke16> maybe `QuerySpec` would be doable... hmm
<FromGitter> <Blacksmoke16> yea ill go with that
jemc has quit [Ping timeout: 240 seconds]
<FromGitter> <dscottboggs_gitlab> why not just spell out the whole word
<FromGitter> <j8r> I can even add Class name in the backtraces :)
<FromGitter> <j8r> Like ` from src/app.cr:10 in 'MyClass#test'`
_whitelogger has joined #crystal-lang
<FromGitter> <Blacksmoke16> `Specification` is kidna long :/ esp how i set it up now to write it a lot