ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.32.1 | 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
renich has joined #crystal-lang
<raz> hrmpf. i want to keep liking lucky. really do. but the verbosity is getting on my nerves.
<raz> ops, actions, queries, all in separate files. it's kinda good. but also nauseating.
<FromGitter> <Blacksmoke16> 😬
<FromGitter> <lbarasti> @tenebrousedge Relief! Defining the record outside the class - at the cost of having to make the record itself parametrised - does the trick. E.g. the following works ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e34c6bf15941335584b9cb8]
<FromGitter> <tenebrousedge> @lbarasti neat
<FromGitter> <lbarasti> even defining the record *inside* the class and with the type parameters works. OK, I'm going to bed. Night!
<FromGitter> <jgillich> Any way to check for `Nop` in a macro? I'd like to provide a nicer error message. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e34d89d594a0517c25d29cc]
<FromGitter> <jgillich> Any way to check for a `Nop` in a macro? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e34d8e0ea9ba00b84a4b697]
<FromGitter> <tenebrousedge> `nil` ?
<FromGitter> <tenebrousedge> or `Nil` since you want the type
<FromGitter> <tenebrousedge> ```def foo; end ⏎ typeof(foo()) #=> Nil``` [https://gitter.im/crystal-lang/crystal?at=5e34d96658f02e3497570f57]
alex`` has quit [Read error: Connection reset by peer]
alexherbo2 has quit [Read error: Connection reset by peer]
<FromGitter> <jgillich> Oh it's that simple, thanks!
alexherbo2 has joined #crystal-lang
<FromGitter> <jgillich> Hmm actually it doesn't seem to work. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e34da6af301780b835bcf62]
<FromGitter> <tenebrousedge> try `Nil`
<FromGitter> <jgillich> Already did, same result. :/
alex`` has joined #crystal-lang
<FromGitter> <jgillich> What works is just `{% raise '...' unless method.return_type %}`, not entirely sure why but oh well.
<FromGitter> <Blacksmoke16> .is_a? Nop
<FromGitter> <jgillich> Darn yes, that's the one :)
<FromGitter> <jgillich> Macros can get confusing at times
<FromGitter> <Blacksmoke16> :p
alex`` has quit [Quit: WeeChat 2.7]
alex` has joined #crystal-lang
alex` is now known as Guest78449
Guest78449 has quit [Client Quit]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
alexherbo2 has joined #crystal-lang
alexherbo2 has quit [Client Quit]
alexherbo2 has joined #crystal-lang
alex`` has joined #crystal-lang
alexherbo23 has joined #crystal-lang
alex`` has quit [Ping timeout: 265 seconds]
alexherbo2 has quit [Ping timeout: 268 seconds]
alexherbo23 is now known as alexherbo2
alex`` has joined #crystal-lang
renich has quit [Quit: renich]
<FromGitter> <rurounijones_gitlab> Is there a nice easy way I am missing to merge two hashes together where one has symbol keys and one has string keys
<FromGitter> <tenebrousedge> hash#merge can take a block argument
<FromGitter> <tenebrousedge> hmm, but that might not get you where you want
<FromGitter> <tenebrousedge> you might have to do `transform_keys(&.to_s)`
<FromGitter> <rurounijones_gitlab> Ah right, yeah that looks close'ish
_ht has quit [Ping timeout: 248 seconds]
DTZUZU has quit [Quit: WeeChat 2.7]
_ht has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
DTZUZU has joined #crystal-lang
Dreamer3 has joined #crystal-lang
fauno has quit [Ping timeout: 272 seconds]
<FromGitter> <rurounijones_gitlab> Probably basic question but I cannot figure this out ⏎ ⏎ How do I declare the first result so that I can reference it in the block and in the return ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e35863ad9895b17c3c5952c]
<FromGitter> <Blacksmoke16> result = nil
<FromGitter> <rurounijones_gitlab> won't that cause issues with having a union of tuple and the actual type
<FromGitter> <Blacksmoke16> Or could just not use the block, doing what the block does is easy enough
<FromGitter> <rurounijones_gitlab> tuple and Nil rather
<FromGitter> <Blacksmoke16> Compiler might be smart enough to know it gets overridden
<FromGitter> <rurounijones_gitlab> Yea, compiler is now complaining about casting Nil
<FromGitter> <Blacksmoke16> I'd just not use the block then
<FromGitter> <straight-shoota> The compiler doesn't know if the block is actually invoked.
<FromGitter> <straight-shoota> Because `yield` might be guarded by some condition
<FromGitter> <straight-shoota> If you know the block is certainly going to be invoked (as is the case with `Time.measure`), you could assign `result = nil` and later `return result.not_nil!`.
<FromGitter> <straight-shoota> That doesn't look very nice, though. So it's probably just easier to not use the yielding `Time.measure` and implement it's behaviour directly. It's really trivial. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e3589b7ea9ba00b84a626f4]
<FromGitter> <rurounijones_gitlab> Righto
OvermindDL1 has quit []
OvermindDL1 has joined #crystal-lang
<FromGitter> <rurounijones_gitlab> I saw a blog post about profiling crystal on mac OSX. Anyone done it on Linux?
<FromGitter> <tenebrousedge> it's about the same, usually
<FromGitter> <tenebrousedge> but writing good benchmarks is somewhat tricky
early has quit [Quit: Leaving]
early has joined #crystal-lang
sagax has quit [Remote host closed the connection]
duane has joined #crystal-lang
sagax has joined #crystal-lang
<FromGitter> <andrewc910> Is there a way to connect icr with a database? Something similar to rails console?
<FromGitter> <andrewc910> Or load up granite for orm queries?
<FromGitter> <Blacksmoke16> i doubt it
<FromGitter> <Blacksmoke16> could always just run a file thats like `pp User.find ...`
<FromGitter> <lbarasti> @rurounijones_gitlab I was looking into it last week, I couldn't find anything specific to crystal. Seems like the best shot is to use an LLVM profiling tool. Will let you know if I try one with success
<FromGitter> <tenebrousedge> @Blacksmoke16 icr allows you to require files, though. Couldn't you just require your user model, or some other bootstrap file, and go from there?
<FromGitter> <Blacksmoke16> i suppose? im just under the assumption icr isnt really good
<FromGitter> <Blacksmoke16> since it would have to recompile everything on every change
<FromGitter> <tenebrousedge> I think it has some sort of caching, but it does mean that time-based queries behave strangely
<FromGitter> <andrewc910> @Blacksmoke16 ill play around. Thanks
<FromGitter> <andrewc910> @tenebrousedge Thats what i am hoping. Just require my models folder and queries should work. ICR is building rn.
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8hsr
<FromGitter> <Blacksmoke16> probably related to some issue with virtual types since `Response` is not abstract
<FromGitter> <andrewc910> IT WORKS! Requiring models isn't the way to go. Requiring 'config/applicaion' loaded up amber, granite, and all the amber files. Works fine albeit a bit slow because each command requires all the files again
<FromGitter> <tenebrousedge> :plus1:
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8hsu reduced, only seems to happen when converting methods into procs
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8hsv works fine using `Proc.new`
<FromGitter> <tenebrousedge> pretty weird, @Blacksmoke16 ⏎ seems like a bug
<FromGitter> <Blacksmoke16> indeed, was able to work around it but kinda a pain
<FromGitter> <Blacksmoke16> ill make an issue for it
<FromGitter> <oren> any ideas how to create a CLI app with a similar interface? https://github.com/workshopper/javascripting#run-the-workshop
<FromGitter> <Blacksmoke16> in other news, Athena can now return ECR templates :p
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e35b939fe0e6f74e9f749ef]
<FromGitter> <Blacksmoke16> prob some fancy terminal stuff
<FromGitter> <Blacksmoke16> write background color and handle key press then rerender the view updating the selected item?
<FromGitter> <oren> @Blacksmoke16 are you talking to me? do you have any examples or something similar that can help me getting started? i am a crystal newb
<FromGitter> <Blacksmoke16> i do not sorry :/
<FromGitter> <oren> is it simple puts statements?
<FromGitter> <Blacksmoke16> tbh i have no idea, i dont know much about it
<FromGitter> <Blacksmoke16> that was just my guess :p
<FromGitter> <oren> maybe something like this? puts "#{"Javascripting".colorize(:white).on(:blue)}"
<FromGitter> <Blacksmoke16> maybe? would have to try it
<FromGitter> <oren> the question is how do i use the arrows to move between the options and how to listen to the enter key and pick on option
<FromGitter> <Blacksmoke16> the underlying code is probably listening for key presses and keeping track which option is currently "selected" and just changing the style of that item
<FromGitter> <Blacksmoke16> i.e. given an array of choices the first would be selected, pressing down arrow would make the 2nd item selected
<FromGitter> <Blacksmoke16> increment an index
<FromGitter> <oren> ok. so listen to up, down, and enter
<FromGitter> <oren> i also need to maintain state somewhere. each line represent a task and if you completed it, it shows 'complted'
<FromGitter> <oren> completed
<FromGitter> <Blacksmoke16> sounds right
<FromGitter> <oren> reading this https://crystal-lang.org/api/0.32.1/Colorize.html i can't see an example of using RGB for the background of the text. Am I blind?
<FromGitter> <oren> I only see for RGB applied for the text font. like this: puts "foo".colorize(Colorize::ColorRGB.new(0, 0, 255))
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.32.1/Colorize/Object.html#back(back:Color)-instance-method
<FromGitter> <oren> but not for the background
<FromGitter> <Blacksmoke16> they're defined on `Object`
DTZUZU2 has joined #crystal-lang
DTZUZU has quit [Ping timeout: 265 seconds]
<FromGitter> <oren> thank you!
<FromGitter> <oren> how did you find it? i want to be able to figure this out myself next time
<FromGitter> <Blacksmoke16> :shrug: just knew where to look?
<FromGitter> <Blacksmoke16> is a search box on the api docs as well
<FromGitter> <Blacksmoke16> doesnt seem to help much tho :p
DTZUZU2 has quit [Ping timeout: 265 seconds]
DTZUZU2 has joined #crystal-lang
DTZUZU2 has quit [Client Quit]
<FromGitter> <oren> i have a case statement that detects up arrow and down arrow. how do i tell 'gets' function to not wait for enter key?
<FromGitter> <oren> wow
<FromGitter> <oren> i just run crystal 2048.cr and it shows me crazy UI
<FromGitter> <Blacksmoke16> well there you go :p
<FromGitter> <oren> classes, modules omg
<FromGitter> <636f7374> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e35d522e8a83835590d737a]
<FromGitter> <636f7374> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e35d584594a0517c25f6758]
<FromGitter> <636f7374> kemal/src/kemal/log_handler.cr (https://github.com/kemalcr/kemal/blob/master/src/kemal/log_handler.cr) Some improvements?
<FromGitter> <636f7374> Crystal - Formatting pretty numbers for humans (https://crystal-lang.org/2019/05/08/formatting-pretty-numbers-for-humans.html) 🙂
<FromGitter> <Blacksmoke16> @straight-shoota does https://github.com/crystal-lang/crystal/issues/8213 need handled in the alpine image as well?
<FromGitter> <Blacksmoke16> building with `-Dpreview_mt` gives ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e35dc37433e1d40398d4f9f]
<FromGitter> <andrewc910> So how can an actual repl work for compiled languages? Icr recompiles after each command so it's pretty slow. How does C-repl solve this problem? I imagine compiling the one line and injecting the new asm into the previously compiled binary?
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <j8r> or reimplement the language as interpreted
<FromGitter> <andrewc910> Oh man that one sounds difficult
<FromGitter> <j8r> it seems Dart does it (not sure)
<jhass> Dart has a VM
<FromGitter> <j8r> there is a compiled mode, right?
<jhass> well I guess the binaries still ship a runtime that effectively runs a VM
<jhass> it's pretty impossible to implement the dynamic typing it has otherwise I think
<jhass> but there's surprisngly sparse documentation on all of that, yeah
<FromGitter> <j8r> There is "Ahead-of-time compiled" and "Native", but it may both reference to compiling to bytecodes and not to a binary
<FromGitter> <straight-shoota> @Blacksmoke16 Yeah, probably. But I won't bother about it right now. IIRC there's going to be a new release for bdwgc in not-so far future which will just solve this issue when it's applied in apk.
_ht has quit [Quit: _ht]
<FromGitter> <Blacksmoke16> Okey dokey
<FromGitter> <Blacksmoke16> would the `0.32.1` image be rebuilt after that then?
<FromGitter> <Blacksmoke16> otherwise it's just always going to be broken for MT
<FromGitter> <Blacksmoke16> or any other image built before it was released upstream
alex`` has quit [Quit: WeeChat 2.7]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
<FromGitter> <oren> how to detect that the enter key was pressed? i copy pasted from an example that had up and down but not enter. for example, 'up' was "\e[A", "w"
<FromGitter> <straight-shoota> > would the `0.32.1` image be rebuilt after that then? ⏎ ⏎ No. 0.32.1-alpine is based on alpine 3.11 and that should not change. Updated bdwgc would probably be in 3.12 but before that we're likely having a couple Crystal releases as well.
<FromGitter> <Blacksmoke16> :/
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <straight-shoota> As soon as the new bdwgc lands in edge, we might consider adding that, though
<FromGitter> <straight-shoota> You can install apk packages from different release branches
<FromGitter> <straight-shoota> Probably not in the official Dockerfile, but it would be a oneliner to add it in a custom one
<FromGitter> <Blacksmoke16> would be nice to apply the patch until that happens tho no, esp if its going to be a "few crystal version" away
<FromGitter> <straight-shoota> Using the package from edge is much easier than building it manually.
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <straight-shoota> And I suppose it's going to be in edge "soon"
<FromGitter> <straight-shoota> If I'm not mistaken, the word was bdwgc release might happen in the next weeks
<FromGitter> <oren> does anyone know how to detect enter key?
<FromGitter> <Blacksmoke16> try googling it?
<FromGitter> <tenebrousedge> > 13 (carriage return, CR, \r, ^M), moves the printing position to the start of the line, allowing overprinting. Used as the end of line marker in Classic Mac OS, OS-9, FLEX (and variants). A CR+LF pair is used by CP/M-80 and its derivatives including DOS and Windows, and by Application Layer protocols such as FTP, SMTP, and HTTP.
<FromGitter> <tenebrousedge> so enter should have the value 13
<FromGitter> <tenebrousedge> `13.chr #=> "\r"`
<FromGitter> <Blacksmoke16> ```when '\n' ⏎ :return``` [https://gitter.im/crystal-lang/crystal?at=5e35fc6e3aca1e4c5f5aee14]
<FromGitter> <Blacksmoke16> er `r`
<FromGitter> <Blacksmoke16> actually needs to be `when "\r"`
<FromGitter> <Blacksmoke16> since it'll come in as `String`
<FromGitter> <tenebrousedge> wait, is unix CR or LF?
<FromGitter> <tenebrousedge> it must be LF
* FromGitter * tenebrousedge can read, honest 🙄
<FromGitter> <oren> "\r" worked for me
<FromGitter> <oren> what kind of google search could have helped me?
<FromGitter> <tenebrousedge> googling control characters
<FromGitter> <tenebrousedge> it helps to understand the history of the ASCII character set
<FromGitter> <tenebrousedge> which dates back to the days of telegraphs
<FromGitter> <tenebrousedge> I'm not sure if I'm being sarcastic about how helpful this is
<FromGitter> <oren> i don't think this is the right place to find the answer. i assumed it's ruby or crystal related but i guess it's more generic
<FromGitter> <tenebrousedge> yup, we build on what came before
<FromGitter> <tenebrousedge> and character encodings predate digital computers
<FromGitter> <tenebrousedge> there's a long dry history article I'm trying to find
<FromGitter> <tenebrousedge> this might be it http://tronweb.super-nova.co.jp/characcodehist.html
<FromGitter> <oren> my question is where does it say that you need to capture `\r`?
<FromGitter> <tenebrousedge> > Keyboards also typically have a few single keys which produce control character codes. For example, the key labelled "Backspace" typically produces code 8, "Tab" code 9, "Enter" or "Return" code 13 (though some keyboards might produce code 10 for "Enter").
_whitelogger has joined #crystal-lang
DTZUZU has joined #crystal-lang
<FromGitter> <SamualLB> Hey everyone, wondering if somebody smarter than me can offer any help: https://stackoverflow.com/questions/60016478/how-to-implement-evented-io-for-c-libraries-ncurses-specifically