<FromGitter>
<watzon:matrix.org> That could work as well
<FromGitter>
<watzon:matrix.org> `.try` is great
<FromGitter>
<watzon:matrix.org> Though I do have to say, the `try` and `not_nil!` methods make me wish `!` and `?` weren't valid ident pieces. It would be nice to be able to use a `!` postfix for `not_nil!` and a `?` postfix as an implicit `try`.
sagax has quit [Ping timeout: 245 seconds]
<FromGitter>
<js:nil.im> btw, if I create a Slice(UInt8).new(2), but access slice[3] = 1 - will that increase the size of the slice or raise?
<FromGitter>
<Blacksmoke16> idk, try it and find out? My vote is on raise
<FromGitter>
<js:nil.im> well, trying out is one way to figure out the state *now*, but not the API contract π
<FromGitter>
<watzon:matrix.org> Pretty sure it's either a raise or undefined behavior
<FromGitter>
<watzon:matrix.org> Since a slice is a wrapper around a pointer
<FromGitter>
<watzon:matrix.org> Yep, it raises
<FromGitter>
<watzon:matrix.org> Also, `Bytes` is an alias for `Slice(UInt8)`
<FromGitter>
<js:nil.im> ah, thx π
<FromGitter>
<js:nil.im> Bytes sounds much nicer π
<FromGitter>
<watzon:matrix.org> Also, if you do need something resizable you can always use `IO::Memory`. Slices aren't resizable afaik.
<FromGitter>
<js:nil.im> ```code paste, see link``` β β The compiler complains here that `sock` is `UDPSocket | Nil`. I suppose that is because I declare the variable without assigning it and it therefore implicitly adds a `?`? [https://gitter.im/crystal-lang/crystal?at=60417a395d0bfb4e58898335]
<FromGitter>
<js:nil.im> ah nvm
<FromGitter>
<js:nil.im> what is the preferred way to copy from a `String` into `Bytes`?
<FromGitter>
<watzon:matrix.org> Copy or convert?
<FromGitter>
<js:nil.im> copy in as ASCII
<FromGitter>
<js:nil.im> should throw if there's any non-ASCII chars
<FromGitter>
<js:nil.im> or copy them verbatim, I don't care π
<FromGitter>
<js:nil.im> (then the NS will just reject it)
<FromGitter>
<watzon:matrix.org> Because `String#to_unsafe` will grab the underlying utf8 encoded bytes.
<FromGitter>
<watzon:matrix.org> So `String#to_unsafe.clone` should copy the slice
<FromGitter>
<js:nil.im> and I suppose this does length checks and won't just overflow, correct?
<FromGitter>
<watzon:matrix.org> Hard to tell without seeing the surrounding code if this is the best way to do things. If your writing a bunch of bytes it might make more sense to use an IO.
<FromGitter>
<js:nil.im> I need to construct one UDP packet with a max size of 512 bytes
<FromGitter>
<js:nil.im> once this is done, would this be something that could be considered for inclusion in stdlib? I think it would be useful to basically move everything that uses DNS to async π
<FromGitter>
<watzon:matrix.org> I'm sure it's something that would be considered
<FromGitter>
<js:nil.im> what would be the requirements for that? I mean, there'll obviously be plenty of feedback and I'll address that. But other than that? I suppose Apache license?
<FromGitter>
<watzon:matrix.org> MIT I believe. Once you have a working library I'd ask in the forum and get some feedback from the maintainers, then open a PR.
<FromGitter>
<js:nil.im> happy to put this under any license. The original (from ObjFW) is GPLv2/3/QPL, but I'm happy to relicense, obviously
<FromGitter>
<watzon:matrix.org> The licence that's generally created with `crystal init` is MIT, so that's what most people tend to go with
<FromGitter>
<watzon:matrix.org> And I believe that's what Crystal itself is licensed under
<FromGitter>
<js:nil.im> I'm looking at the Socket documentation, but cannot find anyhting about async receives?
<FromGitter>
<watzon:matrix.org> Idk much about that myself
<FromGitter>
<watzon:matrix.org> Usually when I find the crystal docs lacking I go one of two places. If it's an implementation detail I'll usually check the Ruby docs/questions since Crystal and Ruby are still similar enough. If I can't find a good answer there I do the same with Go. Surprisingly enough Go and Crystal share a lot in common.
<FromGitter>
<watzon:matrix.org> Especially where concurrency is concerned.
<FromGitter>
<js:nil.im> I β¦ suppose the correct way is to use a fiber and blocking I/O?
deavmi has quit [Read error: Connection reset by peer]
<FromGitter>
<js:nil.im> ok, so, if I have a fiber that is in receive, but I call close from another fiber, I get IO::Error on the fiber that is in the receive. Which is fine. If only there would be a way to tell this IO::Error apart from another. Anything I can do?
bazaar has quit [Ping timeout: 245 seconds]
<FromGitter>
<watzon:matrix.org> You could have a receive channel, a send channel, and a close channel
<FromGitter>
<watzon:matrix.org> Crystal also has `select` blocks, but they're some undocumented voodoo
<FromGitter>
<bararchy> I think i'm hitting this one as well
<FromGitter>
<bararchy> and not sure if anyone had a chance to work around it
hendursa1 has joined #crystal-lang
hendursaga has quit [Ping timeout: 268 seconds]
<FromGitter>
<naqvis> @bararchy that's happening because of tight loop invocation, thus giving GC no chance to breathe. Adding a small sleep after some invocations, will make it pass the test
<FromGitter>
<naqvis> i've tested the same code on linux vm running from my mac, as was able to get through that 100K limit without OOM
<frojnd>
So I have a module named: `Foo` foo.cr file I have a bunch of functions inside that module. Now in another file named bar.cr and I would like to call functions from that bar.cr file. I tried like this: include Foo; pp function_name but I got: Error: undefined constant Foo for include Foo
<FromGitter>
<naqvis> `Module` are Class in disguise. so you can invoke methods which are static or defined as class methods with `self`
<FromGitter>
<naqvis> either go with `extend self` or if you want only few methods to be marked as static then append `self` like in Bar example
hightower2 has quit [Ping timeout: 256 seconds]
<frojnd>
Hm I still get Error: undefined constant Foo
<frojnd>
Do I have to have naming of the file in order with module names too?
<frojnd>
I mean your code works if it's in one file.. but if separated
<FromGitter>
<asterite> frojnd: maybe provide some code?
<FromGitter>
<asterite> you can add `{% puts "hello" %}` inside `foo.cr` to know if it's being required or not
<frojnd>
Ouch didn't require "./foo.cr"
<frojnd>
One question regarding naming conventions... file name is `foo_bar.cr` inside would be better to have `module FooBar` or `module Foo::Bar` or would later be better for `foo-bar.cr` file?
<straight-shoota>
I'd place Foo::Bar in foo/bar.cr
hendursa1 has quit [Remote host closed the connection]
hendursa1 has joined #crystal-lang
hightower3 has joined #crystal-lang
_ht has quit [Read error: Connection reset by peer]
_ht has joined #crystal-lang
<FromGitter>
<roduquen> @j8r Hey, I got the issue, not about code, about port... 5060 not allowed on browser, so I wasn't able to connect to the websocket server just because of the 5060..
<FromGitter>
<jrei:matrix.org> 5060 is Session Initiation Protocol (SIP)
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<jrei:matrix.org> by the way, better to choose classic "free" ports like 808x or 3000
<FromGitter>
<jrei:matrix.org> this case was strange though
hendursaga has joined #crystal-lang
hendursa1 has quit [Ping timeout: 268 seconds]
duane has joined #crystal-lang
duane has quit [Ping timeout: 264 seconds]
ua_ has quit [Ping timeout: 256 seconds]
ua_ has joined #crystal-lang
_ht has quit [Remote host closed the connection]
<Stephie>
so, how stable is preview_mt these days?
<straight-shoota>
Hey, nice to see you around =)
<straight-shoota>
don't think there has been much work on it in the last year...
<straight-shoota>
but people seem to be using it and looks like it can't be too bad
<hightower3>
@watzon were you the one who at one point pasted a short program showing which chars (mostly from utf-8 set) are accepted in method names?
<FromGitter>
<watzon:matrix.org> Itβs possible, but if so I donβt remember it
<hightower3>
ok nm, found a way to document what I needed
<hightower3>
tx
<FromGitter>
<alexherbo2> can the json parser parse chunks in an array?, similarly to jq with the `--slurp` option?
<FromGitter>
<jrei:matrix.org> split the string yourself, then use `Array.from_json`
<FromGitter>
<alexherbo2> how?
<FromGitter>
<alexherbo2> the chunk can span multiple liens
<FromGitter>
<alexherbo2> lines*
<FromGitter>
<jrei:matrix.org> `string.each_line { |line| Array(String).from_json line }`
<FromGitter>
<Blacksmoke16> could you do like `string.each_line.map`?
<FromGitter>
<alexherbo2> it only works if it's a one liner, I would like to abstract to parses the chunk in an array or have the chunks already in an array
<FromGitter>
<Blacksmoke16> could install `oq` as a lib and use that π
<FromGitter>
<alexherbo2> no I cannot ensure it will be a single line
<FromGitter>
<jrei:matrix.org> why do you want to do this way?
<FromGitter>
<jrei:matrix.org> I don't understand what's your requirement
<FromGitter>
<alexherbo2> to send commands to kakoune as chunk or a big array
<FromGitter>
<jrei:matrix.org> I mean, why my proposal don't work?