ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | 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
<FromGitter> <elementio:salt-rock-lamp.ems.host> ```module Q ⏎ q = 1 ⏎ end``` ⏎ ⏎ where does the `q` get assigned here? [https://gitter.im/crystal-lang/crystal?at=6080c2b4a9dd556843f2848b]
<FromGitter> <elementio:salt-rock-lamp.ems.host> is this local to the `Q` namespace and inaccessible from outside?
<FromGitter> <tenebrousedge> ```module Q; q = 1; end ⏎ puts q``` [https://gitter.im/crystal-lang/crystal?at=6080c2f997cf50674677e500]
<FromGitter> <tenebrousedge> `#=> 1`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/ayaz, works in both
<FromGitter> <tenebrousedge> `icr` is nice for answering questions like that. Also the local and online playgrounds
<FromGitter> <Blacksmoke16> icr is not great
<FromGitter> <tenebrousedge> wjat
<FromGitter> <Blacksmoke16> just have a file called `test.cr` and run it
<FromGitter> <Blacksmoke16> ^
<FromGitter> <tenebrousedge> I um. `icr` has limitations, but I still like REPLs
<FromGitter> <Blacksmoke16> if it works for you great, but its not something i would test things with
<FromGitter> <Blacksmoke16> as it does things unique to it
<FromGitter> <tenebrousedge> yes, it displays a notice to that effect on startup. It does have relatively limited utility compared to `pry` or even `psy`, but does usually work to answer questions like the above
<FromGitter> <tenebrousedge> as a tool for serious development, it's probably best avoided
<FromGitter> <tenebrousedge> as a "does this language work the way I think it does" it has a short feedback loop
<FromGitter> <elementio:salt-rock-lamp.ems.host> its pretty cool to have a repl for a compiled language so ill take it
<FromGitter> <Blacksmoke16> Then leads to wrong understanding of how the language works because it's not using the actual language
<FromGitter> <elementio:salt-rock-lamp.ems.host> ive been messing around with a `test.cr` file as well
<FromGitter> <elementio:salt-rock-lamp.ems.host> i didnt think to try it as a top-level assignment
<FromGitter> <tenebrousedge> it is using the actual language: anything compiled successfully by the crystal compiler must be Crystal code
<FromGitter> <Blacksmoke16> Is possible for a bug to happen when using icr that otherwise wouldn't happen
<FromGitter> <elementio:salt-rock-lamp.ems.host> can i disable ansi colors in the crystal cli?
<FromGitter> <elementio:salt-rock-lamp.ems.host> i dont see a `--color=no` or equivalent option
<FromGitter> <tenebrousedge> `icr --help`
<FromGitter> <elementio:salt-rock-lamp.ems.host> ah it's an option to `run`
<FromGitter> <elementio:salt-rock-lamp.ems.host> it's not in the top-level `--help`
<FromGitter> <tenebrousedge> oh, that one
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <elementio:salt-rock-lamp.ems.host> ok, i wrote up what i believe is a correct explanation of inheritance vs inclusion vs extension
<FromGitter> <elementio:salt-rock-lamp.ems.host> https://stackoverflow.com/a/67205474/2954547
<FromGitter> <elementio:salt-rock-lamp.ems.host> if someone is willing to take a look and @ me here or comment on SO with revisions or corrections, i would appreciate it
andremedeiros has quit [Read error: Connection reset by peer]
andremedeiros has joined #crystal-lang
kevinsjoberg has joined #crystal-lang
_ht has joined #crystal-lang
hendursaga has joined #crystal-lang
hendursa1 has quit [Ping timeout: 240 seconds]
deavmi has quit [Ping timeout: 260 seconds]
deavmi has joined #crystal-lang
<FromGitter> <confact> Any way to make a hash of a class and its properties? It would be nice :D
<FromGitter> <erdnaxeli:cervoi.se> nop, but you can easily generate the code that does that with a macro
<FromGitter> <erdnaxeli:cervoi.se> https://carc.in/#/r/aydy
<FromGitter> <confact> Seems I can not do anything with it as it is macro. I am trying to merge things with it and make it a NamedTuple.
<FromGitter> <erdnaxeli:cervoi.se> you could generate an NamedTuple like I did (just replace the "=>" by ":")
<FromGitter> <erdnaxeli:cervoi.se> but namedtuple must be known at compilation time, so you can't do the merge with dynamic values on runtime
<FromGitter> <confact> ah crap ^^
<FromGitter> <confact> I will have to create a long method that make me a NamedTuple with dynamic values then.
<FromGitter> <erdnaxeli:cervoi.se> why do you need a NamedTuple? you can't use a hash?
<FromGitter> <erdnaxeli:cervoi.se> or better, a record
mipmip has quit [Read error: Connection reset by peer]
mipmip has joined #crystal-lang
<FromGitter> <erdnaxeli:cervoi.se> is that expected? https://carc.in/#/r/ayea
<FromGitter> <erdnaxeli:cervoi.se> I was thinking log levels were inherited
<straight-shoota> it seems unless specified, nested loggers have the default log level
<FromGitter> <erdnaxeli:cervoi.se> ☹️
sagax has quit [Ping timeout: 245 seconds]
_ht has quit [Ping timeout: 245 seconds]
_ht has joined #crystal-lang
xybre has quit [*.net *.split]
xybre has joined #crystal-lang
hendursaga has quit [Remote host closed the connection]
hendursaga has joined #crystal-lang
bougyman has quit [Ping timeout: 260 seconds]
bougyman has joined #crystal-lang
hendursaga has quit [Remote host closed the connection]
hendursaga has joined #crystal-lang
Stephanie has joined #crystal-lang
ua_ has quit [*.net *.split]
daemonwrangler has quit [*.net *.split]
Stephie has quit [*.net *.split]
duane has quit [*.net *.split]
<FromGitter> <erdnaxeli:cervoi.se> what is the point of doing `i = self ^ self` here instead of `i = 0`? https://github.com/crystal-lang/crystal/blob/dd40a2442/src/int.cr#L521
ua_ has joined #crystal-lang
<FromGitter> <oprypin:matrix.org> erdnaxeli (https://matrix.to/#/@erdnaxeli:cervoi.se): instead of `i = 0_i32`
<FromGitter> <erdnaxeli:cervoi.se> ah, good point
<FromGitter> <oprypin:matrix.org> it's a weird way to get a zero of the current type. by now there's probably a better way
<FromGitter> <erdnaxeli:cervoi.se> but I think it could use `self.class.zero`
<FromGitter> <oprypin:matrix.org> would be interesting to compare the generated code in each case
<FromGitter> <erdnaxeli:cervoi.se> is there a (simple) way to receive a message from a channel and prevent other message to be sent to this channel while I am processing the message? (with a non buffered channel) ⏎ Something like `channel.receive { |value| process(value) }`, and `send` would block until the block given to `receive` ends. ⏎ I could do something myself with two channel, but that's less simple...
<FromGitter> <erdnaxeli:cervoi.se> actually what I want is to be sync, maybe I don't need a channel to communicate but just to give a callback to the fiber generating the value
<FromGitter> <oprypin:matrix.org> erdnaxeli (https://matrix.to/#/@erdnaxeli:cervoi.se): it's hard to think of a way to do that but it's also hard to think how this could ever be useful
<FromGitter> <oprypin:matrix.org> literally just call the method, dont use a channel
<FromGitter> <erdnaxeli:cervoi.se> yeah ^^'
r0bby has quit [Read error: Connection reset by peer]
sz0 has quit [Read error: Connection reset by peer]
sz0 has joined #crystal-lang
r0bby has joined #crystal-lang
<FromGitter> <rishavs> Have a coding pattern question. I am using a hash map to keep a list of all my api services. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I essentially escape from using a large case/if-else branching using a hash lookup, which I like. ... [https://gitter.im/crystal-lang/crystal?at=6081d600b9e6de24d65046d3]
_ht has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> ```if service = services[url]? ⏎ return service.new context ⏎ end``` ⏎ ⏎ something like that? [https://gitter.im/crystal-lang/crystal?at=6081d6a8a9dd556843f5492d]
<FromGitter> <Blacksmoke16> nvm, i misread
<FromGitter> <Blacksmoke16> however you could have a hash of procs
<FromGitter> <Blacksmoke16> like `Hash(String, Proc(HTTP::Server::Context, Nil))`, then `service.call context`
<straight-shoota> yeah, function pointer is a proc
<straight-shoota> >> def foo; puts "foo"; end; functions = {"f" => ->foo}; functions["f"].call
<DeBot> straight-shoota: foo - more at https://carc.in/#/r/ayl0
<FromGitter> <Blacksmoke16> fwiw thats essentially how athena works :P
<FromGitter> <rishavs> great minds think alike :p
<FromGitter> <rishavs> but thanks. it was instructional
djuber has left #crystal-lang ["ERC (IRC client for Emacs 28.0.50)"]
r0bby has quit [Ping timeout: 250 seconds]
r0bby has joined #crystal-lang
postmodern has joined #crystal-lang
<postmodern> does crystal have a Duration type?
<FromGitter> <Blacksmoke16> Time::Span probably
<postmodern> ah that's it!
<Andriamanitra> can someone explain what i'm doing wrong? (i'm trying to mix in some event handlers) https://play.crystal-lang.org/#/r/ayna
<FromGitter> <Blacksmoke16> i mean as the error says there is no `on` method in the module when it's trying to execute it
<FromGitter> <oprypin:matrix.org> Andriamanitra guess you have to include it at the end not at the beginning lol
<FromGitter> <Daniel-Worrall> Top level code in the module is ran
<FromGitter> <Blacksmoke16> ^
<FromGitter> <Daniel-Worrall> there is no `on` in the context of the module on its own
<Andriamanitra> i'm still getting errors no matter where i include it ("undefined constant EventHandlers")
<FromGitter> <Daniel-Worrall> https://play.crystal-lang.org/#/r/ayne
<FromGitter> <Daniel-Worrall> It is ran regardless of including or not
<FromGitter> <Blacksmoke16> prob could just wrap it in `macro included`
<Andriamanitra> ok i see why this is not working, would macros be the right way to do it then?
<FromGitter> <Blacksmoke16> prob, or a diff design/approach
<Andriamanitra> my goal is to separate different types of events across different files/modules so i could easily choose which ones to enable when compiling, is there a different (better) way to achieve this with some other design?
<FromGitter> <Blacksmoke16> is there a reason to not just register them all?
<Andriamanitra> yes, i don't want all of them running at the same time
<FromGitter> <Daniel-Worrall> https://crystal-lang.org/reference/syntax_and_semantics/macros/hooks.html included hook is powerful
<Andriamanitra> i couldn't figure out how to use the macro but i realized a simple method would work for me https://play.crystal-lang.org/#/r/aynn
<FromGitter> <Blacksmoke16> mmk
<Andriamanitra> i guess the downside is that you couldn't use the module as a type this way but i won't be needing that in this case
<FromGitter> <Blacksmoke16> could you make each listener a dedicated type?
<FromGitter> <Blacksmoke16> idk what the end goal of this is tho
<Andriamanitra> probably could and that's what i was going to do initially but it felt like a lot of extra code for not a lot of extra functionality
<Andriamanitra> (what i'm working on is a chat bot thing but i doubt it'll go anywhere)
<FromGitter> <Blacksmoke16> https://athenaframework.org/EventDispatcher/ could be helpful :shrug:
<Andriamanitra> thanks, i'll check that out