ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.29.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
ua_ has quit [Ping timeout: 245 seconds]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/730d why arent these the same?
<FromGitter> <watzon> Omg I've been having similar issues with watzon/nacl
<FromGitter> <watzon> Slices are weird because you're playing with shared memory I think
<FromGitter> <Blacksmoke16> but even if you remove the first `to_slice` the other that goes thru the method isnt correct
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/730l :thinking:
<FromGitter> <Blacksmoke16> but assigning it to a var first works?
<FromGitter> <watzon> I have no idea
<FromGitter> <watzon> It's really weird behavior
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> dunno
<FromGitter> <Blacksmoke16> see if any of the Euros have an idea when they get up
<FromGitter> <watzon> Your second try still fails if you attempt to do `pp uuid.to_slice` like you did with the first one
<FromGitter> <watzon> It just fails differently
<FromGitter> <watzon> I feel like I'm missing something about how `to_slice` works behind the scenes
<FromGitter> <Blacksmoke16> Probably
<FromGitter> <Blacksmoke16> We shall see
<FromGitter> <tenebrousedge> 👀
<FromGitter> <tenebrousedge> my theory is that Crystal is sentient and does not like us
alex``` has quit [Ping timeout: 248 seconds]
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
laaron- has quit [Remote host closed the connection]
laaron has joined #crystal-lang
salvor has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
ua has joined #crystal-lang
DTZUZO has quit [Ping timeout: 248 seconds]
<FromGitter> <bararchy> Did any change in 0.29 made it so that HTTP::Server won't automaticlly return a Content-Length header ?
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron- has joined #crystal-lang
relyks has quit [Ping timeout: 244 seconds]
laaron has joined #crystal-lang
laaron- has quit [Ping timeout: 256 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
DTZUZO has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> see if any EU people have an idea, https://play.crystal-lang.org/#/r/730d why arent these the same?
<FromGitter> <Blacksmoke16> it does for me @bararchy, but only if it has a body
<FromGitter> <bararchy> it seems not to work for me , I need to manually set `context.response.content_length = response_body.size`
<FromGitter> <Blacksmoke16> using the raw http server?
<FromGitter> <bararchy> yeha
<FromGitter> <bararchy> unless if you "require" Kemal somehow changes the behavior of naked HTTP::Server
<FromGitter> <Blacksmoke16> i just tried it with
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d078480e527d95addec296c]
<FromGitter> <Blacksmoke16> and worked fine
<FromGitter> <Blacksmoke16> so maybe?
duane has joined #crystal-lang
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
_whitelogger has joined #crystal-lang
alex``` has joined #crystal-lang
laaron has quit [Remote host closed the connection]
<alex```> how to print '\0' ?
<alex```> s/print/emit/
<alex```> oh just "\0"
laaron has joined #crystal-lang
<alex```> '\0' doesn't work?
<FromGitter> <Blacksmoke16> its trying to escape the 0
<FromGitter> <Blacksmoke16> the 0 makes it think its a unicde sequence
<FromGitter> <Blacksmoke16> `A backslash followed by at most three digits ranging from 0 to 7 denotes a code point written in octal:`
lucasb has joined #crystal-lang
<FromGitter> <bew> @watzon I think I know why your uuid thing do that
<FromGitter> <Blacksmoke16> oh?
<FromGitter> <bew> The problem is that `UUID` is a struct, which means that when you pass it to a method, it is copied.. Now when you do `to_slice` on a uuid, it returns a slice of the internal StaticArray of UUID, which is local to the function (on the stack).
<FromGitter> <bew> so by accessing it after the method call you're basically accessing a part of the stack that's not 'yours'
<FromGitter> <Blacksmoke16> interesting
<FromGitter> <Blacksmoke16> but shouldnt the bytes be the same even if it was copied? the bytes that make up the uuid should be the same no?
<FromGitter> <bew> inside the function they are the same, that's why when you print the to_slice inside the function it's still ok
<FromGitter> <bew> but when you're outside, the area used by local variables for the function is "freed" and is used for other things
<FromGitter> <Blacksmoke16> ah so the returned slice do longer represents the uuid
<FromGitter> <bew> yes
<FromGitter> <Blacksmoke16> `value.to_slice.dup` and this works id imagine because dup allocate a section of memory specifically for the bytes?
<FromGitter> <bew> I don't have time now, but if someone can report this back in the form of an issue, I think we should fix that..
<FromGitter> <bew> yes @Blacksmoke16
<FromGitter> <Blacksmoke16> 👍 yea i can make an issue later today
<FromGitter> <Blacksmoke16> def not what someone would expect to happen from that
<FromGitter> <naqvis> Hi All, what is idiomatic way to write equality function on types with optional fields (nilable)? I understand `if var` has limitations on instance and/or class variables, and one can circumvent that via local assignment, but that does clutter the code for complex fields. for exmaple, below one liner won’t pass compiler check, as `field` is optional, and it might have Nil. ⏎ ⏎ ```if other.field &&
<FromGitter> ... (other.field.to_set subset? field.to_set)``` ⏎ ⏎ May be i’m missing some steps or I have to go with local assignment for both objects prior to invoking truthy condition? Any comments and suggestions are highly appreciated. [https://gitter.im/crystal-lang/crystal?at=5d07a76f4e8f972d37369c26]
<FromGitter> <Blacksmoke16> `return unless field`?
<FromGitter> <Blacksmoke16> or could do something like `if (f = other.field) && (f.to_set subset? f.to_set)`
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
<FromGitter> <naqvis> Thanks @Blacksmoke16 , problem arises when performing action on local object. In your example last `f.to_set` should be local optional object and that is where compiler throws error
<FromGitter> <Blacksmoke16> could you make an example on https://play.crystal-lang.org/#/cr?
<FromGitter> <naqvis> sure and thanks
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <naqvis> @Blacksmoke16
laaron has quit [Quit: ZNC 1.7.1 - https://znc.in]
laaron has joined #crystal-lang
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d07ad884e8f972d3736cb68]
<FromGitter> <Blacksmoke16> maybe something like that
<FromGitter> <Blacksmoke16> another option is to just set a default on your features type to an empty array
<FromGitter> <Blacksmoke16> then could do like `return false if features.empty?`
<FromGitter> <Blacksmoke16> vs dealing with nil
<FromGitter> <naqvis> aha, default option should be good choice. Thank you so much @Blacksmoke16
gangstacat has quit [Ping timeout: 258 seconds]
<FromGitter> <Blacksmoke16> np
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
gangstacat has joined #crystal-lang
Yxhuvud has joined #crystal-lang
devil_tux has quit [Ping timeout: 248 seconds]
<FromGitter> <naqvis> I just tried setting default empty array and compiler is still yielding the same error. Is empty array equavalent to Nil?
<FromGitter> <Blacksmoke16> get rid of nilable
<FromGitter> <Blacksmoke16> point being its not going to be nilable if you give it a default
<FromGitter> <naqvis> that’s true and outputting the variable does shows that empty array is assigned. So by having default, i should remove nilable?
<FromGitter> <Blacksmoke16> yes because its not nilable anymore
<FromGitter> <Blacksmoke16> unless you want it to be, which you do not
<FromGitter> <naqvis> thanks, seems I was confused with the documentation of `default` key. I thought having default value will override that, but seems this is not the case
<FromGitter> <naqvis> *default*: value to use if the property is missing in the JSON document, or if it's `null` and `nilable` was not set to `true`. If the default value creates a new instance of an object (for example `[1, 2, 3]` or `SomeObject.new`), a different instance will be used each time a JSON document is parsed.
<FromGitter> <Blacksmoke16> well no, it can have a default but be nilable
<FromGitter> <Blacksmoke16> like if you kept nilable: true you could still do like
<FromGitter> <naqvis> doesn’t that contradict?
<FromGitter> <naqvis> when we have default value how that can be nil?
<FromGitter> <Blacksmoke16> obj.features = nil
<FromGitter> <Blacksmoke16> since the *type* of features still allows nil
<FromGitter> <naqvis> so Union is in effect here
<FromGitter> <naqvis> make sense. Thank you @Blacksmoke16
<FromGitter> <Blacksmoke16> thats what nilable does, just adds `Nil` to the property's type
<FromGitter> <naqvis> Thank you
<FromGitter> <Blacksmoke16> np
<FromGitter> <naqvis> one more question though, what is equalvalent of `this` in Crystal? i.e. how can we refer to same object?
<FromGitter> <Blacksmoke16> `self`
<FromGitter> <naqvis> i tried that, but seems i’m not getting that right ⏎ ⏎ ```def compatible_with(target : self) ⏎ return target.can_run(self) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5d07bb63a8d9871b32a3fb5e]
<FromGitter> <naqvis> my intention is to pass current obj to target object
<FromGitter> <Blacksmoke16> whats the error you're getting?
<FromGitter> <naqvis> I’m expecting a boolean, but this is giving me something different
<FromGitter> <Blacksmoke16> dont need the `return` keyword as well
<FromGitter> <naqvis> yeah sure
<FromGitter> <Blacksmoke16> got an example of what you're getting?
<FromGitter> <naqvis> removing that `return` is returning bool, while having `return` was returning `(NamedTuple | Nil)`
<FromGitter> <Blacksmoke16> :thinking:
<FromGitter> <Blacksmoke16> can you make another playground link?
<FromGitter> <naqvis> yeah, doing that
<FromGitter> <naqvis> sorry, can’t reproduce that, seems I might have messed up on my local playground :(
<FromGitter> <Blacksmoke16> rgr
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
<FromGitter> <PlayLights_twitter> Hello :) Is `Mutex` ready for use? I see on the class definition `TODO this is not thread-safe yet.`but I need it
<FromGitter> <Blacksmoke16> its mainly for fibers atm since crystal doesnt have mutli threads yet anyway
rohitpaulk has joined #crystal-lang
<FromGitter> <PlayLights_twitter> Since I'm using Kemal and it use fibers, it supposed it should work right?
<FromGitter> <Blacksmoke16> yes but what are you trying to do, a request in one fiber shouldnt affect another request
<FromGitter> <naqvis> Can we not explicitly type annotate constants? as annotating constant is yielding `unexpected token: :`
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <Blacksmoke16> example?
<FromGitter> <Blacksmoke16> like `FOO : String = "Fred"`?
<FromGitter> <naqvis> ```TEST : String = “abc”```
<FromGitter> <Blacksmoke16> there isnt really a point
<FromGitter> <Blacksmoke16> it get inferred from the value, and you cant change it
<FromGitter> <Blacksmoke16> so its kinda redundent
<FromGitter> <naqvis> yeah I know, but what if i want to annotate my own type?
<FromGitter> <naqvis> could be an alias or could be something
<FromGitter> <PlayLights_twitter> @Blacksmoke16 I mean there is an issue on crystal-db where too many fibers are creating connections at the same time overpassing the`max_connections`. So I tried using a lock with a variable, but on high load on a Xeon it still doesn't work so I think using mutex should work to avoid that.
<FromGitter> <PlayLights_twitter> (I'm planning to buy the 'The art of concurrency book', all of this is pretty interesting)
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> @naqvis not sure what you mean, if you assign something to a constant the type of the constant would just be what you assign it
<FromGitter> <Blacksmoke16> do you have an example of what you are trying to do?
<FromGitter> <naqvis> Yeah, I understand that. But what if like to define different types, for example for my use case I could type alias String to `MediaType`
<FromGitter> <Blacksmoke16> @PlayLights_twitter yea i dunno, not super familiar with that, are you using the shard directly or via an ORM?
<FromGitter> <naqvis> kind of creating own types and using that terminology through the code, to make that easier to read
<FromGitter> <Blacksmoke16> `alias MediaType = String`?
<FromGitter> <naqvis> yeah
<FromGitter> <Blacksmoke16> yea just do that then?
<FromGitter> <naqvis> but constant defined without type annotation will still infer that as String
<FromGitter> <naqvis> shouldn’t the compiler treat different types differently? even if they are alias
<FromGitter> <Blacksmoke16> sec
<FromGitter> <naqvis> sure
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/732t
<FromGitter> <naqvis> thank you so much :). So have to cast that via `as`
<FromGitter> <Blacksmoke16> yes
<FromGitter> <naqvis> big thanks
<FromGitter> <Blacksmoke16> np
lucasb has quit [Quit: Connection closed for inactivity]
alex``` has quit [Quit: WeeChat 2.5]
<FromGitter> <PlayLights_twitter> @Blacksmoke16 im using crystal-db, cystal-mysql, and granite, but the issue is from crystal-db #77 (https://github.com/crystal-lang/crystal-db/issues/77), I'll try to use Mutex to see if it works.
<FromGitter> <Blacksmoke16> gotcha, good luck
<FromGitter> <naqvis> interesting enough, printing type is still going to print its base type, this is totally different from other languages, where compiler will treat UDT differently. pseudo_method `is_a? returns true for both alias as well as base type. While in different languages same case doesn’t stand.
<FromGitter> <naqvis> so is this alias just a compile-time syntatic sugar?
<FromGitter> <Blacksmoke16> what that ⏎ ⏎ ```pp VALUE.is_a? String ⏎ pp VALUE.is_a? FooString``` [https://gitter.im/crystal-lang/crystal?at=5d07ce088e050f62aa357af2]
<FromGitter> <Blacksmoke16> is true for both?
<FromGitter> <naqvis> yeah
<FromGitter> <Blacksmoke16> but its true?
<FromGitter> <naqvis> this isn’t the case with go (just an example)
<FromGitter> <Blacksmoke16> im pretty sure alias just is a wrapper to another type/union of types
<FromGitter> <Blacksmoke16> vs defining a unique type
<FromGitter> <naqvis> where types declared are totally different ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d07ce96bc56c731f8d698e5]
<FromGitter> <Blacksmoke16> i dunno, imo it makes sense that it should pass
<FromGitter> <Blacksmoke16> since the type is just a diff name to a string type
rohitpaulk has quit [Remote host closed the connection]
<FromGitter> <naqvis> agree as we are unable to extend types, so technically speaking alias is just same as base type, its just a syntactical sugar for developers to use. While go does allow extending types, so at runtime two types might not be same
<FromGitter> <Blacksmoke16> main benefit of alias is to shorten types and can also do recursive types (although that isnt usually the best option)
<FromGitter> <naqvis> apologies for irrelevant questions, as I might be in process of adjusting my brain to this amazing language
<FromGitter> <Blacksmoke16> np
<FromGitter> <Blacksmoke16> `Every time you use an alias the compiler replaces it with the type it refers to.`
<FromGitter> <Blacksmoke16> so since your alias is just `String` its essentially the same as doing `.as(String)`
<FromGitter> <naqvis> that clarifies, so aliases are lived till compile time
<FromGitter> <Blacksmoke16> yea
<FromGitter> <naqvis> based on today discussion, does that mean that we won’t have RTTI? or that is something planned for future?
devil_tux has joined #crystal-lang
<FromGitter> <Blacksmoke16> there is no runtime reflection atm, but can use `typeof` to get the type of a variable
<FromGitter> <naqvis> yeah sure, but those are still compile time info, as after compilation, UDT info info is gone and we are back to language types
<FromGitter> <naqvis> so each string can still be identified as alias, even if that’s isn’t something which was annotated using alias
<FromGitter> <Blacksmoke16> hmm, imma go with no
<FromGitter> <Blacksmoke16> but crystal is actually my first compiled lang so not super familiar with how it works in other langs haha
<FromGitter> <naqvis> i’m not comparing Crystal with other languages, its just trying to get my head fit into Crystal :D
lucasb has joined #crystal-lang
<FromGitter> <Blacksmoke16> all good
<FromGitter> <naqvis> `pp "Foo".is_a? FooString => true` though I didn’t annotate this with udt, but compiler treat each String instance same
<FromGitter> <Blacksmoke16> essientailly that is the same as `pp "Foo".is_a? String`
<FromGitter> <naqvis> yeah
<FromGitter> <naqvis> but technically we might need to distinguish between different types
<FromGitter> <watzon> You could Always wrap `String` with another class and just `delegate` all it's methods to an internal string buffer.
<FromGitter> <watzon> Because I don't think `String` can be extended
<FromGitter> <watzon> And as you've seen, `alias` is very similar to c++ `define`
<FromGitter> <naqvis> yeah true, i tried that approach and non abstract `structs` can’t be extended
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/733a he means like this
<FromGitter> <watzon> I forgot `record` existed
<FromGitter> <watzon> But exactly
<FromGitter> <naqvis> Thank you
<FromGitter> <watzon> You could even do something like this to make it so you don't have to instantiate with `.new`
<FromGitter> <watzon> Just cleans things up a tiny bit imo
<FromGitter> <naqvis> 👏
devil_tux has quit [Ping timeout: 248 seconds]
devil_tux has joined #crystal-lang
devil_tux has quit [Ping timeout: 248 seconds]
devil_tux has joined #crystal-lang
devil_tux has quit [Ping timeout: 244 seconds]
<FromGitter> <naqvis> when defining a new type, what method need to be overridden to allow casting to type? currently i’m getting `can't cast Foo to Bar`
<FromGitter> <naqvis> this is received when pseudo method `as` is invoked
<FromGitter> <naqvis> i can’t override pseudo method, so believe there should be some other way to achieve the same
<FromGitter> <Blacksmoke16> well if they arent compatible types i dont think you can
<FromGitter> <Blacksmoke16> got an example?
<FromGitter> <naqvis> same way, when using `from_json` i’m receiving that error
<FromGitter> <naqvis> `can’t cast String to FakeString`
<FromGitter> <Blacksmoke16> well you cant directly cast String to FakeString, they are compatible in the same way you can do `true.as(String)`
<FromGitter> <naqvis> thanks
<FromGitter> <Blacksmoke16> what are you trying to do?
<FromGitter> <naqvis> in JSON.mapping i’ve provided that derived type, implemented json marshalling method one which accepts `JSON::PullParser`, now when invoking instance via `from_json`, macro expanding is failing with above cited error
<FromGitter> <naqvis> seems I might have to revert back to String
<FromGitter> <watzon> Why are you trying to use `FakeString` anyway?
<FromGitter> <Blacksmoke16> ^
<FromGitter> <watzon> What's the poine?
<FromGitter> <naqvis> my use case is String containing two parts like “algo:digest”, so I thought of doing that in respective derived type, instead of treating that as string
<FromGitter> <naqvis> I’m working on json parser to work with end-point
<FromGitter> <Blacksmoke16> could use an enum
<FromGitter> <Blacksmoke16> er nvm
<FromGitter> <naqvis> but enum is restricted to integer values
<FromGitter> <naqvis> at least that’s what I understand from documentation
<FromGitter> <Blacksmoke16> yea
<FromGitter> <Blacksmoke16> you got a playground link of what you got so far?
<FromGitter> <Blacksmoke16> i have an idea
<FromGitter> <naqvis> let me put that in playground
<FromGitter> <naqvis> just put related components into one playground
<FromGitter> <naqvis> 😄
<FromGitter> <Blacksmoke16> might be able to use https://crystal-lang.org/api/master/MIME.html#register%28extension%3AString%2Ctype%3AString%29%3ANil-class-method
<FromGitter> <Blacksmoke16> just as a first thought after seeing content type header style stuff
<FromGitter> <naqvis> sure and thanks @Blacksmoke16 , let me take a quick look
<FromGitter> <Blacksmoke16> which you seem to be recreating https://crystal-lang.org/api/master/MIME/MediaType.html
alex`` has joined #crystal-lang
<FromGitter> <naqvis> Thanks @Blacksmoke16
<FromGitter> <Blacksmoke16> was that something you can use?
<FromGitter> <naqvis> yeah, definitely
<FromGitter> <Blacksmoke16> cool
<FromGitter> <naqvis> i’m looking into that
<FromGitter> <naqvis> thanks again @Blacksmoke16
<FromGitter> <Blacksmoke16> np
duane has quit [Ping timeout: 245 seconds]
devil_tux has joined #crystal-lang
<FromGitter> <naqvis> @Blacksmoke16 actually I was missing `converter` key in my `JSON.mapping`. I’ve implemented converter interface and am able to use my own types
<FromGitter> <naqvis> 😃
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <naqvis> thank you again for all patience and guidance in right direction
<FromGitter> <Blacksmoke16> np
devil_tux has quit [Ping timeout: 258 seconds]
early` has joined #crystal-lang
early has quit [Ping timeout: 258 seconds]
ashirase has quit [Ping timeout: 246 seconds]
ashirase has joined #crystal-lang
sz0 has joined #crystal-lang
<FromGitter> <watzon> What would be the best way to accomplish something like this with fibers? https://github.com/vesselinv/glove/blob/master/lib/glove/workers/cooccurrence_worker.rb#L27
<FromGitter> <watzon> Or would there even be any benefit? I still don't understand fibers super well/.
<FromGitter> <watzon> That particular library is using this https://github.com/grosser/parallel
<FromGitter> <watzon> Which I know we can't do in Crystal yet
lvmbdv has quit [Quit: brb]
laaron has quit [Remote host closed the connection]
laaron has joined #crystal-lang
ashirase has quit [Ping timeout: 246 seconds]
<FromGitter> <omidathari> Hi All, ⏎ In the code below, would you expect the pointer to the first byte of the string to be the same as the pointer of the string ⏎ https://carc.in/#/r/734m
<FromGitter> <watzon> I don't think so. I'm fairly certain there is some additional metadata allocated before the first byte of the string
<FromGitter> <omidathari> @watzon Isn't it interesting that the first byte is actually one byte behind the pointer of the string though?
<FromGitter> <watzon> You should see what the value of the real first byte is
<FromGitter> <watzon> I'd be willing to bet it's always the same value. I think it's metadata saying "what comes after is a string" or something
<FromGitter> <omidathari> bytes pointer = Pointer(Array(UInt8))@0x7fff45e18368 ⏎ byte pointer = Pointer(UInt8)@0x7fff45e18367 ⏎ bytes pointer value = [77, 121, 32, 83, 116, 114, 105, 110, 103] ⏎ byte pointer value = 77 [https://gitter.im/crystal-lang/crystal?at=5d0822d2bc56c731f8d9c34d]
wymillerlinux has quit [Ping timeout: 268 seconds]
<FromGitter> <watzon> Interesting
<FromGitter> <watzon> https://carc.in/#/r/7350
<FromGitter> <watzon> It looks like right before a String is always 40192 and before an Array is 40960