ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.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
straight-shoota has quit [Ping timeout: 244 seconds]
<FromGitter> <tenebrousedge> yay, getting all the way to an invalid memory access! progress! https://play.crystal-lang.org/#/r/8zfe
<FromGitter> <tenebrousedge> probably trying to use C at all here is my first mistake
<FromGitter> <naqvis> i would say its `empties` which is causing this segfault. as simply calling `sscanf` like below works ⏎ ⏎ ```val = uninitialized Int32 ⏎ LibC.sscanf("aa bb a 2 ee", "aa bb a %d ee",pointerof(val))``` [https://gitter.im/crystal-lang/crystal?at=5eaa29df14b48f06989d265e]
<FromGitter> <tenebrousedge> yeah I figured that I should probably be using pointers
<FromGitter> <tenebrousedge> this is probably mostly a stupid idea
<FromGitter> <naqvis> your idea is neat
<FromGitter> <naqvis> and that macro thing is too scary for me
<FromGitter> <tenebrousedge> oh well ty
<FromGitter> <naqvis> 😆
<FromGitter> <tenebrousedge> well I'll poke at it tomorrow
<FromGitter> <naqvis> sure thing
<FromGitter> <tenebrousedge> thanks for the tip
<FromGitter> <naqvis> thanks and just shared my thoughts
deavmi has quit [Ping timeout: 264 seconds]
deavmi has joined #crystal-lang
<FromGitter> <jwaldrip> @tenebrousedge I use it to switch on log/debug settings
<FromGitter> <jwaldrip> but the release flag would tell me that its optimized
<FromGitter> <Blacksmoke16> @jwaldrip you make an issue about that yet?
<FromGitter> <jwaldrip> @Blacksmoke16 one better, here is the PR
<FromGitter> <Blacksmoke16> :vince: nice
<FromGitter> <jwaldrip> I caught it just as you did :-)
zorp_ has joined #crystal-lang
zorp has quit [Ping timeout: 260 seconds]
DTZUZU2 has joined #crystal-lang
DTZUZU has quit [Ping timeout: 244 seconds]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
alexherbo2 has joined #crystal-lang
_ht has joined #crystal-lang
zorp_ has quit [Ping timeout: 246 seconds]
cyberarm has quit [Quit: killed]
beepdog has quit [Quit: killed]
juanfra_ has quit [Quit: killed]
olbat[m] has quit [Quit: killed]
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
juanfra_ has joined #crystal-lang
flips has quit [Remote host closed the connection]
beepdog has joined #crystal-lang
olbat[m] has joined #crystal-lang
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
straight-shoota has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> hello
<FromGitter> <tenebrousedge> o/
<FromGitter> <ImAHopelessDev_gitlab> i am starting to express abstract ideas and convert them into code. better and better. i think i'm doing something right
<FromGitter> <ImAHopelessDev_gitlab> maybe just practice
<FromGitter> <tenebrousedge> :plus1:
alexherbo2 has joined #crystal-lang
<FromGitter> <naqvis> 👍 Girng
<FromGitter> <naqvis> Girng shouldn't you now change your id to `ImAHopefulDev` lol
<FromGitter> <alehander92> yeah i like your progress man
<FromGitter> <alehander92> very hopeful!
sagax has quit [Read error: Connection reset by peer]
ua_ has quit [Ping timeout: 256 seconds]
ua_ has joined #crystal-lang
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
rocx has quit [Quit: 👏 developers 👏 developers 👏 developers 👏 developers 👏 developers]
rocx has joined #crystal-lang
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<repo> ah
<repo> ups
<repo> wrong chat
straight-shoota has quit [Read error: Connection reset by peer]
alexherbo26 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo26 is now known as alexherbo2
<FromGitter> <watzon> Is there an easy way to perform a strip operation on an IO without converting it to a string and back?
<FromGitter> <watzon> Or a slice for that matter. I just need to remove null bytes from the end.
<FromGitter> <tenebrousedge> hmmm, maybe there's a chomp option
<FromGitter> <tenebrousedge> but why does it have null bytes?
<FromGitter> <watzon> For padding
<FromGitter> <tenebrousedge> what are you doing with it?
<FromGitter> <watzon> I guess if I could find the index of the first null byte I could actually create a new slice from a pointer of the section that doesn't have the null bytes
<FromGitter> <tenebrousedge> that sounds reasonable
<FromGitter> <watzon> I need to convert a bytes slice into a UInt32 slice, but that requires that values be properly padded to 4 bytes
<FromGitter> <watzon> Then I need to be able to convert it back, but that ends up giving me the padding so I just need a way to remove it, and I want to not perform any unnecessary string allocations.
<FromGitter> <naqvis> doesn't your slice contains byte encoded UInt32?
<FromGitter> <tenebrousedge> can you use `IO::Delimited` ?
<FromGitter> <watzon> Ooh didn't even know that was a thing
<FromGitter> <watzon> I've never used it
<FromGitter> <tenebrousedge> I think that might help
<FromGitter> <watzon> I wish adding slices together was an easier task, it would make adding the padding in the first place a little easier
<FromGitter> <tenebrousedge> <_< that seems like it's verging on an x y problem
<FromGitter> <naqvis> you could do that `Pointer` and `realloc` and then `copy_from` to concatenate slices
<FromGitter> <watzon> Yeah that's what I figured
<FromGitter> <naqvis> or simple solution would be to create a new slice of combined size and then copy them into appropriately
<FromGitter> <tenebrousedge> ^
<FromGitter> <naqvis> kind of requesting extra space before discarding the existing slices (provided slice size isn't that huge)
<FromGitter> <watzon> How do do you to `#copy_to` at a specific offset?
<FromGitter> <naqvis> `slice[1000..].copy_from(pointer, size)`
<FromGitter> <watzon> Ahhh smart
<oprypin> very smart indeed :>
alexherbo22 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo22 is now known as alexherbo2
straight-shoota has joined #crystal-lang
<FromGitter> <tenebrousedge> does that work?
<FromGitter> <tenebrousedge> `[]` says it returns a new slice
<FromGitter> <watzon> It does
<FromGitter> <watzon> There's probably a better way to do this, but at the very least this should be more efficient than converting slices to Strings and then back again
<FromGitter> <watzon> https://carc.in/#/r/8zm4
<FromGitter> <tenebrousedge> well, right on. Whatever works
<FromGitter> <watzon> I just want to figure out a better way to do the `unpad_slice` function. Right now it will just take the first null byte and get its index, but I want it to only do grab null bytes at the end
<FromGitter> <watzon> But for now it should work. The byte slices I'm dealing with shouldn't have any null bytes until they're padded.
<FromGitter> <naqvis> @tenebrousedge documentation is somewhat misleading, `[]` doesn't allocate new memory, but just move the slice already allocated pointer to particular offset
<FromGitter> <naqvis> that's why this works
<FromGitter> <naqvis> i've used it extensively
<FromGitter> <tenebrousedge> kk
<yxhuvud> it creates a new slice but reuses the pointer
zorp_ has joined #crystal-lang
<FromGitter> <naqvis> it creates a new reference to already allocated slice block and so i said "doesn't allocate new memory"
<FromGitter> <naqvis> kind of mutable view of already created slice
<FromGitter> <naqvis> mutability depends on how initial slice (against which you are requesting this view). If initial slice was read-only, then you will get read-only view
ht_ has joined #crystal-lang
_ht has quit [Ping timeout: 258 seconds]
ht_ is now known as _ht
<FromGitter> <tenebrousedge> @naqvis almost there https://play.crystal-lang.org/#/r/8zm6
<FromGitter> <tenebrousedge> I should probably combine my hashes
zorp_ has quit [Ping timeout: 260 seconds]
<FromGitter> <naqvis> wow, it just got more complex
<FromGitter> <tenebrousedge> nah, I just copy-pasted a hash
<FromGitter> <tenebrousedge> it blows up if I try to use `%s`
<FromGitter> <tenebrousedge> I'm a little worried I need to reimplement `sscanf` entirely in Crystal
<FromGitter> <naqvis> that must be because of `pointerof(String)`
<FromGitter> <tenebrousedge> yes
alexherbo2 has quit [Read error: Connection reset by peer]
<FromGitter> <naqvis> not sure if you tried `va_list` approach?
<FromGitter> <tenebrousedge> how?
<FromGitter> <naqvis> `sscanf` has an overload, which accepts `va_list`
<FromGitter> <naqvis> like `vsscanf`
<FromGitter> <tenebrousedge> right
<FromGitter> <tenebrousedge> but how do I do `va_list` in Crystal?
<FromGitter> <naqvis> but thing is in Crystal they have `va_list` defined as 1 index array
<FromGitter> <naqvis> they have it in `c/stdarg` defined
<FromGitter> <naqvis> and there is a struct `VaList`
<FromGitter> <tenebrousedge> well I'll be meowed
alexherbo2 has joined #crystal-lang
<FromGitter> <naqvis> i tried this `#open`
<FromGitter> <naqvis> it at least doesn't segfault
<FromGitter> <naqvis> but couldn't get the predicted output
<FromGitter> <tenebrousedge> hmm. I think that the `map` is the problem
<FromGitter> <tenebrousedge> that `pointerof` is giving a pointer to the block var
<FromGitter> <naqvis> changing `String` to `LibC::Char` doesn't blow-up
<FromGitter> <naqvis> but don't know if that's going to yield required outcome
<FromGitter> <tenebrousedge> I think that just gets me the first char
<FromGitter> <naqvis> yeah, agree so
<FromGitter> <watzon> Do we have something like this built in? https://golang.org/pkg/math/big/#Int.Exp
<FromGitter> <tenebrousedge> I don't think so?
<FromGitter> <naqvis> `(x ^^ y) % m.abs` ?
<FromGitter> <naqvis> will that work?
<FromGitter> <watzon> I guess we shall see
<FromGitter> <watzon> Shouldn't it be `x ** y`?
<FromGitter> <naqvis> aah yeah
<FromGitter> <naqvis> exponent
<oprypin> well it is the same thing just much less efficient
<FromGitter> <watzon> That's what I thought. So we don't have anything built in that does this a bit more efficiently?
lanodan has quit [Quit: WeeChat 2.7.1]
sagax has joined #crystal-lang
<FromGitter> <tenebrousedge> there we go: ⏎ https://play.crystal-lang.org/#/r/8zmh
<FromGitter> <tenebrousedge> hmm, still need to do type coercion
<FromGitter> <naqvis> wow 👍
<FromGitter> <tenebrousedge> is it sane to return `Tuple(Pointer(Int32), Pointer(Float32))` ?
<FromGitter> <tenebrousedge> doing `map(&.value)` produces a union type
<FromGitter> <tenebrousedge> which, sort of the point is to avoid that
<FromGitter> <tenebrousedge> doing `unsafe_as` returns garbage
<FromGitter> <naqvis> yeah i found that, thought that's why you were casting back via `unsafe_as(type)`
<oprypin> tenebrousedge, at that point just drop libc lol
<FromGitter> <tenebrousedge> well I was trying to avoid completely reimplementing it, it's rather a pain
<oprypin> tenebrousedge, u can return `{ tuple[0].value, tuple[1].value, ... }`
<FromGitter> <tenebrousedge> okay neat, that sounds workable
<oprypin> you're already creating the `empties` like that
<FromGitter> <tenebrousedge> works perfect
<FromGitter> <tenebrousedge> thanks oprypin
<oprypin> i think u dont need to create `type=`
<FromGitter> <tenebrousedge> correct as well
<FromGitter> <tenebrousedge> https://play.crystal-lang.org/#/r/8zmo
<FromGitter> <tenebrousedge> now I just need to decide how to handle strings, I guess
<oprypin> watzon, u just need gmp `powm` function instead of `pow`. https://github.com/crystal-lang/crystal/issues/8612#issuecomment-568737224
<FromGitter> <naqvis> i guess you will have to stick to `StaticArray` for that
<oprypin> ??
<FromGitter> <naqvis> that was for Kai
<oprypin> it's resolved
<FromGitter> <naqvis> lol
<FromGitter> <naqvis> > now I just need to decide how to handle strings, I guess
<oprypin> ah i did miss that
<oprypin> scanf is stupid, it forces you to pre-define a max size on that string
<FromGitter> <tenebrousedge> I mean, I was just going to ask if that's what it did in C 😆
<FromGitter> <tenebrousedge> I could probably do a runtime version and use `unsafe_as` to avoid a union type?
<oprypin> tenebrousedge, wait i'm not sure what you're referring to. do you still have union types in the return type? didnt my sugestion resolve that?
<FromGitter> <tenebrousedge> no but if I rewrite this as a runtime method instead of a macro then I'll have the union type problem
<oprypin> yea
<FromGitter> <tenebrousedge> but I'd have more tools to write it with, and be able to handle arbitrarily long strings
<oprypin> but you can't create an arbitrary tuple in a runtime function
<oprypin> so you'll have to return an array of union of everything
<oprypin> i think it's a no-go for this purpose
<oprypin> you can always still involve runtime components while writing the macro
<oprypin> the macro can just be a wrapper that calls whatever runtime function and then at the end return `{ result[0].value.as({{type[0]}}), result[1].value.as({{type[1]}}) }`
<FromGitter> <tenebrousedge> hmmm
<oprypin> but the parsing of the format specifier also has to be part of the macro
<FromGitter> <tenebrousedge> well that is done I guess?
<FromGitter> <tenebrousedge> it's `O(n^2)` but it works
<oprypin> compile time is constant time 😎
<FromGitter> <tenebrousedge> haha
<FromGitter> <naqvis> +1
<FromGitter> <tenebrousedge> that could be a good way to go, then
<oprypin> tenebrousedge, nice work though. it was good to see that macros can do this
<FromGitter> <naqvis> https://play.crystal-lang.org/#/r/8zmr it segfaults when asked for 3 params
<FromGitter> <naqvis> did i did sth wrong?
<oprypin> i think the parser deosnt know about %f?
<FromGitter> <tenebrousedge> either you did or I did 😆
<FromGitter> <naqvis> rofl
<oprypin> very easy to see in https://play.crystal-lang.org/#/r/8zms
<FromGitter> <tenebrousedge> it's swallowing the second `%d`
<FromGitter> <naqvis> another 👍 to oprypin
<oprypin> tenebrousedge, oh so it is
<oprypin> i added the .as() which u need https://play.crystal-lang.org/#/r/8zmt
<FromGitter> <tenebrousedge> I mean I think it worked fine without the `as`?
<oprypin> tenebrousedge, it returned a tuple of unions
<oprypin> wait maybe not, nvm
<FromGitter> <tenebrousedge> hmm, I found this before, it doesn't like when there's a token at the end of a string: ⏎ https://play.crystal-lang.org/#/r/8zmv
<oprypin> tenebrousedge, some great simplification here https://carc.in/#/r/8zn2
<oprypin> not touching first 2 lines tho :s
<oprypin> without that, also note that instead of `{LibC::Long, (flag?(:win32) || flag?(:i386) || flag?(:arm)) ? 0_i32 : 0_i64},` you could have done `LibC::Long.new(0)`
<FromGitter> <tenebrousedge> I thought that I couldn't do `new` in a macro
<oprypin> oh macro. yeah perhaps
<oprypin> then you just do `t = LibC::Long` in a macro but the rest at runtime. `{{t}}.new(0)`
<oprypin> and doesnt matter anyway because (see my code paste)
<FromGitter> <tenebrousedge> yeah, thanks
<oprypin> note about the %variables, it's important not to pollute the namespace of the caller
<oprypin> so use guaranteed unique names instead of `a1` and such which the caller could already be using for themselves
lanodan has joined #crystal-lang
<FromGitter> <tenebrousedge> but they're in a proc ?
<oprypin> oh. you're right :p
<oprypin> still doesnt hurt / best practice
sz0 has quit [Quit: Connection closed for inactivity]
<oprypin> oh wow i just noticed in the stdout - you see all that scary looking stuff at the top?
<oprypin> it inserts those expressions into the resulting code because u used `{{ r = stuff }}` instead of `{% r = stuff %}`
<FromGitter> <tenebrousedge> 😅
<FromGitter> <tenebrousedge> okay, so it's `[i..j]` instead of `[i...j]`
<oprypin> hehe
<FromGitter> <tenebrousedge> https://carc.in/#/r/8znd
<oprypin> noice
<FromGitter> <tenebrousedge> muchas gracias
<FromGitter> <Blacksmoke16> is there a way to make `ARGF` non blocking?
<FromGitter> <naqvis> 👍 I like that `uninitialized` 😆
<FromGitter> <Blacksmoke16> er `STDIN` i mean
<oprypin> @naqvis: oh no i don't like to hear that
<FromGitter> <naqvis> hahaha
<FromGitter> <naqvis> @Blacksmoke16 read `STDIN` in separate fiber?
<oprypin> asterite always says don't use uninitialized EVER, FULL STOP
<FromGitter> <naqvis> aahh
<FromGitter> <naqvis> any specific reason behind that?
<oprypin> one of the most dangerous features
<oprypin> but this particular case is the exact case that it's designed for
<FromGitter> <naqvis> ```code paste, see link``` ⏎ ⏎ straight from reference doc [https://gitter.im/crystal-lang/crystal?at=5eab225c7a24ff01b0f3abcf]
<FromGitter> <tenebrousedge> it's also necessary IIRC to create self-referencing lambdas
<FromGitter> <naqvis> doing FFI indeed is `unsafe`
<FromGitter> <naqvis> so I don't see any harm
<oprypin> first i wrote `LibC.scanf("foo", out bar)` and the compiler literally says "no, use `uninitialized` here" so it's ok
chachasmooth has quit [Quit: Quit]
chachasmooth has joined #crystal-lang
<FromGitter> <naqvis> yeah, it doesn't allow `out` there
<FromGitter> <Blacksmoke16> looks like the `learn` link on crystal site is broken
alexherbo2 has quit [Quit: Ping timeout (120 seconds)]
alexherbo2 has joined #crystal-lang
<FromGitter> <Blacksmoke16> what does the `shell` option do on `Process.run`?
<oprypin> Blacksmoke16, runs `sh -c "string you passed"`
<FromGitter> <Blacksmoke16> as opposed to what?
<FromGitter> <Blacksmoke16> directly running it?
<oprypin> Blacksmoke16, well as opposed to `"string", ["you", "passed"]`
<FromGitter> <Blacksmoke16> 👍
<oprypin> and yea, then directly running the equivalent of "string you passed"
<oprypin> Blacksmoke16, pls dont use it if at all possible :>
<FromGitter> <Blacksmoke16> dont really have a choice, unless i want to rewrite `jq` or write bindings to it?
<oprypin> Blacksmoke16, hm i don't understand why that would be necessary
<oprypin> use process.run but not shell:true
<FromGitter> <Blacksmoke16> ohh right
<FromGitter> <Blacksmoke16> thought you meant avoid `Process.run`
<FromGitter> <Blacksmoke16> i havent been, just was curious, docs on `Process` are quire sparse...
<oprypin> :|
raz has quit [*.net *.split]
Mikaela has quit [*.net *.split]
dannyAAM has quit [*.net *.split]
olbat has quit [*.net *.split]
dom96 has quit [*.net *.split]
raz has joined #crystal-lang
Mikaela has joined #crystal-lang
_ht has quit [Quit: _ht]
dom96 has joined #crystal-lang
dannyAAM has joined #crystal-lang
zorp_ has joined #crystal-lang
alexherbo22 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo22 is now known as alexherbo2
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
lanodan has quit [Quit: WeeChat 2.7.1]
lanodan has joined #crystal-lang
<FromGitter> <tenebrousedge> can I get an example of using `case` in a macro?
<FromGitter> <Blacksmoke16> idt you can
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8zpn
<FromGitter> <watzon> I've never attempted it, but I feel like a macro is one time when `case` would be messy even if you could do it.
<FromGitter> <watzon> Better to just use `if/else`
<FromGitter> <tenebrousedge> k