jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <octosteve> Hello! Started taking a real look at crystal today and I LOVE IT!!
<FromGitter> <octosteve> Running into something weird when trying to write a DSL. I'm trying to pass a class into a macro and the error I'm getting thinks it's a path
<FromGitter> <octosteve> I think I muscled through it somehow
<FromGitter> <octosteve> I have another question though. Regarding types. How do I match that the *type* of an argument is a particular class?
<FromGitter> <octosteve> not an instance of that class?
<postmodern> octosteve, i think that'd be `foo : MyClass.class`? https://crystal-lang.org/reference/syntax_and_semantics/type_restrictions.html
<postmodern> see "Classes as restrictions"
<FromGitter> <octosteve> Yea I think I'm in a weird rabbit hole. So I'm trying to figure out a type that works for a set of classes that *include* a certain module
<FromGitter> <octosteve> Error: no overload matches 'Hash(String, Protobuf::Message:Module)#[]=' with types String, Events::AThingWasDone.class
<FromGitter> <octosteve> That's what my error looks like. I'm trying to setup a hash that has a string key, and a value of a class that includes the Protobuf::Message module
chachasmooth has quit [Ping timeout: 246 seconds]
chachasmooth has joined #crystal-lang
postmodern has quit [Quit: Leaving]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/cr can you make an example?
<FromGitter> <Blacksmoke16> in regards to the macro question, you prob need to call `.resolve` on the argument
<FromGitter> <Blacksmoke16> which resolves the path to its actual type
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 260 seconds]
<FromGitter> <Blacksmoke16> it sounds like you're doing `hash["foo"] = SomeClassThatIncludesTheModule`
<FromGitter> <Blacksmoke16> when it should be `hash["foo"] = some_instance_of_a_class_that_includes_the_module`
<FromGitter> <octosteve> I got something working. I pass in an instance, and call x.class.method
<FromGitter> <Blacksmoke16> what are you trying to do exactly?
<FromGitter> <octosteve> So many things
<FromGitter> <octosteve> Hold on
<FromGitter> <octosteve> Working on a DSL for encoding and decoding protobufs based on a string representation of the class used to decode it
<FromGitter> <Blacksmoke16> have you seen https://github.com/jeromegn/protobuf.cr/ ?
<FromGitter> <octosteve> The problem code is here https://github.com/octosteve/railway_ipc_cr/blob/master/src/handler.cr#L5
<FromGitter> <octosteve> Yes, I'm using that
<FromGitter> <octosteve> https://github.com/octosteve/railway_ipc_cr/blob/master/src/handler.cr#L9 is where i had to call `.new`
<FromGitter> <octosteve> instead of just having the class as the value since I didn't know how to setup a hash's key to be a class
<FromGitter> <Blacksmoke16> `Hash(String, Protobuf::Message.class)`?
<FromGitter> <octosteve> that includes Protobuf::Message
<FromGitter> <octosteve> I can try that
<FromGitter> <octosteve> Give me sec
<FromGitter> <Blacksmoke16> im assuming the module comes from the other shard?
<FromGitter> <octosteve> It comes from that Protobuf shard you linked
<FromGitter> <Blacksmoke16> might not work then
<FromGitter> <Blacksmoke16> it would be possible via what you have now if you have people use `extend` instead of `include`
<FromGitter> <Blacksmoke16> otherwise having your own type structure might be a big easier
<FromGitter> <octosteve> Was thinking about that. Wrapping everything
<FromGitter> <Blacksmoke16> also couldnt you use overloads instead of a hash?
<FromGitter> <octosteve> The hash is there to convert a string to a class
<FromGitter> <octosteve> The handling does use overloading though
<FromGitter> <octosteve> The "type" value I get from amqp is a string
<FromGitter> <Blacksmoke16> https://github.com/octosteve/railway_ipc_cr/blob/master/src/handler.cr#L22 ideally couldnt this be a compile time error?
<FromGitter> <octosteve> so the hash is there to convert the values
<FromGitter> <octosteve> Maybe? You don't know what you're going to get over the wire
<FromGitter> <Blacksmoke16> fair
<FromGitter> <octosteve> This is fun!
<FromGitter> <octosteve> Been nose down on Elixir for a bit so I'm looking for pattern matching a lot. Didn't know if that overloading pattern was *right*
<FromGitter> <octosteve> One thing I am trying to noodle over is recovering from failure. No supervision trees! If my rabbit connection croaks, I'll just have to rescue in my spawn I guess and restart
_whitelogger has joined #crystal-lang
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 240 seconds]
postmodern has joined #crystal-lang
zorp_ has quit [Ping timeout: 246 seconds]
<deimos_> I think i have a comipler bug, but no idea how to go about debugging it. if i run ```crystal run code.cr``` everything works. if i run ```cyrstal build code.cr```, the resulting binary works fine. if i add --release to the build code.cr, i get a indexerror in boehm.cr
<deimos_> i'm trying to recreate to get more detail
<FromGitter> <naqvis> doesn't the stacktrace shows the details about the line of code which triggering that error?
<FromGitter> <naqvis> might worth adding `--debug` during your build
zorp_ has joined #crystal-lang
hsh has joined #crystal-lang
bazaar has quit [Quit: leaving]
bazaar has joined #crystal-lang
alexherbo2 has joined #crystal-lang
zorp_ has quit [Ping timeout: 240 seconds]
alexherbo2 has quit [Ping timeout: 246 seconds]
alexherbo2 has joined #crystal-lang
alexherbo21 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo21 is now known as alexherbo2
postmodern has quit [Quit: Leaving]
_whitelogger has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi_ has joined #crystal-lang
Vexatos has quit [Quit: ZNC Quit]
Vexatos has joined #crystal-lang
psydroid has quit [Quit: killed]
ryanprior has quit [Quit: killed]
return0e[m] has quit [Quit: killed]
hamoko[m] has quit [Quit: killed]
deavmi_ has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
ryanprior has joined #crystal-lang
hamoko[m] has joined #crystal-lang
psydroid has joined #crystal-lang
return0e[m] has joined #crystal-lang
<FromGitter> <maxbertinetti> @maxbertinetti ⏎ Hi guys ⏎ ⏎ ```code paste, see link``` ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5f52384e89cf2d584b992195]
<FromGitter> <Blacksmoke16> and you share your shard.yml/lock?
zorp_ has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 240 seconds]
zorp_ has quit [Ping timeout: 244 seconds]
<oprypin> oh god did they break this use case as well
<yxhuvud> ?
<FromGitter> <maxbertinetti> name: microsecond-blog ⏎ version: 0.1.0 ⏎ ⏎ authors: ⏎ ... [https://gitter.im/crystal-lang/crystal?at=5f5256559566774dfe53c55c]
<FromGitter> <maxbertinetti> ``````
<FromGitter> <Blacksmoke16> so the problem is pretty clear via the error
<FromGitter> <Blacksmoke16> amber requires a PG version of `~> 0. 21.1` while clear wants master
<FromGitter> <Blacksmoke16> theres no overlap of those requirements, so it cant resolve a version to use
<FromGitter> <maxbertinetti> How?
<FromGitter> <Blacksmoke16> imo clear is in the wrong requiring `master` like that
<FromGitter> <maxbertinetti> Also 0.21.1 and master are the same version
<FromGitter> <Blacksmoke16> thats not a good practice
<FromGitter> <maxbertinetti> Ok, so I can ask to the author to change that?
<FromGitter> <Blacksmoke16> maybe the point to the same commit atm but they are deff not equal
<FromGitter> <Blacksmoke16> they*
<FromGitter> <maxbertinetti> It’s not something that I can resolve locally in a clean way
<FromGitter> <Blacksmoke16> other option would be to make use of the new shard override thing to make pin clear to same version as what amber wants
<FromGitter> <maxbertinetti> Where I can find docs about that?
<FromGitter> <Blacksmoke16> see https://github.com/crystal-lang/shards/pull/422
<FromGitter> <maxbertinetti> Thanks
<FromGitter> <maxbertinetti> It doesn’t work. I think because it cannot install and create the shard.lock because of the conflict
<FromGitter> <maxbertinetti> ``````
<FromGitter> <Blacksmoke16> :shrug: i never tried it
zorp_ has joined #crystal-lang
<FromGitter> <mtsmmp_gitlab> hey guys, any way to convert string to class name?
<FromGitter> <Blacksmoke16> not by default
<FromGitter> <Blacksmoke16> what are you wanting to do?
<FromGitter> <mtsmmp_gitlab> something like this
<FromGitter> <mtsmmp_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f527c11dfaaed4ef52f3181]
<FromGitter> <Blacksmoke16> no
<FromGitter> <Blacksmoke16> thats not a thing
<FromGitter> <Blacksmoke16> is there something you're working on that needs that?
<FromGitter> <mtsmmp_gitlab> it would help
<FromGitter> <mtsmmp_gitlab> would be faster
<FromGitter> <Blacksmoke16> got an example of what your use case is?
<FromGitter> <mtsmmp_gitlab> its like
<FromGitter> <mtsmmp_gitlab> i have the classes' names stored already somewhere, instead of picking which one ill instantiate i would just loop through the data and instantiate them straight up. without having to create a class to control which one im calling
<FromGitter> <mtsmmp_gitlab> like this i would be just passing information through different functions and i dont like that
<FromGitter> <Blacksmoke16> can you share more of what you're ultimately trying to do?
<FromGitter> <Blacksmoke16> like you're storing them in a file and wanting to create an instance of each class based on the data from the file?
<FromGitter> <mtsmmp_gitlab> ye
<FromGitter> <mtsmmp_gitlab> the simplest example
<FromGitter> <mtsmmp_gitlab> ```pages = ["Home", "Blog", "About"] ⏎ ⏎ pages.each do |Page| ⏎ "Page".new ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f527ddd482378093764aa48]
<FromGitter> <Blacksmoke16> heres a thought
<FromGitter> <Blacksmoke16> why not just do like
<FromGitter> <Blacksmoke16> ```pages = [Home, Blog, About] ⏎ ⏎ pages.each do |p| ⏎ p.new ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f527dfec3aa024ef9c13e24]
<FromGitter> <Blacksmoke16> tada?
<FromGitter> <mtsmmp_gitlab> the page names are strings
<FromGitter> <Blacksmoke16> granted if you're reading these in dynamically from a file or something idt you can do that
<FromGitter> <Blacksmoke16> do they have to be strings?
<FromGitter> <mtsmmp_gitlab> yes
<FromGitter> <Blacksmoke16> because you're storing them in a file and not statically in an array like that?
<FromGitter> <mtsmmp_gitlab> yep
<FromGitter> <mtsmmp_gitlab> actually their names are always in the file. it just happens that i gave the classes the same exact name
<FromGitter> <mtsmmp_gitlab> so i thought, well it would be nice to just read this from the file
<FromGitter> <mtsmmp_gitlab> and initialize all of them
<FromGitter> <mtsmmp_gitlab> since they are already there, so
<FromGitter> <Blacksmoke16> what else is stored in this file? just the class names or?
<FromGitter> <mtsmmp_gitlab> page names
<FromGitter> <mtsmmp_gitlab> of a website
<FromGitter> <mtsmmp_gitlab> as i said i gave the class names the same page names that are in the file
<FromGitter> <Blacksmoke16> and these classes contain the data that should be rendered on each page?
<FromGitter> <mtsmmp_gitlab> yea
<FromGitter> <mtsmmp_gitlab> they literally create the page
<FromGitter> <Blacksmoke16> got an example of what one looks like?
<FromGitter> <mtsmmp_gitlab> oh
<FromGitter> <mtsmmp_gitlab> we are getting nowhere lol
<FromGitter> <Blacksmoke16> well im just trying to learn how you have everything setup
<FromGitter> <Blacksmoke16> because i feel like there is a better alternate solution
<FromGitter> <mtsmmp_gitlab> maybe you can help me other way
<FromGitter> <perfecto25> hello, Im trying to setup a Multicast listener via UDP Socket (https://crystal-lang.org/api/0.33.0/UDPSocket.html) ⏎ ⏎ Im trying to figure out how to make it bind to a specific interface (we have Solarflare ifaces that receive market data) ⏎ ⏎ ```code paste, see link``` ... [https://gitter.im/crystal-lang/crystal?at=5f5280bd89cf2d584b99fbbb]
<FromGitter> <mtsmmp_gitlab> @Blacksmoke16 ``` ⏎ Class.new(first_param, some_param, other_param, param: "something_cool") ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f528100ec534f584fe28bce]
<FromGitter> <mtsmmp_gitlab> duh
<FromGitter> <mtsmmp_gitlab> ```Class.new(first_param, some_param, other_param, param: "something_cool")``` ⏎ ⏎ how do i get the first_param, isolate it and pass everything that is after to another function? i know its a noob question but i was thinking about doing something with it [https://gitter.im/crystal-lang/crystal?at=5f52810a49148b41c99489b9]
<FromGitter> <Blacksmoke16> could do something like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f52814c59ac794e02ea0083]
<FromGitter> <mtsmmp_gitlab> cool!
<FromGitter> <Blacksmoke16> although i wouldnt go around just doing `*args, **named_args` everywhere...
<FromGitter> <mtsmmp_gitlab> ok
<FromGitter> <mtsmmp_gitlab> makes sense
<FromGitter> <mtsmmp_gitlab> that helps
<FromGitter> <Blacksmoke16> @perfecto25 have you seen https://github.com/crystal-lang/crystal/issues/3825 ?
<FromGitter> <Blacksmoke16> something in the issue/pr/specs maybe
alexherbo2 has quit [Ping timeout: 256 seconds]
alexherbo2 has joined #crystal-lang
postmodern has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 260 seconds]
alexherbo2 has joined #crystal-lang
repo has quit [Remote host closed the connection]
alexherbo26 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 264 seconds]
alexherbo26 is now known as alexherbo2
hsh has quit [Quit: Connection closed for inactivity]
renich has joined #crystal-lang
renich has quit [Quit: Leaving.]
postmodern has quit [Quit: Leaving]