ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.34.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
ur5us has quit [Ping timeout: 246 seconds]
ur5us has joined #crystal-lang
rocx has quit [Quit: 👏 developers 👏 developers 👏 developers 👏 developers]
<FromGitter> <didactic-drunk> @Blacksmoke16 Or in place of a proc.
<FromGitter> <wontruefree> Is there a way to implicitly call a block in Crystal?
<FromGitter> <tenebrousedge> `yield`
<FromGitter> <watzon> You can use `block.call` as well
<FromGitter> <watzon> Blocks are just procs
<FromGitter> <tenebrousedge> that's more explicit though
<FromGitter> <watzon> Yeah, but sometimes necessary
<FromGitter> <watzon> For instance, you can't use yield inside of another block
<FromGitter> <Blacksmoke16> @didactic-drunk u think Lucky's logger lib does, but wouldn't really be hard to implement
ur5us has quit [Ping timeout: 265 seconds]
ur5us has joined #crystal-lang
<FromGitter> <watzon> Well this should be a fun project https://github.com/watzon/tomi
<FromGitter> <watzon> I have bitcoin wallet generation working, now it's time to add bitcoin derivatives
<FromGitter> <grkek> It popped up on my news feed, awesome work @watzon props to you
ur5us has quit [Ping timeout: 265 seconds]
_ht has joined #crystal-lang
_whitelogger has joined #crystal-lang
<FromGitter> <watzon> Thanks :)
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
flaviodesousa has joined #crystal-lang
flaviodesousa has quit [Client Quit]
<FromGitter> <naqvis> ```code paste, see link``` ⏎ ⏎ doesn't work and returns compilation error `Error: no overload matches 'bar' with type Proc(Bool)`, But if type annotation is removed in `bar`, it works. Why is that? is this a expected behavior? [https://gitter.im/crystal-lang/crystal?at=5ea29e183ea9b172a488376c]
<FromGitter> <grkek> You need to pass it a (Bool | Int32 | Float64)
<FromGitter> <naqvis> yeah, isn't that proc returning Bool?
<jhass> I think crystal currently is not smart about this, it needs to be literally the union
<jhass> You can do this so it's a little less ugly https://carc.in/#/r/8y0d
<FromGitter> <naqvis> thanks jhass
<FromGitter> <naqvis> but shouldn't this behavior be fixed?
<jhass> I'm sure there's a couple of open issues about it
<FromGitter> <naqvis> aahh
<FromGitter> <naqvis> then I won't be adding new mess then 😆
<jhass> priorities, time, motivation, not the easiest thing to do ;)
<FromGitter> <naqvis> agree
<FromGitter> <naqvis> for time-being i'll stick with `Proc::new` then
<jhass> can't really find anything, but related and explaining why it's hard: https://github.com/crystal-lang/crystal/issues/7306#issuecomment-453784876
<FromGitter> <naqvis> thank you jhass
<FromGitter> <stergiom> `def bar(f : Proc(FOO))` would work in this case?
<FromGitter> <naqvis> interesting
<FromGitter> <naqvis> thanks @stergiom
<FromGitter> <naqvis> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea2a32761a0002f7946dbd6]
<FromGitter> <naqvis> it works
<FromGitter> <stergiom> 👍
<FromGitter> <Zed-Inc> has anyone used ANSI escape codes before?
<jhass> I'm sure their creator did at least!
<FromGitter> <Zed-Inc> hahah
<jhass> just ask your question, don't look for an expert ;)
ur5us has joined #crystal-lang
<FromGitter> <xmonader> i'm trying to create a server using kemal ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ The idea i want to invoke the module with some path that i can use in the get hander [https://gitter.im/crystal-lang/crystal?at=5ea2b8a11eb8bd3978f0e854]
<FromGitter> <xmonader> but that doesn't seem to be ok when i try WikiServer::docspath = "mypath"
<FromGitter> <straight-shoota> `docspath` is a local variable, you can't access it from outside the module scope. You need a class variable for this, which can be declared using the `class_property` macro: `class_property docspath = ""`
<FromGitter> <straight-shoota> This exposes `docspath` and `docspath=` methods on the module. At callsite the syntax is `TfWiki::WikiServer.docspath = "..."`
<FromGitter> <c2akula> Hey guys, I'm a total beginner to Crystal. I program in C/C++/Go/Matlab mostly. I need help with converting a do..while loop construct in Pascal to an iterator based one in Crystal. I'm working through Goldberg's Genetic Algorithms book to learn the language. On pg.63 fig.3.5, the snippet of Pascal code is as follows: ⏎ ⏎ ```repeat (Find wheel slot) ⏎ j = j+1; ⏎ until (partsum >= rand) or
<FromGitter> <straight-shoota> Probably something like this should work: ⏎ ⏎ ```popsize.each do |j| ⏎ partsum += pop[j].fitness ⏎ break if partsum >= rand ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5ea2bf3e1eb8bd3978f0f8da]
<FromGitter> <straight-shoota> sry, `popsize.times` instead of `popsize.each`
<FromGitter> <straight-shoota> this is assuming j starts at 0
<FromGitter> <straight-shoota> That's an almost literal transformation. With knowing some more context, you might also be able to use `pop.each` for example
ur5us has quit [Ping timeout: 240 seconds]
zorp has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> @xmonader did @straight-shoota help with your issue?
<FromGitter> <ImAHopelessDev_gitlab> > I'm sure their creator did at least! ⏎ ⏎ ROFL
<FromGitter> <Zed-Inc> What do you guys use crystal for?
Andriamanitra has joined #crystal-lang
<FromGitter> <xmonader> @ImAHopelessDev_gitlab yes, but I converted it to a class already but i still get ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea2cf742bf9ef12699f554c]
<FromGitter> <Zed-Inc> hey @xmonader i noticed you have a couple nim repos
<FromGitter> <Zed-Inc> how do you find the language?
<FromGitter> <Zed-Inc> how would you compare it to crystal?
<FromGitter> <xmonader> i'm struggling a bit with the tooling compared to nim, language feels more polished and a smaller learning curve too :)
<FromGitter> <xmonader> I think my problem is because i'm trying to use that method inside of a get marcro in kemal? is that right
<FromGitter> <tenebrousedge> no, you're defining an instance method but trying to call it as a class method
<FromGitter> <tenebrousedge> `def self.send_from_dirsinfo(env, filename)`
<FromGitter> <xmonader> @tenebrousedge I tried without self as well :(
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#28b6308 (master - Add Path#each_part iterator (#9138)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/678991211
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9138 (Add Path#each_part iterator)
<FromGitter> <xmonader> @tenebrousedge fyi i tried same logic on just pure functions and it worked, probably the 'get' macro
<FromGitter> <xmonader> aha my bad indeed, but still can't figure it out :'(
<FromGitter> <tenebrousedge> `def self.send_from_dirsinfo(env, filename)`
<FromGitter> <xmonader> @tenebrousedge but then i can't use `@walker` in that code right?
<FromGitter> <tenebrousedge> no you'd have to use a class variable
<FromGitter> <xmonader> but why can't I use it as any normal instance method?
<FromGitter> <straight-shoota> Either you have your methods and variables on the class or on an instance of the class
<FromGitter> <straight-shoota> You can't mix
<FromGitter> <tenebrousedge> because you're not calling `new` anywhere
<FromGitter> <tenebrousedge> you don't have an instance
<FromGitter> <xmonader> in another file i do ⏎ ⏎ ``` s = WikiServer.new(docspath, w) ⏎ s.serve``` [https://gitter.im/crystal-lang/crystal?at=5ea2df7361a0002f794776b0]
<FromGitter> <straight-shoota> Somewhere you're calling `TfWiki::WikiServer.send_from_dirsinfo` which tries to call an instance method as a class method
<FromGitter> <tenebrousedge> that could be a thing too
<FromGitter> <straight-shoota> It's probably the call in the `get` handler. That code is in class scope
<FromGitter> <straight-shoota> To fix this you would need to get access to an instance of `WikiServer` inside the get handler
<FromGitter> <xmonader> so i can't have the routes defined in a class and using data from that class. got it
<FromGitter> <xmonader> will try to define another module to use and do include module
<FromGitter> <straight-shoota> Yeah, you should usually define the handlers on top level scope. It doesn't make any difference where that code is literally, but top level makes it easier to understand how it applies
<FromGitter> <straight-shoota> I'm not sure how including another module could help with that
<FromGitter> <xmonader> will make it globally for now and see. thank you guys so much it was driving me crazy
<FromGitter> <straight-shoota> You probably just need to make `s` (your `WikiServer` instance) accessible.
<FromGitter> <straight-shoota> if it's a local variable in top level scope, it should be as simple as `s.send_from_dirsinfo(env, filename)` in the get handler.
hightower2 has quit [Remote host closed the connection]
<FromGitter> <straight-shoota> (only works in the same file, though)
<FromGitter> <straight-shoota> Making it a class variable (like `WikiServer.instance`) would probably be better.
<FromGitter> <straight-shoota> This is assuming you actually want to share the same instance between handlers, which means it needs to be concurrency safe
<FromGitter> <xmonader> @straight-shoota my problem is the code is already just like that ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea2e28ff6a6e539797363c1]
<FromGitter> <xmonader> So my plan was I'd just pass the walker `w` to wikiserver and that w has all the info for the handlers to use
<FromGitter> <tenebrousedge> okay but `get` isn't an instance method
<FromGitter> <Blacksmoke16> im not sure how smart it is to use a class var to share state between requests
<FromGitter> <Blacksmoke16> unless that state is truly global, i.e. can be safely shared
<FromGitter> <xmonader> i'm not attached to kemal, i can use any other thing that's lightweight enough
<FromGitter> <Blacksmoke16> well that was a general thought not specific to kemal
<FromGitter> <grkek> Use Grip
<FromGitter> <grkek> it JUST WORKS(TM)
<FromGitter> <c2akula> @straight-shoota thanks for the reply. what kind of context would help? I tried doing something like `pop.each { |ind| partsum += ind.fitness if partsum < rand }, I don't think it's the same logic and the `until` loop.
<FromGitter> <straight-shoota> @c2akula Like what are the contents of the actual variables. Your logic isn't exactly the same but should have the same result. I'd suggest `break if partsum >= rand` though to stop entirely instead of skipping every iteration from now on.
<FromGitter> <tenebrousedge> `pop[0...popsize].reduce(0) {|m, e| break if m >= rand; m + e.fitness }`
<FromGitter> <straight-shoota> @xmonader Your problem is simply that the handler needs to have access to `WikiServer`. It doesn't execute in instance scope.
<FromGitter> <tenebrousedge> or you could use `take_while`
<FromGitter> <c2akula> @straight-shoota The Pascal code is returning the index of the item inside `pop` at the time of breaking out of the loop. It's a roulette wheel selection algorithm. The entire code listing is as follows: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea2e5b42bf9ef12699f98ea]
<FromGitter> <tenebrousedge> hmm
<FromGitter> <tenebrousedge> ``pop[0...popsize].each_with_index.reduce(0) {|m, (e, idx)| break idx if m >= rand; m + e.fitness }`
<FromGitter> <tenebrousedge> might need `each.with_index`
<FromGitter> <c2akula> @tenebrousedge If I'm understanding correctly, this snippet is iterating over each item in `pop` with its corresponding index, starting out with a memo (partsum) of `0` and returning `idx` from the block when `m>=rand`?
<FromGitter> <tenebrousedge> yes
<FromGitter> <straight-shoota> each_with_index + reduce is an option, but I'd probabaly go with this: ⏎ ⏎ ```popsize.times do |j| ⏎ partsum += pop[j].fitness ⏎ break j if partsum >= rand ⏎ end ``` ⏎ ⏎ Seems better readable [https://gitter.im/crystal-lang/crystal?at=5ea2e711afa1f51d4e19a1d7]
<FromGitter> <tenebrousedge> but is the partsum guaranteed to exceed `rand` ?
<FromGitter> <c2akula> @c2akula @tenebrousedge would you say the following is correct? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea2e763afa1f51d4e19a2d0]
<FromGitter> <straight-shoota> Also `pop[0...popsize]` creates a new array, `pop.each.take(popsize)` would probably be better.
<FromGitter> <xmonader> is there such thing as module variables? https://gist.github.com/xmonader/e791491b3e67d9fbd62e383cc2bed282
<FromGitter> <c2akula> @straight-shoota thanks, @straight-shoota makes sense.
<FromGitter> <xmonader> and i made the usage like that ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea2e78a1e3d5e20633fadee]
<FromGitter> <c2akula> @tenebrousedge yes not sure about guaranteed, but definitely can
<FromGitter> <straight-shoota> > but is the partsum guaranteed to exceed `rand` ? ⏎ ⏎ If no, it would just be `|| popsize` because the iterator returns nil.
<FromGitter> <Blacksmoke16> @xmonader https://crystal-lang.org/api/master/Object.html#class_getter(*names,&block)-macro
<FromGitter> <xmonader> I just moved everything to a module :'( @Blacksmoke16
<FromGitter> <Blacksmoke16> same thing
<FromGitter> <Blacksmoke16> could you not use https://crystal-lang.org/api/master/HTTP/StaticFileHandler.html ?
<FromGitter> <straight-shoota> > I just moved everything to a module ⏎ ⏎ Why? A class was probably already the right choice
<FromGitter> <tenebrousedge> how about: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea2e8461e3d5e20633fb0d4]
<FromGitter> <tenebrousedge> `each` is fine too though
<FromGitter> <c2akula> @c2akula `sumfitness` is the sum of the fitnesses of all the individuals in `pop`. `rand = random * sumfitness` is essentially just randomly spinning the roulette wheel. Since `partsum` is the sum of the fitness of each individual as well, we're just checking which happens earlier, either we add all the fitnesses, in which case we selected the last individual in `pop`, in the other case, we land on some
<FromGitter> ... individual.
<FromGitter> <xmonader> @Blacksmoke16 I've some rules to apply on the served file so i need to hook in the serving phase
<FromGitter> <straight-shoota> You need to look at this very closely to udnerstand what it's doing. My favourite is still https://gitter.im/crystal-lang/crystal?at=5ea2e711afa1f51d4e19a1d7
<FromGitter> <Blacksmoke16> @xmonader copy the handler and modify it to what you want to do?
<FromGitter> <Blacksmoke16> that seems like a better approach no?
<FromGitter> <xmonader> @straight-shoota but i won't be using any of class features and these handlers require broad scope? and if i can just use them with modules variables it'd be okay
<FromGitter> <straight-shoota> We schould probably make StaticFileHandler modular to make resusing for custom implementations easier
<FromGitter> <xmonader> @Blacksmoke16 isn't it based on the public/assets dir to use?
<FromGitter> <tenebrousedge> @c2akula can't you just take a random element from the array then?
<FromGitter> <Blacksmoke16> @xmonader you can specify the dir it should use
<FromGitter> <straight-shoota> @xmonader Module variables are class variables. They're called the same and work exactly the same way on any type, whether it's a module, class or struct.
<FromGitter> <c2akula> @tenebrousedge Would this compile down to something like the following? Seems like it's doing more work due to the `find`? I could be wrong, and with more individuals inside `pop`, the following might be doing more runtime checks. ⏎ ⏎ > each_with_index + reduce is an option, but I'd probabaly go with this: ⏎ > ```cr ⏎ > popsize.times do |j| ... [https://gitter.i
<FromGitter> ... m/crystal-lang/crystal?at=5ea2e9782bf9ef12699fa7a6]
<FromGitter> <tenebrousedge> ignore performance. Write something readable
<FromGitter> <c2akula> @tenebrousedge You can randomly select, but the reason for the roulette wheel selection is to give higher fitness individuals more chances at selection.
<FromGitter> <c2akula> @c2akula a random selection wouldn't give you that behavior
<FromGitter> <tenebrousedge> k
<FromGitter> <straight-shoota> performance wise, both approaches should probably be similar. I'm not sure, it depends on LLVM optimizaions. But it's nothing to worry about really.
<FromGitter> <xmonader> It seems to work now yaay!
<FromGitter> <c2akula> @straight-shoota Thanks. C/C++ world can mess with your thinking at times and not thinking in terms of performance can be hard work. :D
<FromGitter> <c2akula> @c2akula Thanks a lot, will try both the approaches and will get back :)
<FromGitter> <xmonader> @Blacksmoke16 that's not what i want, what i want whenever u ask for /afilename.md -> i get the unique afilename.md from the the dir i'm serving from after some preprocessing
<FromGitter> <xmonader> @tenebrousedge @straight-shoota @Blacksmoke16 thank you for all of the help ^_^ i'm sure i'll be back again with more questions
<FromGitter> <c2akula> @tenebrousedge thanks Kai
<FromGitter> <tenebrousedge> :plus1:
<FromGitter> <straight-shoota> @c2akula So what the algorithm does is essentially weigh the random chance of each individual based on its fitness. I suppose there's no trivial O(1) solution for this. But for repeated use, pop would need to be shuffled.
<FromGitter> <straight-shoota> (For the first use too obviously, but I'm not sure where the data comes from so it could already be in random order)
<FromGitter> <c2akula> @straight-shoota that's right. "shuffling" happens when `pop` is replaced with a new `pop` from the selected individuals, you generate new ones through the "recombination" and "mutation" operators.
<FromGitter> <c2akula> @straight-shoota In this case because each individual is essentially a bit-string, they are generated randomly.
Mikaela has joined #crystal-lang
hightower2 has joined #crystal-lang
<disruptek> decided to use nim for my premiere competitor. thanks for all your help!
<FromGitter> <j8r> disruptek why not contributing to an existing OSS one?
<FromGitter> <j8r> kdenlive or openshot
<FromGitter> <grkek> Guys I think I have the corona virus
<FromGitter> <grkek> and I might die
<FromGitter> <grkek> very soon
<FromGitter> <grkek> R.I.P me, all I wanted was a post apocalyptic earth
<FromGitter> <xmonader> is FileUtils.cp("srcdir/*", "destdir") valid to copy all files in srcdir? or i should do something like Dir.glob("*/**") ?
<FromGitter> <tenebrousedge> that looks like it should work
<FromGitter> <tenebrousedge> do you have `icr` ?
<FromGitter> <xmonader> what is icr?
<FromGitter> <j8r> @grkek G.R.I.P? was is a vision? I think yes
<FromGitter> <tenebrousedge> you can test those sort of questions
<FromGitter> <tenebrousedge> `icr` is a Crystal REPL, more or less
<FromGitter> <grkek> @j8r I honestly have a hard time breathing, because my shoulders hurt like a bitch
<FromGitter> <grkek> I will check my temperature now and will keep you guys updated
<FromGitter> <xmonader> @tenebrousedge where can i find that? do you mean the online playground?
<FromGitter> <tenebrousedge> https://github.com/crystal-community/icr
<FromGitter> <xmonader> I see thank you
<FromGitter> <j8r> @grkek All's gonna be fine, get some rest 🙏
<FromGitter> <grkek> I couldn't find the thing which measures my temperature
<FromGitter> <tenebrousedge> take some ibuprofen
<FromGitter> <straight-shoota> @xmonader `FileUtils.cp` doesn't understand shell expansions
<FromGitter> <grkek> I mean it doesn't even hurt it just feels uncomfortable
<FromGitter> <grkek> maybe its because I smoke cigs ?
<FromGitter> <tenebrousedge> are you coughing, feel hot?
<FromGitter> <grkek> no my chest hurts
<FromGitter> <tenebrousedge> then probably it's not COVID-19
<FromGitter> <grkek> and my shoulders
<FromGitter> <grkek> and when I breathe I feel weird things in my trachea
<FromGitter> <tenebrousedge> your doctor would advise you to quit smoking, or at least switch to vaping
<FromGitter> <grkek> I wont smoke anymore
<FromGitter> <grkek> fuck this
<FromGitter> <tenebrousedge> in the meantime a muscle relaxant would probably help
<FromGitter> <grkek> It might be because of my open window habit
<FromGitter> <tenebrousedge> with an analgesic if it doesn't do that normally
<FromGitter> <xmonader> okay looks like i found a bug ⏎ https://github.com/crystal-lang/crystal/blob/ccf46c095a7e10cb120d4d04c96333858be4aaa2/src/file_utils.cr#L110 ⏎ ⏎ cp_r will fail if ur dest exists .. which is legit [https://gitter.im/crystal-lang/crystal?at=5ea2f58e501f8f72a5005edc]
<FromGitter> <tenebrousedge> it should probably not do that, yeah
<FromGitter> <alehander92> @grkek stop smoking, man!
<FromGitter> <alehander92> and just call your doctor if you continue feeling bad, but don't worry
<FromGitter> <grkek> It's like a ton of smoke is stuck in my lungs and it just feels horrible
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#0741ee2 (master - Deprecate top-level fork (#9136)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/679061395
<DeBot> https://github.com/crystal-lang/crystal/pull/9136 (Deprecate top-level fork)
travis-ci has joined #crystal-lang
<travis-ci> crystal-lang/crystal#5cecc19 (master - Add -h short flag to spec runner (#9164)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/679063507
travis-ci has left #crystal-lang [#crystal-lang]
<DeBot> https://github.com/crystal-lang/crystal/pull/9164 (Add -h short flag to spec runner)
<FromGitter> <dweqv> Do we have ruby's `undump`, complementing `String#dump`, somewhere in the stdlib? Or is there another way to read/eval the escaped string back in resulting in the unescaped version?
<FromGitter> <tenebrousedge> doesn't look like it
<oz> What are the default sinks / levels for the new logger in 0.34? I'm updating an (old) program where I setup a `Log.for` in the shard's module, but it never logs anything. 😕
<FromGitter> <Blacksmoke16> idt there are any defaults atm
<FromGitter> <Blacksmoke16> would have to setup the backends and such you want
<FromGitter> <Blacksmoke16> might be able to just call `Log.setup_with_env`, also see https://github.com/crystal-lang/crystal/pull/9145
<oz> Thankms. It looks like my issue was from the source-thing. The doc is pointing to setup `Log.for "something"` but `setup_with_env` will ignore this source by default (at least in 0.34).
robacarp has joined #crystal-lang
<robacarp> oz: So, the stdlib Log module is pretty _library_ focused. It allows a bunch of disparate libraries to use a unified logging system, which is then subscribed to, silenced, etc by the final application.
<robacarp> In mosquito I had to add a line to the demo runner which subscribes to the messages the library is publishing: https://github.com/robacarp/mosquito/commit/bd4d646312fecebabaf34099b99384ff0d473213#diff-0f3b37e1d0af7f88f4ca7bcae34ec22aR3
<robacarp> By default, Log::IOBackend emits to stdout, which is the important (and kind of unexpected to me) part of that line
<FromGitter> <j8r> Is the name robacarp related to magicarp?
<FromGitter> <j8r> (to stay on the topic :D )
<oz> robacarp: indeed. In the end I used `setup_from_env` the update the builder to the log-level I want for the app [depending on some env. vars].
<oz> s/the update/to update/
<FromGitter> <straight-shoota> oz, yeah the default in 0.34.0 is to only log top level scope (that is is, not "." in the log source). This will change in 0.35.0 to log all sources by default.
<FromGitter> <straight-shoota> So that `Log.builder.bind "*", :info, Log::IOBackend.new` won't be necessary in the next release
<oz> I think it's a more sensible default.
<robacarp> @j8r I've had people ask me that many times, but I have honestly no idea what a magicarp is ...
<FromGitter> <j8r> haha
<robacarp> @straight-shoota, good to know. Log is a nicely done package either way, didn't mean to rag on the design. I appreciate all the design thought that went into it.
_ht has quit [Ping timeout: 240 seconds]
<oz> Same. In the end, I removed code. So 💯
_ht has joined #crystal-lang
<FromGitter> <watzon> @straight-shoota that makes me happy. I love the new Log design, but it's not all that intuitive right now.
<FromGitter> <grkek> So has anyone looked into the `io << a << b << c << d` being slower than `io.print("#{a} #{b} #{c} #{d}")`
<FromGitter> <grkek> ?
<FromGitter> <tenebrousedge> uh, that sounds totally normal
<FromGitter> <tenebrousedge> one method call should be faster than four, all other things being equal
<FromGitter> <grkek> Isn't interpolation slower?
<FromGitter> <tenebrousedge> it should be pretty irrelevant at that level but you can use stringbuilder if you really need to
<FromGitter> <watzon> Interpolation is actually one of the faster String building methods
<FromGitter> <watzon> Def faster than concatenation
<FromGitter> <watzon> I didn't know it was faster than IO streaming, but I can see how it would be
<FromGitter> <tenebrousedge> but at the same time, that should probably not be a limiting factor for your application
<FromGitter> <watzon> Likely not
<hightower2> I would use something from LibC.
<hightower2> (j/k :)
<FromGitter> <watzon> Lmao
<FromGitter> <grkek> I would write nand logic just to print faster
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 265 seconds]
<FromGitter> <straight-shoota> @grkek a series of `<<` needs to allocate a new string for every intermediate step. Interpolation allocates only once in the best case, i.e. when the resulting string length is < 64 bytes.
<FromGitter> <watzon> Hmm that's interesting. I didn't know about the byte limit. So each 64 byte block allocates a new String?
<hightower2> grkek maybe you were thinking of a.to_s(io); b.to_s(io); ...
<FromGitter> <grkek> We really need the tips and tricks for crystal
<FromGitter> <watzon> I'll start working on some ;) lol
<FromGitter> <straight-shoota> No, 64 bytes is just the default size of a string builder. If you append more strings, it needs to expand.
<FromGitter> <watzon> I am working on a pretty big project right now that I'm going to be using Crystal for
<FromGitter> <straight-shoota> But actually, IIRC there has been some performance improvement, so the interpolation actually sums up the individual string lenght before allocating, so it really just allocates once
<hightower2> I think it would be great if these "tips" were part of official docs. I think nothing would beat complete docs that threat individual subjects from the basics at the top to pro level at the bottom.
<hightower2> s/threat/treat/
<FromGitter> <watzon> That's pretty great. I like when something as convenient as interpolation is actually fast as well.
<FromGitter> <watzon> `String.build` is still faster than using individual concatenation operations, right? Or is it about the same?
<FromGitter> <grkek> Sounds like a wonderful idea
<FromGitter> <straight-shoota> `String.build` is definitely faster than concat because of the multiple allocation thing.
<FromGitter> <j8r> I'm struggling with the `&.` syntax, how can I make this working: https://carc.in/#/r/8y43
<FromGitter> <j8r> I think I miss parenthesis somehow
<FromGitter> <watzon> @j8r https://carc.in/#/r/8y46
<FromGitter> <j8r> ho thanks @watzon
<FromGitter> <watzon> Np haha. You're right, it's the parentheses.
<FromGitter> <c2akula> @straight-shoota @tenebrousedge Hey guys, how're you doing? So I went back and implemented both your versions of the `select` procedure along with some benchmarks. Here are the results along with the code. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Let me know what you think? I've tested their output and they are identical, indicating to me that they are doing the same thing. Thanks :)
<FromGitter> <tenebrousedge> semantically, I like using `find` for this
<FromGitter> <tenebrousedge> but whatever works
sz0 has joined #crystal-lang
sagax has quit [Ping timeout: 240 seconds]
<FromGitter> <c2akula> @tenebrousedge The following is the `#find` version. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Recently I read both the volumes of "Elegant Objects" by Yegor Bugayenko. His suggestion to use a declarative approach to code resonated with me. I believe the `#find` version fit that bill to the T. I can see where you are coming from. [https://gitter.im/crystal-lang/crystal?at=5ea324171eb8bd3978f242d9]
<FromGitter> <naqvis> i'm experiencing an interesting situation, where line below the one triggering exception is getting executed and run time generated exception is not what code raised, but something like `Unhandled exception: can't execute `baz = Dummy.new(foo)` `foo` has no type (Exception) ⏎ ⏎ pesudo-code like this ⏎ ⏎ ```foo = bar_which_can_raise_exception(params) ⏎ baz = Dummy.new(foo)```
<FromGitter> <naqvis> question is, why exception is not propagated above?
<FromGitter> <tenebrousedge> @c2akula interesting results. I'll check out the books
<FromGitter> <c2akula> @tenebrousedge no worries. thanks btw. laters!
<FromGitter> <kingsleyh> does anyone know if there is a way to not get all the deps when doing: shards build mything
<FromGitter> <grkek> why wouldn't you want all the deps?
<FromGitter> <Blacksmoke16> you mean like non dev deps?
<FromGitter> <kingsleyh> I'm building my app to check some things - and I don't want to wait for it to fetch an build all the deps each time - as non of the deps change
<FromGitter> <Blacksmoke16> try with shards master
<FromGitter> <kingsleyh> like it goes to the internet and fetches all the deps
<FromGitter> <rdsaba> hi
<FromGitter> <kingsleyh> I'm still on 0.8 for shards :(
<FromGitter> <Blacksmoke16> o/
<FromGitter> <kingsleyh> I'll have to u/g
<FromGitter> <user45789> hi
<FromGitter> <grkek> Hi
<FromGitter> <tenebrousedge> ho
<FromGitter> <grkek> Hi ho
<FromGitter> <grkek> Hi ho
<FromGitter> <user45789> crystal in quite amazing
<FromGitter> <Blacksmoke16> indeed
<FromGitter> <user45789> there a cool way to generate html files : https://pastebin.com/PsjrzG24
<FromGitter> <Blacksmoke16> there are some shards out there that add DSLs for creating HTML yes
<FromGitter> <Blacksmoke16> but whats the goal here? seems kinda silly to use crystal to make static HTML files when you could just create HTML itself
<FromGitter> <user45789> but you could do it real time
<FromGitter> <user45789> including stuff from a database
<FromGitter> <grkek> Heigh ho
<FromGitter> <user45789> and send the result trough the http crystal server
<FromGitter> <grkek> Heigh ho
<FromGitter> <grkek> use Grip
<FromGitter> <grkek> everything else is like
<FromGitter> <grkek> hard and sad
<FromGitter> <Blacksmoke16> 😐
<FromGitter> <grkek> :DDDD
<FromGitter> <grkek> jk obviously
<FromGitter> <user45789> indeed, just wanted to share my finding xD
<FromGitter> <user45789> also i tought it could be cool to include a free crystal youtube video course made by derek banas on the web page https://www.youtube.com/watch?v=DxFP-Wjqtsc
<FromGitter> <Blacksmoke16> prob not the best idea considering that the video is already 2 years old
<FromGitter> <Blacksmoke16> helpful? yes, but maintainable? no
<FromGitter> <Blacksmoke16> i.e. some of the examples probably wouldnt compile anymore
<oprypin> looks fine in that regard
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/pull/9073 would/will break the file one
<FromGitter> <user45789> ok, i did not know u right
<FromGitter> <Blacksmoke16> majority of it would be fine tho
<FromGitter> <Blacksmoke16> file thing is prob the only thing actually
<FromGitter> <user45789> http://www.newthinktank.com/2018/10/learn-crystal-one-video/ here is the transcript
<oprypin> thats so nice
<FromGitter> <Blacksmoke16> neat
zorp has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
zorp has joined #crystal-lang
ur5us has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> > but whats the goal here? seems kinda silly to use crystal to make static HTML files when you could just create HTML itself ⏎ ⏎ oh boy
<FromGitter> <watzon> I didn't know Derek did a Crystal video haha
<FromGitter> <watzon> Personally I like what Paul and Jeremy did with Lucky's HTML DSL, but that's not static content
<FromGitter> <asterite> about that benchmark before, `each.with_index` is slow because it allocates an iterator, but `each_with_index` is fast. That's probably all the mystery around that benchmark
<yxhuvud> OTOH, if the difference between them actually matters you are most probably measuring something that doesn't matter.
Dreamer3 has joined #crystal-lang
<oprypin> Stephie, is it time for event loop work on Windows yet? the prerequisite is there ;)
<Stephie> uhh
<Stephie> promise valid for, whenever i have time :/
<Stephie> i really have uni stuff going on till june
sagax has joined #crystal-lang
<oprypin> alright, do what you gotta do :>
sagax has quit [Remote host closed the connection]
sagax has joined #crystal-lang
<yxhuvud> Oh, you are not done with uni yet. Thought you had passed that by now
<FromGitter> <ImAHopelessDev_gitlab> i just realized how much i like how crystal's docs are structured
ur5us has quit [Quit: Leaving]
_ht has quit [Remote host closed the connection]
<FromGitter> <jwaldrip> Step one is live: https://new.crystalshards.org/
<FromGitter> <oliviahandoko> if I have an array of strings and I want to output a random string from that array, how should I approach this?
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Array.html#sample(n:Int,random=Random::DEFAULT)-instance-method
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Indexable.html#sample(random=Random::DEFAULT)-instance-method
<FromGitter> <Blacksmoke16> the latter
<FromGitter> <sardaukar> so er... how do you change the log level on the new Log ?
<FromGitter> <sardaukar> if I do `Log.level = Log::Severity::Debug` I get `undefined constant Log::Severity::Debug`
<FromGitter> <Blacksmoke16> :thinking:
<FromGitter> <Blacksmoke16> i assume you required `log`
<FromGitter> <sardaukar> yes
<FromGitter> <Blacksmoke16> hm
<FromGitter> <sardaukar> what am I missing? https://carc.in/#/r/8y6t
<FromGitter> <Blacksmoke16> ah
<FromGitter> <Blacksmoke16> can just do `Log.level = :debug`
<FromGitter> <Blacksmoke16> or `Log.level = ::Log::Severity::Debug`
<FromGitter> <sardaukar> aaah `::`
<FromGitter> <sardaukar> ok makes sense... ish
<FromGitter> <sardaukar> yes, because the new `Log` constant is distinct from `::Log` yes
<FromGitter> <sardaukar> ok
<FromGitter> <sardaukar> still no output if i set it to `:debug` and do a `Log.debug` https://carc.in/#/r/8y6x
<FromGitter> <Blacksmoke16> need to setup a backend
<FromGitter> <Blacksmoke16> https://carc.in/#/r/8y70
<FromGitter> <sardaukar> cool, thanks!
<FromGitter> <sardaukar> @Blacksmoke16 any idea what's going on here? https://carc.in/#/r/8y71
<FromGitter> <sardaukar> why is setting :debug fine, but setting a variable with a value of :debug blow up?
<FromGitter> <Blacksmoke16> prob related to how autocasting symbols works
<FromGitter> <sardaukar> this... sucks :D
<FromGitter> <sardaukar> very non-intuitive
<FromGitter> <Blacksmoke16> did you checkout that issue?
<FromGitter> <Blacksmoke16> it helps fix some of thjis
<FromGitter> <sardaukar> didn't read the whole thing, will do
<FromGitter> <sardaukar> still feel like not being able to use a var here is pretty weird
<FromGitter> <sardaukar> it's already weird that I can pass a literal Symbol to an overload that takes `level : Severity`
ur5us has joined #crystal-lang
<FromGitter> <straight-shoota> @sardaukar The symbol syntax is just a short cut and unfortunately only works when literals are used as method arguments. The full name would be `Log::Severity::Debug`. The compiler can autocast that literal based on the type restriction of the methdo definition. But it's impossible to know when it's assigned to an untyped local variable.
<FromGitter> <straight-shoota> You can make it work by adding a type restriction to the var: `level : Log::Severity = :debug`
woodruffw has quit [Ping timeout: 256 seconds]
<FromGitter> <sardaukar> @straight-shoota thanks, that makes sense
<FromGitter> <sardaukar> but what if I want it to be an assignment? `level : ::Log::Severity = options["--debug"].as(Bool) ? :verbose : :info`
<FromGitter> <sardaukar> ?
<FromGitter> <Blacksmoke16> At this point just don't use the symbols
<FromGitter> <sardaukar> I have it 'working' with ```if options["--debug"].as(Bool) ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5ea3766911ffed1268323678]
<FromGitter> <sardaukar> which feels wrong
<FromGitter> <Blacksmoke16> Can't just use setup from env method?
<FromGitter> <Blacksmoke16> And use env vars to configure it
<FromGitter> <sardaukar> this is supposed to be a CLI tool, asking users to setup the logger from the ENV is awkward
<FromGitter> <Blacksmoke16> Fair
<FromGitter> <sardaukar> I just have a `-d` or `--debug` CLI flag
<FromGitter> <Blacksmoke16> Makes sense
<FromGitter> <j8r> I think I'm mad haha
<FromGitter> <j8r> I have made an object that turn anything into an iterator
<FromGitter> <tenebrousedge> we're all mad here. I'm mad. You're mad
<FromGitter> <j8r> https://carc.in/#/r/8y7f
<FromGitter> <j8r> there are rough edges, but the idea is there
<FromGitter> <tenebrousedge> I don't think I understand this
<FromGitter> <j8r> oprypin gots me this idea, by mentioning having automatic iterators
<oprypin> what
<oprypin> oh channels. moving along
<FromGitter> <j8r> in a random PR, forgot what exactly, you mentioned automatic iterators.
<oprypin> yea i did
<FromGitter> <j8r> using channels is kind of cheating
<oprypin> yes
<FromGitter> <j8r> likely not as efficient as a proper iterator
<FromGitter> <j8r> Don't know, may be still useful
<oprypin> way too inefficient, s adly.
<FromGitter> <j8r> wait, I'm not sure I need 2 channels
<FromGitter> <j8r> it won't change much though
<FromGitter> <j8r> nvm
<FromGitter> <didactic-drunk> How would I detect ``` lib LibC; struct Passwd```?
<FromGitter> <j8r> hum, the auto iter seems faster...
<FromGitter> <j8r> very similar is more correct
<FromGitter> <j8r> My benchmark is wrong