<FromGitter>
<Blacksmoke16> still working on the serializer, then need to rework validation component, prob going to skip porting crylog if that sweet new stdlib `Log` module is in the works
<FromGitter>
<christopherzimmerman> Anyone know how to turn a string into `Char**` to pass to a c lib? I've tried `[s.chars.to_unsafe]` and it takes it, but I feel like there's a better way.
<FromGitter>
<Blacksmoke16> `**`? what's next `Char***`? :P
postmodern has joined #crystal-lang
<FromGitter>
<Blacksmoke16> does `s.to_slice` not work?
<FromGitter>
<Blacksmoke16> er sorry, this is the default `crystal spec -v` idk about that shard
<postmodern>
Blacksmoke16, i tried setting formatter = Spectator::Formatting::DocumentFormatter, but the compiler didn't like that for some reason (it does inherit from the Formatter base class)
<FromGitter>
<Blacksmoke16> what was the error?
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
<postmodern>
Blacksmoke16, ah nevermind. Required an instance of it. Works now.
<FromGitter>
<christopherzimmerman> @watzon I ended up creating a separate library (https://github.com/crystal-data/clcr) for opencl so its reusable
<FromGitter>
<Blacksmoke16> er not exactly what you're looking for
<FromGitter>
<watzon> That is something I didn't know existed. Interesting.
<FromGitter>
<watzon> postmodern: could you share a code snippet so I can get a better idea of what we're dealing with? I'm having a hard time wrapping my head around the problem for some reason.
<FromGitter>
<watzon> Very visual person here haha
<postmodern>
Blacksmoke16, not exactly. Instead of leaving the data uninitialized, i call an C function that zeroes/resets all of the fields.
<postmodern>
essentially i want to prevent against UD#syntax from being called when @ud has just been init'd by ud_init, which sets all pointers to NULL.
<FromGitter>
<watzon> Ok, so the `if @ud.translator` guard clause isn't working?
<postmodern>
watzon, correct, it's coming back as #<Proc(Pointer(LibUDis86::UD), Nil):0x0>
<postmodern>
watzon, ah didn't know you could go down that far into the Proc.
<FromGitter>
<watzon> Yeah, let me know if that works
<FromGitter>
<watzon> Fingers crossed
<postmodern>
watzon, is there a cleaner way of detecting null C function pointers, and map them to a Nil?
<postmodern>
seems to work!
<FromGitter>
<watzon> Not that I know of unfortunately. Might be something to make an issue about and see what the maintainers think.
<FromGitter>
<watzon> Because it would be nice to just have it be null instead of what basically amounts to a null proc, which I'm sure most people don't know exist
ur5us has quit [Ping timeout: 240 seconds]
<postmodern>
what's the preferred way to link against a local libfoo.so? working on writing up an example for the null proc issue
sagax has joined #crystal-lang
<FromGitter>
<watzon> That's a good question. Maybe using the `-L` flag in your linker options?
<FromGitter>
<watzon> So `-L../vendor/libfoo/libfoo.so` or something. I haven't actually done it so I'm not sure.
alexcouch has joined #crystal-lang
<alexcouch>
So I'm trying to use the socket api, and it's not entirely clear to me on the best approach to sending/receiving raw ICMP echo packets. I'm trying to construct the raw byte packets but the send method doesn't really like that. I've tried sending it as a Bytes object, but that yielded a hang on the receive method call. And I'm sending to
<alexcouch>
destinations I have already confirmed are on my network. I''m struggling to understand what conventions to use for this kind of stuff. I get the conventions for sending packets in general for tcp, udp, etc are already built in but that's not gonna satisfy my case. I'm really just trying to rewrite a python module my team and I made in the company I
<alexcouch>
work for, as a personal experiment. Could anyone point me in the right direction?
<postmodern>
hmm -L./libfoo.so is finding the lib, but getting undefined references, even though i've extern'd the functions and can see them listed by nm -D
ur5us has joined #crystal-lang
<FromGitter>
<watzon> You'd also have to do `-lfoo` to link the library
<FromGitter>
<watzon> Where foo is the library name of course
_ht has joined #crystal-lang
_ht has quit [Remote host closed the connection]
ur5us has quit [Ping timeout: 240 seconds]
alexcouch has quit [Remote host closed the connection]
<postmodern>
hmm it's not liking "-L./libfoo.so -lfoo"
<postmodern>
xyxhuvud, ah ha, #{__DIR__}/foo.o and #{__DIR__}/libfoo.so both work. Also looks like -L has to be given an absolute path, not a relative one.
Nicolab has joined #crystal-lang
Nicolab has quit [Quit: Leaving.]
ur5us has joined #crystal-lang
Nicolab has joined #crystal-lang
<FromGitter>
<mavu> Is there a way for a method (class initializer in this case) to accept any argument that has a .to_json method?
Human_G33k has quit [Ping timeout: 260 seconds]
<FromGitter>
<watzon> Glad you got it working postmodern π
<FromGitter>
<watzon> @mavu not that I know of. This is why interfaces would be nice. Modules cover some use cases, but not this one.
<FromGitter>
<mavu> @watzon thanks, that saved me from pointless searching :)
HumanG33k has quit [Read error: Connection reset by peer]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Read error: Connection reset by peer]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Read error: Connection reset by peer]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Read error: Connection reset by peer]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Read error: Connection reset by peer]
alexherbo2 has joined #crystal-lang
HumanG33k has joined #crystal-lang
HumanG33k has quit [Read error: Connection reset by peer]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Read error: Connection reset by peer]
HumanG33k has joined #crystal-lang
Nicolab has quit [Ping timeout: 260 seconds]
gangstacat has quit [Quit: Δis!]
alexherbo2 has quit [Ping timeout: 268 seconds]
gangstacat has joined #crystal-lang
<FromGitter>
<Blacksmoke16> @mavu couldnt you just not add a type restriction? It would obs fail if the type doesnt support `.to_json`
<FromGitter>
<Blacksmoke16> which would be similar to `method .to_json does not exist on SerializableInterface`
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #crystal-lang
postmodern has quit [Quit: Leaving]
<FromGitter>
<smw> hi crystal people! I'm really enjoying the language, but I ran into a stumbling block:
<FromGitter>
<smw> if I have an array of (Type | Nil), and I want to remove the Nils and turn it into an array of Type, how do I get the compiler to accept that?
<FromGitter>
<tenebrousedge> `try`, `not_nil!` or `as`
<FromGitter>
<tenebrousedge> and probably you should consider them in that order
<FromGitter>
<tenebrousedge> you may also be able to use `compact` with an array, if the position doesn't matter
<FromGitter>
<smw> Ok, I'm not quite following...
<FromGitter>
<smw> if I have an array with some elements as Nil, and I call compact on it, will the compiler now understand the new type of the array?
<FromGitter>
<Blacksmoke16> pretty sure you would have to go with `#compact` to create a new array without `Nil`
<FromGitter>
<Blacksmoke16> otherwise the type of the original array will still be `Type?` even if it doesnt have `nil` values
<FromGitter>
<smw> That seems to do it, thank you!
<FromGitter>
<Blacksmoke16> `#compact!` cant be used either, even tho it removes `nil`, it still retains the type since its the same array https://play.crystal-lang.org/#/r/8kyp
<FromGitter>
<smw> but you can do array = array.compact and it changes type
<FromGitter>
<Blacksmoke16> to be clear it doesnt *change* the type of the array
<FromGitter>
<Blacksmoke16> it creates a *new* array
<FromGitter>
<Blacksmoke16> with a different type
<FromGitter>
<smw> right, fair enough. the type associated with the variable binding changes?
<FromGitter>
<smw> not sure the correct terminology in crystal
<FromGitter>
<Blacksmoke16> > the type associated with the variable binding changes? β β hm?
<FromGitter>
<Blacksmoke16> its more so you're just overriding the value of `arr`
<FromGitter>
<Blacksmoke16> with a new array so its type changes
<FromGitter>
<smw> I'm following you. Having trouble thinking of other statically typed languages where the *name* `arr` would have a type associated with it?
<FromGitter>
<smw> Is there a difference between using the arr = [] of x syntax in the arr: Array(x) syntax?
<FromGitter>
<tenebrousedge> there used to be some edge cases where the compiler didn't like the first syntax, I think. Not sure if those were fixed
<FromGitter>
<Blacksmoke16> there is a diff
<FromGitter>
<smw> but is one talking about the variable name and the other what it's pointing to?
<FromGitter>
<Blacksmoke16> the first is setting the value of `arr` to be an empty array of `X`, where the type is inferred to be `Array(X)`
<FromGitter>
<j8r> I prefer using the generic one, always
<FromGitter>
<Blacksmoke16> the latter one is declaring `arr`'s type, but not setting its value
<FromGitter>
<Blacksmoke16> i.e. with the first you could do `arr = "foo"`, the second you couldn't
<FromGitter>
<smw> and in the later one, the type of arr is set permanently?
<FromGitter>
<j8r> It is more natutal `@ary : Array(String) = Array(String).new` than `@ary : Array(String) = [] of String`
<FromGitter>
<j8r> the only main use case is `["a", "b", "c"] of String | Int32`
<FromGitter>
<smw> does `@ary : Array(String) = []` not do the same thing by type inference?
<FromGitter>
<smw> reverse type inference?
<FromGitter>
<j8r> it does not work yes
<FromGitter>
<Blacksmoke16> you would still have to do `[] of String` to tell it what the empty array should be
<FromGitter>
<Blacksmoke16> as without it, it's untyped
<FromGitter>
<j8r> because a `[]` value is not a thing
<FromGitter>
<smw> Ok. I think I'm catching on. Thank you again!
<FromGitter>
<j8r> I have propose to remove this syntax in the past, to have less ways and confusions
<FromGitter>
<Blacksmoke16> what `[] of Type`?
<FromGitter>
<j8r> this
<FromGitter>
<Blacksmoke16> why?
<FromGitter>
<Blacksmoke16> it has its uses, esp when working with macros
<FromGitter>
<j8r> I didn't say in macro, only in the language
<FromGitter>
<Blacksmoke16> sorry i mean if you use a macro to build out an array
<FromGitter>
<Blacksmoke16> ```{{values}} of Type```
<FromGitter>
<j8r> `[]` will work too?
<FromGitter>
<Blacksmoke16> not when values is a child type and you want it to use the parent type's type
<FromGitter>
<j8r> Quite sure there are work arounds
<FromGitter>
<j8r> Sure there are pros
<FromGitter>
<j8r> But at the same time there are cons
<FromGitter>
<j8r> like this syntax doesn't work in some places, and one more thing to learn
<FromGitter>
<Blacksmoke16> both have their uses
<FromGitter>
<yxhuvud> `Array(Supertype){values}`
<FromGitter>
<yxhuvud> (perhaps you need some more {{}}s.
<FromGitter>
<j8r> @yxhuvud π , the only sing is one says it was less efficient than the `of` syntax
ancorgs has left #crystal-lang ["Konversation terminated!"]
<FromGitter>
<bararchy> @watzon @christopherzimmerman if you get GPU working let me know XD
<FromGitter>
<bararchy> Anything like `includes?` but for enumerable? like, can I see if this array holds anything for other array?
<FromGitter>
<christopherzimmerman> I am working on generalizing it a bit, but within the next few days I'm going to be adding `ClTensors` to my library :). Once I got the OpenCL bindings working, adding in all of the elementwise kernels/linear algebra libraries was pretty trivial. If you want I can submit a PR at some point to back SHAINet with tensors (CPU and GPU).
<FromGitter>
<bararchy> Oh wow that would be amazing!
<FromGitter>
<bararchy> @ArtLinkov ^ you'll love this
<FromGitter>
<christopherzimmerman> I posted this example (https://gist.github.com/christopherzimmerman/c35f5f38f3de1ce51e324967f99a8f24) yesterday using the wrapper I'm working on. Kernels do have to be JIT compiled unfortunately, which adds a bit of overhead. If you don't want to add num.cr to the library directly, you could always just use the OpenCL wrappers. I'm planning on adding a similar one for CUDA once I have a
<FromGitter>
... compatible card.
<FromGitter>
<bararchy> oh...CUDA, my beloved and most hated lib in the world
<FromGitter>
<christopherzimmerman> CUDA is going to be a *lot* easier than OpenCL, don't worry :). I am really motivated to get better deep learning tools into Crystal, especially since I'm changing jobs and won't be doing any ML at work anymore. Gotta get my fix somewhere else.
<FromGitter>
<ArtLinkov> @christopherzimmerman this sounds awesome :)
<FromGitter>
<christopherzimmerman> I'm very excited. By far the biggest thing my numerical library was GPU support. Hopefully it starts bringing more people to Crystal
<FromGitter>
<ArtLinkov> Looking forward to it! Ping me when it's ready, I'll love to take a look
<FromGitter>
<PlayLights_twitter> Hello There, I have a simple question, I haven't looked at the base Dockerfile but why the crystal image is so heavy? like 550mb
<FromGitter>
<PlayLights_twitter> yeah I know like 280MB, which is a lot more than a node/ruby alpine
<FromGitter>
<Daniel-Worrall> I keep seeing alpine and musl being the only way to statically compile, but what I really want to know is *why*
<FromGitter>
<PlayLights_twitter> that was I think its weird
<FromGitter>
<tenebrousedge> the size could probably be reduced by making it a multistage build
<FromGitter>
<tenebrousedge> ah, no, it is
<FromGitter>
<tenebrousedge> I got nothing
<FromGitter>
<tenebrousedge> maybe it's just an interpreter-vs-compiler thing
<FromGitter>
<Blacksmoke16> @Daniel-Worrall because alpine uses a diff `musl libc`
<FromGitter>
<Blacksmoke16> which i guess is easier/only one that supports static linking versus the normal `libc`
_ht has joined #crystal-lang
<FromGitter>
<straight-shoota> Gnu libc can't be statically linked.
<FromGitter>
<straight-shoota> Or technically, it can but it doesn't properly work
<FromGitter>
<straight-shoota> musl instead is designed for statically linking
<FromGitter>
<Daniel-Worrall> so it's a design feature that we can integrate with
<FromGitter>
<Blacksmoke16> does that mean like Go also only supports static linking on alpine?
<FromGitter>
<straight-shoota> Go doesn't link against libc at all.
<FromGitter>
<straight-shoota> If you need C interop, you can use cgo but that doesn't link statically against glibc as all.
<FromGitter>
<Blacksmoke16> and i imagine we need libc for c bindings and some system level stuff?
<FromGitter>
<straight-shoota> yes
<FromGitter>
<Blacksmoke16> how does Go handle their system level stuff in that case? Just don't offer anything similar to what we have or?
<FromGitter>
<straight-shoota> They just implement everything themselves and call system calls directly.
<FromGitter>
<Blacksmoke16> gotcha
<FromGitter>
<straight-shoota> That actually doesn't seem too much of an effort. We should be able to do the same thing without too much hassle, I suppose. But then you can't use other c libraries as well because they all depend on libc.
<FromGitter>
<kinxer> Why can't we re-open an enum to add more constants?
<FromGitter>
<Blacksmoke16> id imagine it could be ok if you add them to the end, otherwise things would break
<FromGitter>
<tenebrousedge> I think enums are pretty "magical"
<FromGitter>
<Blacksmoke16> but gets tricky when you try to open it multiple times, what would the order be, maybe not an issue if every member has a value explicitly defined?
<FromGitter>
<straight-shoota> @Daniel-Worrall There's no difference between nightly and latest, except for different crystal build and source
<FromGitter>
<Daniel-Worrall> yeah, I know
<FromGitter>
<kinxer> Hm... I'm trying to figure out if there's a good way to build an enum as part of multiple invocations of different macros (which already do other things).
<FromGitter>
<Daniel-Worrall> Just don't want to point someone in the direction of a nightly without them knowing it is such
<FromGitter>
<straight-shoota> @Daniel-Worrall I don't think the docker layers don't provide any meaningful insights.
<jhass>
kinxer: I guess you could always collect and generate in a finished hook
<FromGitter>
<straight-shoota> It's much better to look at what's inside the final image: The crystal compiler (66 MB), shards (8 MB), git (12MB), default libraries (40MB total), gcc (80MB) and alpine base image (3MB).
<FromGitter>
<straight-shoota> @kinxer Would help if you could elaborate more on the use case
<jhass>
I would prefer designs that can avoid this but yeah
<FromGitter>
<tenebrousedge> neat
<jhass>
neat until you have a dozen things doing something on finished and depending on each other you don't understand anything anymore :P
<FromGitter>
<tenebrousedge> I save time by not understanding anything after I finish writing it :D
<FromGitter>
<Daniel-Worrall> why do those 2 macros do the same thing tho
<jhass>
just an example
<jhass>
they can do different things additionally
<jhass>
as that was kinxer's question, to build a single enum for calls to two different macros
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter>
<mavu> @Blacksmoke16 (late reply, everyone else, best ignore :) ) Current plan : use Union type of AppConfig | Array. both Types I know support .to_json. And I don't have to use the appconfig class when testing in isolation. not tested yet, something came up, but should work i think.
<FromGitter>
<Blacksmoke16> okey dokey
<livcd>
are there any gtk apps in Crystal?
ur5us has joined #crystal-lang
<FromGitter>
<kinxer> @jhass Thanks for the prototype. Unfortunately, this idea was intended to help avoid the use of `Symbol`. I'll try to figure out a good analogous use-case.
<jhass>
just gotta be able to store it to an array in some form and convert it to an identifier after
<FromGitter>
<jwoertink> Has anyone here booted a crystal app on ClearLinux docker?
sorcus has joined #crystal-lang
darkstardevx has quit [Remote host closed the connection]
darkstardevx has joined #crystal-lang
<FromGitter>
<kingsleyh> after upgrading to 0.33.0 - my specs are failing with this error: `Can't read UInt64 at 1:20` - were there any changes that could have caused this?
_ht has quit [Remote host closed the connection]
<FromGitter>
<kingsleyh> It seems like it's something to do with Json parsing
alexherbo23 has joined #crystal-lang
alexherbo23 has quit [Client Quit]
alexherbo28 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 265 seconds]
alexherbo28 is now known as alexherbo2
<FromGitter>
<kingsleyh> In Crystal 0.32.1 - although the JSON.parse prints out an incorrect negative number - the Item.from_json works correctly: https://carc.in/#/r/8l16 but the same code in crystal 0.33.0 - returns the negative number then blows up on the Item.from_json: https://carc.in/#/r/8l17
<FromGitter>
<kingsleyh> any idea what the correct way to fix this is?
sagax has quit [Remote host closed the connection]