<FromGitter>
<straight-shoota> @watzon You can surely expose a C interface. That's essentially what the compiler (or rather LLVM) does to build any Crystal binary.
<FromGitter>
<watzon> Is there documentation on doing that anywhere? All I managed to find was @ysbaddaden's project from a couple years ago.
<FromGitter>
<straight-shoota> ```crystal build test.cr --single-module --link-flags="-shared" -o libtest.so --prelude=empty``` β β I'm skipping the prelude for a minimal demonstration, but it should also work with default runtime. [https://gitter.im/crystal-lang/crystal?at=5e4f200d8e726c7dc5b959e0]
<FromGitter>
<watzon> Oh awesome
<FromGitter>
<straight-shoota> There's no documentation I'm aware of but it's also not an officially supported feature.
<FromGitter>
<watzon> That makes sense. I've seen issues in Github for it, but could never find anything concrete.
<FromGitter>
<straight-shoota> It's really very basic stuff, actually. Even I can understand it and my C foo is really low.
<FromGitter>
<straight-shoota> You might want to look at `src/crystal/main.cr` how the default runtime is set up.
<FromGitter>
<watzon> Thanks for the help
<FromGitter>
<straight-shoota> I'm glad to share some Crystal knowledge
<FromGitter>
<watzon> Awesome. That should be a lot of help
<FromGitter>
<watzon> Damn, are there no ORMs that have a `::Serializable` module? The Crystal DB shard does, but I was hoping for an ORM.
<FromGitter>
<watzon> @Blacksmoke16 ever thought of doing this in granite?
<FromGitter>
<Blacksmoke16> what to handle to/from db?
<FromGitter>
<Blacksmoke16> whats the point of that if you're using an orm?
<FromGitter>
<watzon> Exactly. More `from` than anything.
<FromGitter>
<Blacksmoke16> granite already has `.from_rs` iirc
<FromGitter>
<watzon> Maybe my case is special, but I have a ton of classes that are already built and I don't want to duplicate the class' structure if I can avoid it.
<FromGitter>
<Blacksmoke16> i.e. that already have properties?
<FromGitter>
<watzon> Yeah, and already include `JSON::Serializable`
<FromGitter>
<Blacksmoke16> fwiw granite includes `JSON::Serialziable` for you, and its `column` macro essentially just defines an ivar and throws an annotation on it
<FromGitter>
<watzon> And the database connector isn't a mandatory thing, it's only going to be included if you include a `Persistence` module
<FromGitter>
<Blacksmoke16> so should just have to like replace your `property` with `column`
<FromGitter>
<Blacksmoke16> or add the annotation manually i guess would work too
<FromGitter>
<watzon> Is there a column annotation?
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<Blacksmoke16> its not in the public api tho
<FromGitter>
<Blacksmoke16> but you can prob figure it out
<FromGitter>
<watzon> That could work. I guess I just have to essentially redefine all the fields and apply the annotation to them.
<FromGitter>
<watzon> Too bad `Granite::Base` isn't a module
<FromGitter>
<Blacksmoke16> indeed
<FromGitter>
<Blacksmoke16> no reason it cant be afaik
<FromGitter>
<watzon> If it can be it would be a lot better
<FromGitter>
<Blacksmoke16> maybe make an issue for it
<FromGitter>
<watzon> Since having it as a class keeps you from extending other types
<FromGitter>
<Blacksmoke16> be pretty easy, but ofc big breaking change
<FromGitter>
<watzon> Maybe it doesn't have to be. What if everything in `Granite::Base` were moved into it's own module with a different name, like `Granite::Modelable` or something, and then that same module were included into `Granite::Base`? That should allow it to continue functioning, right?
<FromGitter>
<Blacksmoke16> `You can see that @pet is Animal+. The + means it's a virtual type, meaning "any class that inherits from Animal, including Animal".`
<FromGitter>
<ImAHopelessDev_gitlab> oh, it's showing output from `tool`
<FromGitter>
<ImAHopelessDev_gitlab> i thought new syntax got introduced for a second, i was like wtf
<FromGitter>
<Blacksmoke16> is there something similar to PHP's `continue 2`?
<FromGitter>
<watzon> This is why abstract types are a necessity in many cases
<FromGitter>
<Blacksmoke16> yea apparently so
<FromGitter>
<watzon> I still don't get why I'm having this problem though :/
<FromGitter>
<watzon> I'm sure I'm just doing something wrong
<FromGitter>
<ImAHopelessDev_gitlab> `next 2`?
<FromGitter>
<ImAHopelessDev_gitlab> it needs to be implemented?
<FromGitter>
<Blacksmoke16> no because in crystal land that would return `2` to the block
<FromGitter>
<ImAHopelessDev_gitlab> maybe a different keyword can be introduced
<FromGitter>
<watzon> For what?
<FromGitter>
<ImAHopelessDev_gitlab> PHP's `continue 2` β β > If a switch is inside a loop, continue 2 will continue with the next iteration of the outer loop.
<FromGitter>
<Blacksmoke16> i refactored to avoid needing it
<FromGitter>
<Blacksmoke16> prob why its not a thing already
<FromGitter>
<Blacksmoke16> `arr.select().map` versus `arr.map.compact!`?
<FromGitter>
<watzon> Hmm interesting
<FromGitter>
<watzon> Yeah probably best to avoid that
<FromGitter>
<Blacksmoke16> either way `arr` would have to be iterated twice
<FromGitter>
<ImAHopelessDev_gitlab> arr.select().map for me
<FromGitter>
<Blacksmoke16> oh wait
<FromGitter>
<Blacksmoke16> `.compact_map` π
<FromGitter>
<watzon> Well there you go lol
<FromGitter>
<watzon> I actually didn't know that existed
<FromGitter>
<Blacksmoke16> `loop { each { |x| yield x } }`
<FromGitter>
<Blacksmoke16> yup
<FromGitter>
<Blacksmoke16> sometimes idk how i feel about crystal efficiency, esp when you have a file with `record Athena::Routing::Parameter(T), value : T` literally just that in it
teardown has joined #crystal-lang
<FromGitter>
<ImAHopelessDev_gitlab> power of macros?
<FromGitter>
<Blacksmoke16> pretty much
<FromGitter>
<Blacksmoke16> tl;dr im refactoring how i handle controller arguments/param converters internally
<FromGitter>
<watzon> Basically this, but using a database
<FromGitter>
<watzon> I have `json_persistence`, which saves a `json_file` on exit and stores everything in memory, but obviously that isn't ideal for production use
<FromGitter>
<Blacksmoke16> why not just include `Persistence` into your granite model
<FromGitter>
<Blacksmoke16> or at the very least define a `GranitePersistence`
<FromGitter>
<Blacksmoke16> at a quick glance it essentially would be like
<FromGitter>
<watzon> Well `Persistence` get's included into a `Tourmaline::Client` instance. I was working on defining `GranitePersistence`, but I need to be able to define my models
<FromGitter>
<Blacksmoke16> tbh no, i think it would also depend on what db driver is being used
<FromGitter>
<Blacksmoke16> would deff be pretty low level...
<FromGitter>
<Blacksmoke16> if you want to keep things generic between databases
<FromGitter>
<watzon> Yeah I don't care that much right now. I just want one database layer that works. I don't particularly even care what database it is, I just need one.
<FromGitter>
<mavu> @kingsleyh are you not intentionally changing pieces within @board?
<FromGitter>
<kingsleyh> @mavu - as far as my understanding goes - the swap method should not mutate @board - and if I want to mutate @board - I should have to do `@board = swap(p1, p1, @board)`
<FromGitter>
<kingsleyh> but just calling `swap(p1, p2, @board)` should not mutate @board - should it ?
<FromGitter>
<asterite> it's mutating the data inside board, so it's mutating board. Or what do you mean by mutating?
<FromGitter>
<kingsleyh> do you expect that calling the swap method will change the contents of the @board variable?
<FromGitter>
<kingsleyh> I didn't expect it should
<FromGitter>
<asterite> yes, you are changing the pieces inside it
<FromGitter>
<asterite> if you don't want that to happen you should create a new piece inside the map. block
<FromGitter>
<asterite> but then you should assign the value of swap to a new variable, but I don't know where would that go since there's only a single board in the code
<FromGitter>
<mavu> @kingsleyh In crystal all objects (except primitive types) are passed around as references
<FromGitter>
<mavu> They are not copied on method calls.
<FromGitter>
<kingsleyh> ok thanks - I always thought that - mapping over an array of items would never change the array - unless the result of the map was assigned back to the array - but I see now that this is not the case!
<Andriamanitra>
you're not actually changing the array itself as the array is just a "list of references" - what is changing is the objects those references point to
<FromGitter>
<kingsleyh> ok great thanks - I've created new Pieces instead of mutating
darkstardevx has quit [Remote host closed the connection]
<FromGitter>
<mavu> Is there a way to use the linux inotify to react to file changes?
<FromGitter>
<msa7> It my question. What do you mean `you the one`?
gangstacat has joined #crystal-lang
alexherbo2 has joined #crystal-lang
<FromGitter>
<wout> What's the best way to get an instance variable dynamically? I've got a struct with `JSON::Serializable`, so a solution would be `JSON.parse(to_json)["dynamic_name"]`. Which works, but I am wondering now if there isn't a more elegant way.
Human_G33k has joined #crystal-lang
HumanGeek has quit [Ping timeout: 260 seconds]
<FromGitter>
<straight-shoota> Instance variables can't be dynamically defined. They are set in stone at compile time. In order to store dynamic data, you need a data structure like a `Hash` (which is what `JSON::Any` is based on).
<FromGitter>
<straight-shoota> Whether you use JSON to serialize such data is a different question, depending on your use case. But there's no "more elegant way" to store dynamic data other than a `Hash` or similar data structure.
<raz>
crystal makes programming so easy, it feels like cheating
<FromGitter>
<wout> @straight-shoota I think I wasn't clear in my question. I am looking for a way to get a value from a struct instance, similar to `.send("name")` in Ruby.
<raz>
wout: these types of questions are difficult to answer because it's very case-dependent.
<raz>
but the good news is, once you've overcome a few of them, you suddenly realize how much nicer and safer it is in Crystal (send is almost never a good idea in ruby either)
<FromGitter>
<asterite> @wout There's no way to do what you want
<FromGitter>
<wout> Ok, so here is a bit more context:
<FromGitter>
<igor-alexandrov> Mainly yes, but I believe you can use it not only in web.
<FromGitter>
<acoolstraw> yep
<FromGitter>
<acoolstraw> so is it like a replacement to regular file uploading included in Kemal or other frameworks?
<FromGitter>
<igor-alexandrov> It is a toolkit (based on Shrine.rb https://shrinerb.com/) that helps to upload, process and manage files.
<FromGitter>
<asterite> @acoolstraw shrine seems to be about uploading files to external services like S3. Maybe you are thinking about uploading files to a server. Kemal and other frameworks handle that. Shrine handles where to physically store those files
<FromGitter>
<acoolstraw> aw
<FromGitter>
<acoolstraw> S3 is real expensive
<FromGitter>
<Blacksmoke16> not really, depends how you use it
<FromGitter>
<Blacksmoke16> long term archive is stupid cheap
<FromGitter>
<acoolstraw> yeah
<FromGitter>
<acoolstraw> but for small projects I don't like the price
<FromGitter>
<acoolstraw> wait
<FromGitter>
<acoolstraw> I'm confusing it with something else, sorry
<FromGitter>
<acoolstraw> it's really cheap, wow
<FromGitter>
<Blacksmoke16> main cost comes from the requests to add/retrieve the data
<FromGitter>
<acoolstraw> surprised that storage costs less
ua has quit [Ping timeout: 240 seconds]
<FromGitter>
<Blacksmoke16> storage is cheap these days
<FromGitter>
<Blacksmoke16> terabyte SSDs are under $100
<FromGitter>
<636f7374> I like M.2.
<FromGitter>
<636f7374> Samsung 9x0 EVO / Pro
<FromGitter>
<acoolstraw> terabyte
<FromGitter>
<acoolstraw> they're charging practically nothing for hundreds of terabytes
<FromGitter>
<acoolstraw> also, are they?
<FromGitter>
<acoolstraw> the ones I've looked for are a bit over that
<FromGitter>
<Blacksmoke16> you can find them, idk how *good* they are tho
<FromGitter>
<acoolstraw> they've been gradually decreasing in prices though
<FromGitter>
<acoolstraw> good ones have been $200 last year and now they're 130-150$
<FromGitter>
<acoolstraw> double the HDD cost, much more the speed
<FromGitter>
<christopherzimmerman> I picked up ~5 1TB SSDs a few months ago for like 80 each and Iβve been really happy with them. Havenβt noticed any real differences from my $150 one.
<FromGitter>
<Blacksmoke16> Probably will in life span