<FromGitter>
<Blacksmoke16> so im thinking i can have a parent object that implements the `serialize` method
<FromGitter>
<dscottboggs_gitlab> so you have to inherit from rather than `include`ing?
<FromGitter>
<dscottboggs_gitlab> (not that I'm partial to either way)
<FromGitter>
<Blacksmoke16> let me finish :p sec
<FromGitter>
<dscottboggs_gitlab> haha ok
<FromGitter>
<Blacksmoke16> it'll return an array of `SerializeableObject` or something that contains key/value properties
<FromGitter>
<Blacksmoke16> then each sub module will implement a method that will be responsible for converting that array of objs into whatever type you want
<FromGitter>
<dscottboggs_gitlab> ohhh no I see
Renich has quit [Quit: Renich]
<FromGitter>
<dscottboggs_gitlab> that's acutally great
<FromGitter>
<Blacksmoke16> so like if you want `serialize` to do `JSON` you `include CrSerializer::JSON`
Renich has joined #crystal-lang
<FromGitter>
<Blacksmoke16> yaml would be like `::YAML`
<FromGitter>
<Blacksmoke16> etc
<FromGitter>
<dscottboggs_gitlab> yes that's great
<FromGitter>
<dscottboggs_gitlab> having a standard interface to build serializers off of makes a lot of sense
Renich has quit [Client Quit]
<FromGitter>
<Blacksmoke16> if you want your own thing should just be able to override the `SerializableObject` to include your `Serializeable` module if you have one
Renich has joined #crystal-lang
<FromGitter>
<Blacksmoke16> and/or implement your sub module you can include
<FromGitter>
<Blacksmoke16> deserialization would work in a similar way i think
<FromGitter>
<dscottboggs_gitlab> yeah you just use PullParser for one and Builder for the other to make your Serializeable module
<FromGitter>
<Blacksmoke16> and should be generic enough where other style wouldnt have to implement my custom logic for my annotations, as the `serialize` method would return an array or single obj of `SerializeableObject`
<FromGitter>
<Blacksmoke16> then its the submodule's job to turn that into X
<FromGitter>
<Blacksmoke16> 💯
<FromGitter>
<Blacksmoke16> wish you could declare abstract defs on module :p
<FromGitter>
<Blacksmoke16> but i guess it doesnt really make sense
<FromGitter>
<dscottboggs_gitlab> why not?
<FromGitter>
<Blacksmoke16> because there isnt really a concept on inheritance with a module
<FromGitter>
<Blacksmoke16> it could be included in a class, another module, extended etc
<FromGitter>
<dscottboggs_gitlab> oh,yeah
<FromGitter>
<dscottboggs_gitlab> also if `include` two modules that define the same function overload it works like ruby functions
<FromGitter>
<dscottboggs_gitlab> :/
<FromGitter>
<Blacksmoke16> thats the one downside of this, if you want to support say both YAML *AND* JSON you wouldnt be able to do that...but i dont think that is a common need?
<FromGitter>
<Blacksmoke16> since one include would override the other
<FromGitter>
<Blacksmoke16> since method names are the same
<FromGitter>
<dscottboggs_gitlab> wouldn't they be different overloads since they'd each have their type ::Serializable as the argument?
<FromGitter>
<dscottboggs_gitlab> oh, not the actual conversion method, I see. :/
<FromGitter>
<Blacksmoke16> unless i renamed the methods to like `serialize_x`
<FromGitter>
<Blacksmoke16> ?
<FromGitter>
<Blacksmoke16> but is it really that common to want to output json in one context and yaml in another, or con or xml for example?
<FromGitter>
<dscottboggs_gitlab> well
<FromGitter>
<dscottboggs_gitlab> in the stdlib it's `to_json`and `from_yaml`
<FromGitter>
<dscottboggs_gitlab> so why not?
<FromGitter>
<Blacksmoke16> or could just take over those names...
<FromGitter>
<Blacksmoke16> nvm no i cant
<FromGitter>
<Blacksmoke16> yea i cant do that
<FromGitter>
<dscottboggs_gitlab> I wouldn't say it's common but I think it should be easy to do. What if you want to store a class in YAML or CON and send it through an IPC in a gob or JSON encoding
<FromGitter>
<Blacksmoke16> even renaming them, as it would break the generic parent method
<FromGitter>
<dscottboggs_gitlab> what if the generic parent method iterates over the values in @type in a macro like JSON::Serializable does?
<FromGitter>
<Blacksmoke16> but i guess i could just have a macro plop down the code so i dont have to duplicate it
<FromGitter>
<Blacksmoke16> it does
<FromGitter>
<dscottboggs_gitlab> ah shit I tried to figure out how to make that work with methods and I could only get it for instance vars. I don't think that feature exists yet?
<FromGitter>
<Blacksmoke16> it would do that to build out an array of the `SerialzableObject` then its the submodule's job to turn that into X type
<FromGitter>
<Blacksmoke16> it does but only in context of a method atm
<FromGitter>
<ilanusse> Which basically looks for a class's policy
<FromGitter>
<ilanusse> A class can either have a method called `policy_class` which states this explicitly
<FromGitter>
<ilanusse> Or what I had in mind was to use an implict `#{class_name}Policy`
<FromGitter>
<ilanusse> Say if my class is Post
<FromGitter>
<dscottboggs_gitlab> does it matter what a policy is in this context?
<FromGitter>
<ilanusse> No
<FromGitter>
<dscottboggs_gitlab> ok
<FromGitter>
<ilanusse> Call it foo or bar or whatevs
<FromGitter>
<ilanusse> So I just wanted to get something dynamically but obviously this is a compiled language
<FromGitter>
<ilanusse> I don't really have much experience with macros and I'm guessing I want something like that?
<FromGitter>
<Blacksmoke16> prob
<FromGitter>
<ilanusse> Basically, I want a way that given a constant Foo
<FromGitter>
<ilanusse> My function should return the constant FooPolicy
<FromGitter>
<dscottboggs_gitlab> yeah but this just doesn't make sense in the context of a strictly typed language.
<FromGitter>
<ilanusse> Figured as much
<FromGitter>
<dscottboggs_gitlab> why not have it be a generic like `PolicyFinder(PolicyType)`?
<FromGitter>
<ilanusse> I'm still thinking this way too Rubyish
<FromGitter>
<dscottboggs_gitlab> I mean, you can usually shoehorn dynamic types into crystal but there's usually a better way to implement it, you know?
<FromGitter>
<ilanusse> Yeah
<FromGitter>
<dscottboggs_gitlab> idk maybe the wizard has an idea 😉
<FromGitter>
<dscottboggs_gitlab> also, object.class is a constant that you could then modify in a macro
<FromGitter>
<Blacksmoke16> when you have an `@[Assert::Email]` annotation, for example, on a property that will pick it up and at compile time will look like `assertions << EmailAssertion(String).new("name",nil,name)`
<FromGitter>
<Blacksmoke16> where the property name is name of type `String`
<FromGitter>
<dscottboggs_gitlab> but then how does EmailAssertion get defined?
<FromGitter>
<Blacksmoke16> ^^
<FromGitter>
<dscottboggs_gitlab> oh you have to define it manually?
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<dscottboggs_gitlab> ok
<FromGitter>
<Blacksmoke16> but can define your own
<FromGitter>
<dscottboggs_gitlab> yes that's very nice.
<FromGitter>
<Blacksmoke16> i.e. `@[Assert:Custom]`
<FromGitter>
<Blacksmoke16> Think I'll go with only one include possible, let it become an issue, I don't think multiple serialization would be real common ..
<FromGitter>
<Blacksmoke16> Less complex code on my end
<FromGitter>
<girng> need to do server-side skill tree web
<FromGitter>
<girng> i don't know how to tackle this issue programatically
<FromGitter>
<anamba> trying to use the new language-agnostic Passenger 6 with the hello world example in HTTP::Server but both the passenger agent process and the crystal process just go to max cpu until i kill them. it feels like both sides are silently erroring on something and immediately retrying. any ideas on how to troubleshoot?
<FromGitter>
<girng> create a array of classes with a `property required_ids`, and then when user tries to activate a new skill, loop through the player's current skills to make sure they have the required skill_ids? If so, then append that new skill id to their `skills` array? i'm not sure but that's what i'm thinking
<FromGitter>
<Blacksmoke16> could prob use `Enumerable#all?`
<FromGitter>
<girng> oh that' snice, yeah
<FromGitter>
<Blacksmoke16> not sure @anamba
<FromGitter>
<Blacksmoke16> anyone know how to declare any empty array of a struct that has a generic
<FromGitter>
<dscottboggs_gitlab> @ezrast what in the hell
<FromGitter>
<ezrast> ?
<FromGitter>
<dscottboggs_gitlab> that just... it's not very obvious how that all works
<FromGitter>
<dscottboggs_gitlab> I guess it makes sense if you can have arrays of Modules but that doesn't really make a ton of sense to think about, having an array of a Module type.
<FromGitter>
<ezrast> Including a module is in practice almost the same as inheriting from a class
<FromGitter>
<dscottboggs_gitlab> that makes a lot more sense IMO but I guess the other one is useful too.
Renich has quit [Quit: Renich]
<FromGitter>
<dscottboggs_gitlab> oh actually I totally get it now
Renich has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> because types are verified on the basis of the presense or lack of a given method, and including a module adds its methods to your class
Renich has quit [Client Quit]
Renich has joined #crystal-lang
<FromGitter>
<ezrast> Not quite; simply defining a type's methods isn't enough to make an object be of that type in Crystal (you may be thinking of Go)
<FromGitter>
<dscottboggs_gitlab> oh I see, I must be
<FromGitter>
<ezrast> It's just that including a module adds that module to your type's list of ancestors, just like inheriting from a class does
<FromGitter>
<dscottboggs_gitlab> yes I'm thinking of go interfaces, you're right
<FromGitter>
<dscottboggs_gitlab> interesting
<FromGitter>
<dscottboggs_gitlab> well it sort of works that way in crystal too if you don't specify a type but I see what you mean about this not being an example of that
<FromGitter>
<ezrast> yeah
Renich has quit [Quit: Renich]
Renich has joined #crystal-lang
Renich has quit [Client Quit]
Renich has joined #crystal-lang
Renich has quit [Quit: Renich]
Renich has joined #crystal-lang
Renich has quit [Quit: Renich]
Renich has joined #crystal-lang
Vexatos has joined #crystal-lang
Vexatos has quit [Quit: ZNC Quit]
Vexatos has joined #crystal-lang
return0e_ has quit []
DTZUZO has quit [Ping timeout: 272 seconds]
Renich has quit [Quit: Renich]
Renich has joined #crystal-lang
ashirase has quit [Ping timeout: 250 seconds]
<oprypin>
i really enjoyed reading this last conversation. you figured it out completely :)
<FromGitter>
<KevinSjoberg> Does Crystal have the `DATA` and `__END__` capabilities from Ruby?
<FromGitter>
<KevinSjoberg> At first try, it doesn't seem like it.
ua_ has joined #crystal-lang
<FromGitter>
<j8r> @jamesfuture really nice! This could be considered if it has pros vs Gitter. https://github.com/withspectrum/spectrum/issues/2621 remains to do :/. This is a blocking point because it prevent ot have an IRC bridge like here
ua has quit [Ping timeout: 246 seconds]
Raimondi has quit [Ping timeout: 240 seconds]
Raimondi has joined #crystal-lang
Raimondi has quit [Ping timeout: 245 seconds]
<FromGitter>
<jamesfuture> Yeah, it could take a while to get there
<FromGitter>
<ilanusse> I'm trying to make a shard recreating Pundit
<FromGitter>
<Blacksmoke16> you could do it with a macro, but it wouldnt be real clean as it would have to be a case statement mapping symbol to method name
<FromGitter>
<Blacksmoke16> is the symbol going to be the same as the method name?
<FromGitter>
<ilanusse> Yep
<FromGitter>
<ilanusse> I guess I could just go for the case statement
<FromGitter>
<ilanusse> I was wondering if there was any way it could be extensible
<FromGitter>
<ilanusse> But this'll do for now
<FromGitter>
<ilanusse> Thanks!
Renich has quit [Quit: Renich]
Renich has joined #crystal-lang
Renich has quit [Client Quit]
Renich has joined #crystal-lang
<FromGitter>
<Blacksmoke16> those methods are not global, would be specific to something?
<FromGitter>
<Blacksmoke16> @ilanusse
<oprypin>
ilanusse: definitely do the case statement, but you can generate it using macros, which can list all methods in the current object. or it may be wise to maintain the list manually but at least you don't write out the actual cases
jtianling has quit []
Renich has quit [Quit: Renich]
Renich has joined #crystal-lang
Renich has quit [Client Quit]
Renich has joined #crystal-lang
<FromGitter>
<Blacksmoke16> @ezrast 💯 perfect!
<FromGitter>
<ilanusse> Sorry, was coding!
<FromGitter>
<ilanusse> So the whole idea is
<FromGitter>
<ilanusse> You have Policies for your different model objects
<FromGitter>
<ilanusse> Here's the source I just pushed, feel free to snoop around
<FromGitter>
<ilanusse> I'm writing a README rn
<FromGitter>
<noahlh> hey everyone - quick question about some code that’s working, but I don't understand why (which scares me ;)
<FromGitter>
<drum445> @j8r don't think that would work exactly how the guy changed it, commented lines wouldn't be taken into account
<FromGitter>
<drum445> see his spec
<FromGitter>
<noahlh> If I launch a node server and pipe the output to a logger: ⏎ ⏎ ‘’’’ ⏎ node_process = Process.new("node server.js", shell: true, output: Process::Redirect::Pipe) ⏎ node_process.output.each_line do |line| ... [https://gitter.im/crystal-lang/crystal?at=5c02b692500e8e372843b789]
<FromGitter>
<noahlh> (oops sorry for bad formatting - on mobile)
<FromGitter>
<noahlh> My Crystal prog stays alive and patiently pipes the output until I Ctl-C, at which point the program (and the external process) both exit. ⏎ ⏎ If I simply create the Process without the pipe or logger, the node server launches, my Crystal program immediately exits, and I have an orphan process. ⏎ ⏎ What’s going on here? I assume ‘IO.each_line’ is spawning Fibers behind the scene? Why and how
<FromGitter>
<drum445> @j8r "Dotenv values containing spaces must be surrounded by quotes."
<FromGitter>
<Blacksmoke16> ahh i dont have a good way to handle array of objects...
<FromGitter>
<Blacksmoke16> hmm
<FromGitter>
<Blacksmoke16> `["{\"name\":\"Bob\",\"age\":234}", "{\"name\":\"Bob\",\"age\":234}"]` i get that since its just making an array of each obj as a string...
<FromGitter>
<Blacksmoke16> i cant just do `.to_json` on the array since i need to preprocess that data, for custom keys for example
<FromGitter>
<drum445> ah right, so you've got the serializing in the array handler
<FromGitter>
<drum445> Guess there's no way it could be in the class themselves
<FromGitter>
<Blacksmoke16> nor that would be generic enough to support all serialization types
<FromGitter>
<drum445> damn
<FromGitter>
<Blacksmoke16> would be nice if you could edit/remove key/value pairs using json builder
<FromGitter>
<Blacksmoke16> i have an idea
<FromGitter>
<Blacksmoke16> naw wont wory
Renich has quit [Quit: Renich]
Renich has joined #crystal-lang
Renich has quit [Client Quit]
Renich has joined #crystal-lang
<FromGitter>
<Blacksmoke16> anyone have an example of how to use `YAML::Nodes::Builder`?
Jenz has joined #crystal-lang
<Jenz>
Is there a macro method to read a file during compile time?
<Jenz>
Specifically I want to read a file into a constant during compile-time
<Jenz>
Im aware of the method using `cat file`, but Im a bit sceptical to doing it like that
<FromGitter>
<r00ster91> Jenz, this macro has actually been added some time ago: https://github.com/crystal-lang/crystal/pull/6967. But it won't be available until 0.27.1 is released. So you probably have to use `cat` for now.
<Jenz>
Ah, well ok, thanks rooster91, I knew I had seen it _somewhere_
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
<FromGitter>
<Blacksmoke16> how do you get the resulting yaml from a `YAML::Nodes::Builder`
junland has quit [Quit: Disconnected.]
junland has joined #crystal-lang
<FromGitter>
<drum445> How do I force the type of a union hash value into a method
<FromGitter>
<drum445> I can use .as(String) is that best?
akaiiro has quit [Remote host closed the connection]
<jokke>
anyone here doing AoC in crystal? :)
<jokke>
i'm doing both rust and crystal this year and i love how the crystal solution to part one is literally one line long
<jokke>
and still super readable
<Jenz>
jokke: Im doing crystal
<jokke>
cool :)
<Jenz>
input.each_line.map(&.to_i).sum
* Jenz
:D
<jokke>
yup :)
<jokke>
spoiler though :P
<Jenz>
oh, eh well
<Jenz>
too late D:
<Jenz>
Maybe if I just post a lot of messages it'll go away with the scroll
* Jenz
hmmm
<FromGitter>
<drujensen> Lol
<jokke>
:D
<FromGitter>
<r00ster91> eh I just wanted to begin solving the puzzle and read this message lol
<Jenz>
Thanks for the help
<jokke>
well it's part 1 isn't rocket science
<jokke>
-it's
<Jenz>
Sorry, @r00ster91
<Jenz>
Is there a crystal leaderboard?
<jokke>
Jenz: you can make one!
<jokke>
i already made one for work
<Jenz>
Here's one for crystal: 289786-69f3013e
<Jenz>
Where do we share it?
<jokke>
dunno?
<Jenz>
Ok, I'll see what I can do to share it
<jokke>
i joined :)
<Jenz>
Nice :D
<FromGitter>
<Blacksmoke16> @j8r its not going to work out. Cant come up with a good enough way that will cover *all*serialization types in a generic way
<FromGitter>
<Blacksmoke16> what would work for one obj doesnt work for an array
<FromGitter>
<Blacksmoke16> it is possible but i would have to override and maintain my own `to_x` method that implements my logic, which isnt terrible, could easily do that if i have code to copy :p and there is a need
<FromGitter>
<Blacksmoke16> but not plug and play method :(
<FromGitter>
<Blacksmoke16> i did find an issue with current master branch of my shard, it didnt handle array of objects correctly 😱
<FromGitter>
<Blacksmoke16> i also dont think i can convert the classes to structs
<FromGitter>
<Blacksmoke16> at least without some refactoring
thews has quit [Ping timeout: 245 seconds]
thews has joined #crystal-lang
Jenz has quit [Quit: leaving]
<FromGitter>
<greenbigfrog> Is there a method on Enumerable, that basically does Enumerable#select.size ? Basically my usage would be to get the amount of X in an Enumerable
<FromGitter>
<Blacksmoke16> Sum?
<FromGitter>
<greenbigfrog> Not rly. I'll explain better in a sec
<FromGitter>
<greenbigfrog> smh I kept missing that
moei has joined #crystal-lang
sevensidedmarble has joined #crystal-lang
<FromGitter>
<asterite> jokke: I'm doing advent of code
<FromGitter>
<asterite> Every year it's the same, I want to try other languages but get bored because I have to write so much
<FromGitter>
<asterite> And I tried Nim but the Set implementation seems to be really slow or dumb and the second part took like 4 seconds, I thought it was never going to end
<FromGitter>
<asterite> So I guess I'll just do them in Crystal again
<FromGitter>
<jgaskins> @greenbigfrog Not if there are duplicate input values
<FromGitter>
<jgaskins> `pp input.group_by(&.itself).transform_values(&.size)` will show you how many of each value there are. there are a lot of duplicates.
<FromGitter>
<greenbigfrog> oh. right
* FromGitter
* greenbigfrog was simply being stupid as always
<FromGitter>
<greenbigfrog> thanks...
<FromGitter>
<girng> array.includes? is nice, loving it
<FromGitter>
<girng> here is my example code: https://play.crystal-lang.org/#/r/5o9k ⏎ I was reading this and it said i should use a tuple instead of allocating a new array. https://crystal-lang.org/docs/guides/performance.html ⏎ ⏎ but i've also read about "stack overflow". how does a stack overflow error work within crystal and is it possible to get a stack overflow by using stack allocated code instead of heap allocated
<FromGitter>
<dscottboggs_gitlab> I've definitely overflowed the stack in crystal by creating too many fibers/channels
<FromGitter>
<dscottboggs_gitlab> I tried to do a naive merge-sort algorithm using fibers to demonstrate concurrency and it did not go well
<FromGitter>
<girng> this is why i worry about structs because the stack is only so much, and the heap we have a lot more memory available (less chance of stack overflowing)? or can the stack take more memory from the heap when it needs it?
<FromGitter>
<dscottboggs_gitlab> tbh I still need to learn how all that works :/
<FromGitter>
<dscottboggs_gitlab> would love to see some resources using Crystal or Go or something at least legible to demonstrate these concepts. Kinda like I tried to do here (https://madscientists.co/pointers/)