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
<FromGitter> <tenebrousedge> kay. It's 2005 hours. Do I keep coding?
<FromGitter> <Daniel-Worrall> 4 hour break, start again when AoC drops
<FromGitter> <tenebrousedge> kay
f1refly has joined #crystal-lang
<FromGitter> <tenebrousedge> hmmm. Your solution today was short
f1refly- has quit [Ping timeout: 272 seconds]
<Andriamanitra> kevinsjoberg: maybe you've figured it out by now but you can save a lot of performance if in part1 you start from the desired vertex rather than doing full dfs for every bag in the input (you'd need to modify the graph to allow traversing in that direction)
teardown has quit [Ping timeout: 240 seconds]
teardown has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
f1refly has quit [Ping timeout: 256 seconds]
coderobe has quit [Quit: Ping timeout (120 seconds)]
coderobe has joined #crystal-lang
FromGitter has quit [Ping timeout: 260 seconds]
f1refly has joined #crystal-lang
oprypin has quit [Ping timeout: 264 seconds]
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
oprypin has joined #crystal-lang
f1refly has quit [Ping timeout: 264 seconds]
f1refly has joined #crystal-lang
_whitelogger has joined #crystal-lang
teardown_ has joined #crystal-lang
HumanG33k has quit [Ping timeout: 240 seconds]
teardown has quit [Ping timeout: 240 seconds]
f1refly has quit [Ping timeout: 264 seconds]
f1refly has joined #crystal-lang
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
chachasmooth has quit [Ping timeout: 264 seconds]
hightower3 has quit [Ping timeout: 240 seconds]
chachasmooth has joined #crystal-lang
f1refly- has joined #crystal-lang
f1refly has quit [Ping timeout: 272 seconds]
gangstacat has quit [Quit: Ĝis!]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
chachasmooth has quit [Ping timeout: 240 seconds]
chachasmooth has joined #crystal-lang
gangstacat has joined #crystal-lang
_whitelogger has joined #crystal-lang
teardown_ has quit [Ping timeout: 240 seconds]
<kevinsjoberg> Andriamanitra: Yeah, realized it just before bed actually. I reversed the graph.
<kevinsjoberg> Felt like todays problem was much easier than yesterdays. *shrugs*
<Andriamanitra> yeah felt easier for sure, although i'm worried this is intcode v2
<Andriamanitra> ..so i'm determined to write the most robust overengineered interpreter i possibly can so i maybe don't need to start from scratch next time it comes up
<kevinsjoberg> Haha, don't bring back those memories. Still haunts me.
<Andriamanitra> search in the new crystal reference manual might need some love.. i typed in "while" and it says no matching documents
woodruffw has quit [Ping timeout: 256 seconds]
woodruffw has joined #crystal-lang
postmodern has joined #crystal-lang
hightower4 has joined #crystal-lang
<Andriamanitra> this will have to do.. for now at least https://github.com/Andriamanitra/adventofcode2020/blob/main/day08/solution.cr
<Andriamanitra> also is this a known issue or something i should report? https://play.crystal-lang.org/#/r/a2w6
<kevinsjoberg> How does parse work?
<kevinsjoberg> Given enums only support integer values
<kevinsjoberg> this was my implementation by the way
<kevinsjoberg> Not as structured as yours.
<Andriamanitra> it basically camelcases the string and sees if that's one of the constants in the enum
<Andriamanitra> so all of "jmp" "JMP" and "JmP" would parse to IType::Jmp
<kevinsjoberg> That's awesome. Didn't know about it.
<sorcus> asterite: Hi. https://gist.github.com/MrSorcus/6b644e7485d84b8e5052248231f40f48 - should i open an issue?
<f1reflyylmao> I usually feel bad when I see the way better solutions here but today wasn't _that_ bad https://gitgud.io/f1refly/adventofcode2020/-/blob/master/aoc08/src/aoc08/aoc08.cr
<Andriamanitra> what's the ex.message.not_nil!.to_i about?
<f1reflyylmao> I wanted a way to differentiate between regular "line doubled" acc output and "now we have reached the last line" acc output. Given that it tries to access a point after the array I thought raising an exception in that case may be dirty but functional
<f1reflyylmao> That way I could use my loop searching function in my program repair function and saved a lot of work
<Andriamanitra> oh i see now.. yeah that's certainly dirty :D
<f1reflyylmao> Sometimes I think the rust guys may be onto something with their exceptionless language, but I just cant get myself to take a closer look
postmodern has quit [Quit: Leaving]
sorcus has quit [Quit: WeeChat 2.9]
f1reflyylmao has quit [Remote host closed the connection]
f1refly has joined #crystal-lang
<straight-shoota> did anyone solve today's AoC part 2 _without_ brute force?
<kevinsjoberg> nope, brute force all the way.
<yxhuvud> no. Solver goes brr. I mean, it still takes like 0.006s.
<straight-shoota> sure
<yxhuvud> and that is before polishing.
<kevinsjoberg> I had a list of candidates (all jmp and nop) and then just popped and flipped until it worked.
<straight-shoota> just considering backtracking for academic reasons
<straight-shoota> but it's hard also because every acc could be a target from any flipped nop
<f1refly> I considered doing something clever for a moment, but it just didn't seem like it'd be worth it to me
<kevinsjoberg> I was considering that initially, but decided not to pursue it in the end.
<Andriamanitra> straight-shoota: yes, i did
<yxhuvud> hmm. I have an idea that might work. Something to investigate tonight I think.
<Andriamanitra> although not initially, i only implemented the smarter way afterwards
<f1refly> You could probably make a finer selection of the list and consider only the nops that point to lines.size or the jumps that mask other jumps that point there
<Andriamanitra> i went through the program once saving all the steps and the states at each step, then tried to continue from each state where the current instruction was either jmp or nop
<Andriamanitra> funnily enough i first implemented the history just for debugging possible later problems and only then thought hey i can actually use this :p
<raz> i don't even understand what the goal of that task is
<raz> just run the thing and report the last value before it goes into a loop?
<Andriamanitra> in part1, yeah
<Andriamanitra> in part2 you want to find an input that takes you all the way through the code without looping
<raz> ahh gotcha
<raz> i wasn't logged in so only saw the first part
<raz> i'm too lazy for these puzzles, but still curious :D
<Andriamanitra> i do wonder if there's even less bruteforce method than mine, it's entirely possible there's some smart trick that lets you not even execute the code
<raz> well my feeling is it's likely a play on the halting problem (so only brute force can solve it)
<raz> but perhaps there's some algorithm hidden in the code that could make it predictable
<raz> blacksmoke16: where's 0.12, i need RequestParam πŸ€“
sorcus has joined #crystal-lang
<straight-shoota> Andriamanitra, but that's brute force: https://github.com/Andriamanitra/adventofcode2020/blob/main/day08/solution.cr#L105
<Andriamanitra> it's not checking every jmp/nop instruction nor is it starting from the beginning
<straight-shoota> okay a little bit informed brute force
<Andriamanitra> yeah i guess it's still sort of brute force
<Andriamanitra> also now that i look at it i don't know how it even gets the right answer, that should be bugged
<straight-shoota> why? looks fine to me
<Andriamanitra> run_until_repeat initializes the set of visited to empty, but the execution resumes from midway through
sorcus has quit [Quit: WeeChat 2.9]
<straight-shoota> ah, so it could also match for a loop that loops back to a state before the execution resumed
<straight-shoota> but then it would loop again
<Andriamanitra> oh right
<straight-shoota> so you don't need that previous state to be correct
<Andriamanitra> because the program can't change itself
<Andriamanitra> and has no conditions
<straight-shoota> exactly
<straight-shoota> if there's a loop, it's going to loop always, no matter how many iterations are skipped
<straight-shoota> or part of iterations
<straight-shoota> a jmp may land you in the middle of an iteration where the previous steps haven't been visited
<straight-shoota> same thing
sorcus has joined #crystal-lang
sorcus has quit [Client Quit]
sorcus has joined #crystal-lang
skrzyp has quit [Ping timeout: 264 seconds]
<kevinsjoberg> I'm thinking about giving Emacs a try. Any emacs users here? If so, how's the support for Crystal?
xaxisx has joined #crystal-lang
<straight-shoota> it seems the gitter bridge is down
<straight-shoota> jhass ^
<jhass> oprypin runs the bridge :)
<straight-shoota> oh, I confused it with DeBot :D
<sorcus> kevinsjoberg: What do you mean by "support for Crystal"? Syntax highlighting or something else?
<kevinsjoberg> sorcus: syntax highlighting mostly but tooling integration would be nice as well.
woodruffw has quit [Ping timeout: 256 seconds]
woodruffw has joined #crystal-lang
<sorcus> kevinsjoberg: Oh, than i don't know. I use neovim. :-(
<sorcus> kevinsjoberg: https://github.com/crystal-lang-tools/emacs-crystal-mode - did you try this?
xaxisx has quit [Quit: Leaving...]
<kevinsjoberg> Nope, never used Emacs, so was just scouting. Thanks though! πŸ‘
f1refly has quit [Disconnected by services]
f1refly- is now known as f1refly
<hightower4> Blacksmoke16 wasn't there an example of yours for using Athena with some/any crystal db framework?
<straight-shoota> hightower4 he is probably not going to see this because the Gitter bridge is down
<hightower4> cool, thanks
<straight-shoota> actually they're currently talking about db stuff on Gitter
FromGitter has joined #crystal-lang
<FromGitter> <Blacksmoke16> if you're using granite pretty sure you could do like `Vuln.find_by(belongs_to: repo).to_json io`
<FromGitter> <Blacksmoke16> versus creating a new string for each array item
<FromGitter> <3n-k1> that query actually doesn't even work xd
<FromGitter> <Blacksmoke16> rip, you know what i mean tho
<FromGitter> <3n-k1> but i'll definitely do that, ty
<straight-shoota> ... and then the bridge's back on
<FromGitter> <Blacksmoke16> plus granite models include JSON::Serializable as well
<FromGitter> <3n-k1> oh that's nice
<oprypin> i restarted the IRC <-> Gitter bridge. i actually had done another restart earlier but that didnt help. seems like gitter api was failing
<oprypin> `POST https://api.gitter.im/v1/rooms {"uri":"BlaXpirit/critter"}`
<oprypin> `Unhandled exception: getaddrinfo: Temporary failure in name resolution (Socket::Addrinfo::Error)`
<raz> oh, then i have to nag Blacksmoke16 again! Blacksmoke16: where's 0.12, i need RequestParam 😬
<oprypin> it kept seeing this thing after several restarts and gave up eventually, it seems
<FromGitter> <Blacksmoke16> *soon*, writing up forum thread atm, so prob tomorrow morning?
<FromGitter> <Blacksmoke16> could just pin to latest commit for now tho
<straight-shoota> oprypin that could also be a DNS error
<FromGitter> <Blacksmoke16> would essentially be what the version is
<oprypin> straight-shoota, could be yea
<raz> yay :) (and no stress! just whipping the ungrateful OSS-user whip a bit :P)
<raz> yup, i might just switch to master for now. just not keen on bumping into potential dep troubles
<FromGitter> <Blacksmoke16> commit would be safer
<FromGitter> <Blacksmoke16> as like soon as i release `0.12.0` im going to remove that deprecated method
<raz> yea i'll just wait a bit, have enough other stuff on my plate anyway (just using athena for the internal admin REST-API)
<FromGitter> <Blacksmoke16> πŸ‘Œ
sagax has quit [Ping timeout: 240 seconds]
<frojnd> Where can I paste code so it can be seen an output?
<oprypin> frojnd, https://carc.in
DTZUZU has quit [Read error: Connection reset by peer]
<FromGitter> <Blacksmoke16> `time.is_a? String`
<FromGitter> <Blacksmoke16> not `typeof(time) == String`
<oprypin> frojnd, `typeof(time) == String` is not a supported way to tell something to a compiler
<FromGitter> <Blacksmoke16> also could use a case
<FromGitter> <Blacksmoke16> ```case time ⏎ in String then "..." ⏎ in Time then "..." ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5fcfd273b252c17f51524997]
<frojnd> oprypin: yeah what I was trying to do is if type is String return this else return that
<frojnd> is_a? thats' what I was missing
<oprypin> frojnd, it's simple, the compiler treats this syntax specially `a.is_a?(String)` but not this syntax `typeof(a) == String`
<oprypin> but as people said before, this has 0 reason to be 1 method instead of 2 method overloads
<frojnd> What's cleaner?
<frojnd> Probably 2 method overloads
<FromGitter> <Blacksmoke16> id say so
<frojnd> If I remove first puts "verse url... then there is no error
<frojnd> Just thought it's interesting
DTZUZU has joined #crystal-lang
<frojnd> Yeah much cleaner
<oprypin> frojnd, yes quite interesting. in this case the compiler just never noticed that this method is broken because it never instantiated the method `verse_url(String, String)`, it only instantiated `verse_url(String, Time)`
<frojnd> Yeah.. why is that hm
<FromGitter> <Blacksmoke16> its never called so it doesnt make it into the binary
<frojnd> Ok now I get it
renich has joined #crystal-lang
mistergibson has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
mps has joined #crystal-lang
<FromGitter> <erdnaxeli:cervoi.se> Hi, why this works https://carc.in/#/r/a310 but this does not https://carc.in/#/r/a311 ?
<FromGitter> <erdnaxeli:cervoi.se> did I found a bug?
<FromGitter> <Blacksmoke16> prob something to do those two methods not returning the same thing
teardown has joined #crystal-lang
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> no sure looks like a bug i think? it should know not to push the iterator stop value
<FromGitter> <Blacksmoke16> :shrug: im not super familiar with iterators
<FromGitter> <erdnaxeli:cervoi.se> yeah it's weird that it pushes the stop value
<FromGitter> <erdnaxeli:cervoi.se> wel, that it tries
<FromGitter> <Blacksmoke16> its part of how iterator is implemented
<FromGitter> <Blacksmoke16> > To implement an Iterator you need to define a #next method that must return the next element in the sequence or Iterator::Stop::INSTANCE, which signals the end of the sequence (you can invoke #stop inside an iterator as a shortcut).
<FromGitter> <erdnaxeli:cervoi.se> yeah i know, I would expect cons_pair et cons(2) to give the same result
<FromGitter> <Blacksmoke16> its fixed in master
<FromGitter> <erdnaxeli:cervoi.se> cool!
<hightower4> Blacksmoke16 while the gitter proxy was down I asked here wasn't there your tutorial showing Athena + some ORM. For everyone's benefit, I found it in the meantime: https://dev.to/blacksmoke16/creating-a-json-api-with-athena--granite-510i
<FromGitter> <Blacksmoke16> πŸ‘
<FromGitter> <Blacksmoke16> needs updated but at this point im debating breaking it out into external docs as its quite long and changes too often to keep up with really :/
<FromGitter> <RespiteSage> Just fell for one of the Crystal Classic Blunders: `while foo argument && other_condition`
<FromGitter> <Blacksmoke16> rip
<FromGitter> <RespiteSage> It had been just long enough since I fell for it the last time that I wasn't looking out for it.
<oprypin> just use parentheses geez
<FromGitter> <RespiteSage> I mean, yeah. Not using parens was the blunder.
<hightower4> Hey, to run an idea here first. Often times, I do something like @x = Something.some_constructor(...), and then compiler says: "can't infer the type of instance variable ...". But as soon as Something is some non-built-in class, I often don't remember what the actual class will be. So...
<hightower4> So the trick I use is I insert a known-invalid type, like @x : Int32 = Something.some_constructor(...)
<hightower4> and by doing that I make the compiler tell me: instance variable '@db' of Abc must be Int32, not ( ClassInQuestion | Int32)
<FromGitter> <Blacksmoke16> got an example?
<FromGitter> <Blacksmoke16> but sounds like you should define the ivars outside of the constructor
<hightower4> So, since it knows what the type is (ClassInQuestion), why not suggest to the user that it may be this class?
<hightower4> here's an example:
<oprypin> hightower4, that some_consutrctor should have a type annotation
mps has left #crystal-lang [#crystal-lang]
<raz> oprypin: he complains about the error message not including what type it might be, tho
<hightower4> Yes, no, I am suggesting a better error msg... let me finish the example
<hightower4> yes
<raz> but why can it guess and suggest the type when a wrong type is provided, but not when none is provided? πŸ€”
<oprypin> raz, it can guess in both cases but chooses not to allow it
<hightower4> It's fine that it does not allow it. I am not asking for any change in behavior
<hightower4> I am asking just for printing/suggesting to the screen what the type is
<raz> +1 ^
<oprypin> hightower4, yea good feature request -- good github issue
<hightower4> Awesome! Will do
<hightower4> Just wanted to check here that I am not off the mark
<hightower4> I am looking at asterite's response. Did he misunderstand and think the issue asked for anything more but including the just-encountered type in error message text?
<hightower4> Or he's saying that these two errors (one without type, one with) happen at different stages, and the type is not known in the first stage?
<raz> no, i think he understands you but says the info isn't easily available in the problem case
<hightower4> right,
<hightower4> hm.. ok
<raz> it sounds like the compiler could "pretend" a type was provided and figure it out that way, but that's probably an extra step
<hightower4> Ah yes, yes, right
<hightower4> To pretend it was NoReturn
<hightower4> ok, got it
postmodern has joined #crystal-lang
Human_G33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
<hightower4> Hey Blacksmoke16, when using `assert` shard I got:
<hightower4> (actually ok, needed a 'update')
<FromGitter> <Blacksmoke16> That shard is deprecated as well in favor of the validator component
<FromGitter> <Blacksmoke16> As an FYI
<hightower4> ok, removed it
<FromGitter> <Blacksmoke16> https://github.com/athena-framework/validator this one is the one you want