ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.23.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
<oprypin> don't mess with uint either
<watzon> Why not?
<oprypin> just as much of a pain as that case with uint8
<oprypin> and has no advantage
<oprypin> and is more prone to overflows
<FromGitter> <bew> watzon: slightly simplified code: https://carc.in/#/r/2kgi (still using UInt8 though)
<FromGitter> <johnjansen> now thats much better
<FromGitter> <johnjansen> nothing wrong with UInt8 for that
<FromGitter> <johnjansen> its what it shouldbe
alex`` has quit [Ping timeout: 240 seconds]
<watzon> Yeah I like it
<watzon> Does anyone have a good example of a y-combinator in Crystal?
<FromGitter> <bew> what is it?
<watzon> Here's a Ruby example http://rosettacode.org/wiki/Y_combinator#Ruby
_whitelogger has joined #crystal-lang
<FromGitter> <bew> watzon: This is a port of the Go version to Crystal: https://carc.in/#/r/2kgw (disclamer: I have no idea what I'm doing)
<watzon> I love the disclaimer lol. Thanks bew
rohitpaulk has joined #crystal-lang
<FromGitter> <rufusroflpunch> is there a way to assign a splat argument to an instance variable? I would think that the compiler could infer the type since a splat creates a tuple, but it doesn't seem to
rohitpaulk has quit [Ping timeout: 248 seconds]
<FromGitter> <rufusroflpunch> if there isn't a way, is there some way I'm missing for a method to receive a tuple via a splat and store it for later use in a different method
<FromGitter> <bew> `@var = my_splat`?
<FromGitter> <johnjansen> what have you tried
rohitpaulk has joined #crystal-lang
<FromGitter> <rufusroflpunch> ``` def method(*args) ⏎ @args = args ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=59990b24578b44a046ca7035]
<FromGitter> <rufusroflpunch> this yields the long "can't infer the type of instance variable" message
<FromGitter> <rufusroflpunch> but it seems to me, since tuple are always known at compile time, that the compiler should be able to infer the type of the instance variable
<FromGitter> <mgarciaisaia> @rufusroflpunch I don't think it has to do with the splat, but with the fact that instance variables type's *have to* be explicitely declared
<FromGitter> <rufusroflpunch> @mgarciaisaia but that doesn't seem to be true. there are times when the compiler can infer the type (such as assigning an undeclared literal to an instance variable)
<FromGitter> <rufusroflpunch> sorry, I meant to say: (such as assigning a literal to an undeclared instance variable)
<FromGitter> <mgarciaisaia> Have you seen the full error message? It states the ~8 cases by which you can declare the type
<FromGitter> <mgarciaisaia> Your example would work if you [could?] declare the type of `args` in the method's signature
<FromGitter> <mgarciaisaia> I'm not even sure if that's doable with splats, but if you could do something like `def method(*args : Tuple(Int, String, MyThing))`, then it should compile I think
<FromGitter> <rufusroflpunch> yeah, I've seen it. I'm just curious about two points: 1) Why is this a case where the compiler can't determine the type for inference? Since a splat creates a tuple, it must, by definition, be known at compile time, so I would think that inference would be possible. 2) If I can't save a splat to an instance, is there some other way to capture that as state for later use?
<FromGitter> <mgarciaisaia> The underlying issue is that instance variables can change it's assignment at any point in time (your code could switch to a different fiber - let alone whenever we got concurrency working) so you need to specify and restrict its - if not, compile times were sooooooooooooo high
<FromGitter> <mgarciaisaia> There was a time in which Crystal didn't have this restriction (your code would have worked in, I don't know, Crystal 0.16? 0.18? don't recall), but adding it really simplified lots of stuff
<FromGitter> <rufusroflpunch> hrm
<FromGitter> <mgarciaisaia> I wasn't *that into* the team at that time, but I recall hearing some of the discussions about this
<FromGitter> <codenoid> please somebody make mongo driver for crystal
<FromGitter> <mgarciaisaia> @rufusroflpunch here's Ary explaining it *way* better than me: https://crystal-lang.org/2016/05/05/crystal-0.16.0-released.html
<FromGitter> <mgarciaisaia> @codenoid have you checked these? (I haven't) http://crystalshards.xyz/?filter=mongo
<FromGitter> <rufusroflpunch> @codenoid I believe there is a mongo driver: https://github.com/datanoise/mongo.cr
<FromGitter> <codenoid> it doesnt work
<FromGitter> <codenoid> all of it
<FromGitter> <mgarciaisaia> :/
<FromGitter> <rufusroflpunch> I would guess a mongo driver is no small task. the code for that driver alone looks fairly gnarly
<FromGitter> <rufusroflpunch> @mgarciaisaia thanks for that link. I actually remember that post now
<FromGitter> <rufusroflpunch> sort of ruins of my plans. lol. guess I'll need to be rethinking some things
_whitelogger has joined #crystal-lang
<FromGitter> <fridgerator> @codenoid mongo.cr was just updated 19 days ago
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
alex`` has joined #crystal-lang
<FromGitter> <fridgerator> the array is zero indexed, the first object is at `array[0]`
<FromGitter> <fridgerator> the last one is at `array[array.size -1]`, or just `array[-1]`
Philpax_ has joined #crystal-lang
Philpax has quit [Ping timeout: 240 seconds]
fenicks has quit [Quit: Leaving.]
fenicks has joined #crystal-lang
fenicks has quit [Ping timeout: 255 seconds]
<FromGitter> <cevarief> @fridgerator Why the output is different between 4,0 and 5,0. Both exceeds array.size - 1.
<FromGitter> <danlucraft> @cevarief that's a good question! I looked at the docs https://crystal-lang.org/api/0.23.1/Array.html#%5B%5D%28start%3AInt%2Ccount%3AInt%29-instance-method and guessed that it was because you can do array[4, -1] to count backwards from the end.... however the source code shows that this method doesn't accept negative arguments
<FromGitter> <danlucraft> @cevarief I deleted a message that was about me misreading the docs doh
<FromGitter> <danlucraft> it's a good question!
<FromGitter> <danlucraft> This is the same behaviour as Ruby.
<FromGitter> <danlucraft> But array[5] being Index out of bounds is NOT the same behaviour as Ruby
DTZUZO has quit [Ping timeout: 240 seconds]
<FromGitter> <cevarief> @danlucraft Yes, either it’s a bug or it’s on purpose. We don’t know yet why 😄
<FromGitter> <bew> At least it's consistent with the docs @codenoid https://crystal-lang.org/api/0.23.1/Array.html#%5B%5D%28start%3AInt%2Ccount%3AInt%29-instance-method
<FromGitter> <bew> But I agree, it's confusing and looks like a bug..
alex``` has joined #crystal-lang
DTZUZO has joined #crystal-lang
alex``` has quit [Quit: WeeChat 1.9]
<FromGitter> <sdogruyol> @fridgerator i did and it was not stable
<FromGitter> <sdogruyol> Morning everyone
<vegai> morning
<vegai> hey, I was just wondering if there's a mechanism for making a compile-time error
<vegai> I'm implementing a BigDecimal struct and would like to actively discourage people from instantiating a BigDecimal from a float
<FromGitter> <bararchy> What am I missing here ? ⏎ https://play.crystal-lang.org/#/r/2khy
<FromGitter> <bararchy> Morning @sdogruyol
<vegai> but have a nicer "no overload matches"
hightower3 has joined #crystal-lang
<vegai> nicer error message than*
<vegai> because initializing from a Float is probably an intuitive thing to do
<hightower3> Hey, if I have an abstract class with the implementation of method x(), and then I subclass that class, I see I can't call "super". How do I make it so that both the default implementation from the abstract class and my own custom addition gets executed then?
<vegai> ah, found something. Crystal::Macros.#raise
<FromGitter> <sdogruyol> @bararchy https://play.crystal-lang.org/#/r/2ki6
<FromGitter> <bararchy> WTF, why ?
<FromGitter> <sdogruyol> it's obvious
<FromGitter> <sdogruyol> your hash has either string or Hash(Symbol, Int32)
<vegai> mm, no idea how to use Crystal::Macros.raise though :P
<vegai> perhaps it would be a bit too defensive programming anyway
<FromGitter> <bew> vegai: `{% some_node.raise "error message" %}`
<FromGitter> <bew> or simply `{% raise "error message" %}` if you don't want the error to be applied on a specific node
<vegai> mm
<vegai> cool, that works. Thank you :)
<FromGitter> <bew> @bararchy, because `typeof(a[:verified]) # => Hash(Symbol, Int32) | String`
<FromGitter> <bararchy> Yeha, thanks @bew @sdogruyol , it makes sense, I just never got this in Hash context hahah , i had a moment of WTF lol
<FromGitter> <sdogruyol> yeah
<FromGitter> <bew> with named tuple, no errors: https://play.crystal-lang.org/#/r/2ki8, but it's maybe not applicable
<FromGitter> <sdogruyol> if your container is mutable and has more than one type inside you need casting
<vegai> I wonder if "to_big_d" is too funny a method name
<vegai> even though it's clearly in line with other to_* methods
<vegai> https://github.com/crystal-lang/crystal/compare/master...discord-tech:bigdecimal?expand=1 -- would anyone have energy to take a quick look at what I'm attempting
<vegai> which is trying to implement a BigDecimal type for arbitrary full precision decimals
<vegai> I suppose it's a bit more than halfway done, but would be nice to hear if it's a dumb idea :)
<vegai> btw, how can I make "make doc" generate docs for this library?
<FromGitter> <bew> ``It's implemented as a layer on top of `BigRational`.`` why?
<RX14> vegai, make a makefile which runs crystal doc?
<vegai> RX14: there's already a "make doc" target, but somehow, docs for my lib is not generated by it
<RX14> show me your makefile?
bmcginty has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> you should add your include in `src/big.cr` I think
<FromGitter> <bew> because `src/docs_main.cr` requires this file to populate docs
<RX14> vegai, oh wait are you modifing the compiler?
<vegai> bew: seems logical, since gmp doesn't have a bigdecimal itself, I think. It could be a BigInt too, though -- that's how people usually implement it I think
<vegai> RX14: no, just the std
<RX14> yeah sorry thats what i meant
<RX14> when you said "my lib"
<vegai> ah, sorry for the confusion
<RX14> it doesn't sound like you're modifying the stdlib
bmcginty has joined #crystal-lang
<vegai> bew: yeah, that did it. Thanks.
<vegai> if you're wondering about the motivation for this library, I'm mainly thinking about financial calculations
<vegai> where the loss of precision of floats isn't tolerated, and where BigRational's API may be too clunky
alibby1 has joined #crystal-lang
<oprypin> vegai, how does BigFloat not fit your needs?
<FromGitter> <codenoid> hi, i want to change word inside `str` with my words collection inside `LIB` https://play.crystal-lang.org/#/r/2kid
<Papierkorb> codenoid, see https://crystal-lang.org/api/0.23.1/String.html#gsub%28pattern%3ARegex%2Chash%3AHash%28String%2C_%29%7CNamedTuple%29-instance-method
<oprypin> hm what a strange method
<oprypin> seems like the regex part could've been avoided
<Papierkorb> a pure gsub(Hash) would be neat
<Papierkorb> Or at least auto-generated..
<oprypin> codenoid, i think this works https://play.crystal-lang.org/#/r/2kie
<FromGitter> <bew> @oprypin why not use `str.gsub(/\b\w+\b/, LIB)` ?
<Papierkorb> bew, not all words are set in `LIB`, so oprypin's code defaults to the original word for that
<FromGitter> <bew> oh I see, yes just tested it
<oprypin> this inflexibility is the main downfall of this method, well other than being trivial
<oprypin> i'd just remove it ¯\_(ツ)_/¯
<Papierkorb> Yes, if it's replaced by a pure gsub(Hash | NamedTuple)
<oprypin> but then you get the inflexibility of "to \b or not to \b"
<Papierkorb> I'd expect that function to replace matches anywhere, not only at boundaries
<oprypin> someone else would expect otherwise and get bitten
<Papierkorb> Thank god for documentation
<FromGitter> <bew> someone can try to write two backslash (not in inline code) from IRC?
<Papierkorb> The functionality is fine, the function is improvable
<Papierkorb> \\
<FromGitter> <bew> do you see 2 or one in IRC?
<FromGitter> <bew> I see one in gitter
<Papierkorb> IRC should see two
<Papierkorb> Wait a second \n bew, is this \n in a third \n actually fourth line?
<FromGitter> <bew> no, oneline, with `\n` written
<FromGitter> <bew> (so they're escaped)
<oprypin> Papierkorb, it's just markdown getting rendered on gitter side
<Papierkorb> So .. it just eats double \\ - Webapps are the future ~
<oprypin> expected behavior, basically
<Papierkorb> Why would you want to not print \\
<Papierkorb> using some run-of-the-mill markdown.js lib is no excuse
<FromGitter> <bew> yeah, who manager the IRC->Gitter bot?
<FromGitter> <bew> manage*
<oprypin> hi
<Papierkorb> it makes sense *for this*, but backslashes?
<oprypin> Papierkorb, it's just markdown, you can use \_ to write `_` then how do you write `\_`
<FromGitter> <bew> would be nice to escape the backslashes, to properly see the ¯_(ツ)_/¯ :D
<oprypin> it's not easy to escape markdown exactly the same as gitter expects it. not with standard library markdown parser.
<FromGitter> <bew> hum..
<Papierkorb> oprypin: I'd hope that their markdown parser is smart enough with _
<Papierkorb> Everything else is just broken
<oprypin> i don't see your point
<Papierkorb> _this_ can be used this_should_not and neither in ¯\_(ツ)_/¯ - Aka, if there's no space before it or no word-char after it, it's not meant to underline
<oprypin> so you mean to say that markdown in gitter is broken?
<oprypin> well yeah, that's just another reason i'm afraid of trying to replicate the brokenness
<FromGitter> <bew> ahah you broke gitter formatter: `not and neither in ¯\` is in italic
<Papierkorb> if it doesn't work like that, then that's broken
<FromGitter> <krypton97> sub is much faster than gsub
<vegai> oprypin: BigFloat has the same loss of precision
<oprypin> krypton97, so you're saying that doing one replacement is much faster than doing N replacements?
<FromGitter> <krypton97> is that what gsub does?
<vegai> oprypin: see https://carc.in/#/r/2kih
<FromGitter> <krypton97> I mean the multiple part
<oprypin> vegai, ok that explains it, thanks
<vegai> no problem :)
<FromGitter> <bew> yes @krypton97
<FromGitter> <bew> it replaces in the whole string
<FromGitter> <krypton97> Ok, so I ran this one wrk -d 60 -t 20 -c 1015 http://127.0.0.1:3000/ and got the following output
<FromGitter> <krypton97> accept: Too many open files (Errno) ⏎ 0x4130be: ??? at ?? ⏎ 0x4454fc: main at /home/alex/Documents/crystal-0.22.0-1/src/socket.cr 226:11 ⏎ 0x7f443d7f3671: __libc_start_main at ?? ⏎ 0x40e1fa: *start at ../sysdeps/x86*64/start.S 122:0 ... [https://gitter.im/crystal-lang/crystal?at=59996dceee5c9a4c5fdde845]
<FromGitter> <krypton97> Does it mean that it can't handle that many users?
<oprypin> hit the system limit for file descriptors?
<FromGitter> <krypton97> Hm, I ran the benchmark with 1015 concurrent connection
<FromGitter> <krypton97> that wouldnt be nice to happen in production
<FromGitter> <krypton97> nice
hightower3 has quit [Ping timeout: 240 seconds]
<oprypin> how do we index all these irc answers in a search engine :(
<Papierkorb> ?handle-limit
<oprypin> more like DedBot
<oprypin> no but i mean a search engine
<oprypin> forced stackoverflow posts?
<Papierkorb> not at all. will find more false positives than anything useful
<Papierkorb> if people knew what they're looking for, they wouldn't ask and just google it (well, most would)
<oprypin> that doesn't work when there's almost never an answer in google
<oprypin> maybe they do search for it and never find it and eventually give up
<Papierkorb> what? on file handles? There are billions, five of which are actually good
<FromGitter> <bew> oprypin, you're asking about where/how do we store the knowledge-base around crystal?
<oprypin> yes
<oprypin> Papierkorb, the person doesn't know that this is not crystal-specific, and the person knows that searching crystal-specific stuff doesnt work, so your argument doesnt work
rohitpaulk has quit [Ping timeout: 248 seconds]
<FromGitter> <bew> ok, wasn't sure. No idea though, SO answers would be best I think, but it means we'll need to write & answer a lot of questions before people will start using SO I think (I have no idea actually)
<Papierkorb> But it's a non-issue. IRC is there to answer questions, many of which are similar. building a bot which knows whats up with a really good hit rate is hard to get right.
<Papierkorb> Or rather, it has been a non-issue in my decade of IRC usage
<Papierkorb> That's why a simple `?` command is so helpful to guide people
<Papierkorb> Or whatever it's called
rohitpaulk has joined #crystal-lang
<FromGitter> <codenoid> thanks ^^ @oprypin @bew
<FromGitter> <codenoid> is `.fetch(s)` used for check *is value available on LIB * ?
<oprypin> see doc
<FromGitter> <codenoid> https://apidock.com/ruby/Hash/fetch
<FromGitter> <bararchy> It's interesting how many programmers don't recognize and know how to solve the `Too many open files` issue, unles Crystal is your first lang ofc :) or if you never made a server before Crystal ?
<FromGitter> <bew> Maybe it's because in Crystal everything 'looks' easy, you try bigger things than you're used too?
<FromGitter> <bararchy> IDK, it's really interesting, the first I hit the `too many open files` issue was when trying to convert a C# to work on MONO with Linux, the main programmer was not a Linux user and never used Linux before, so when we hit it I was like, maybe it's a mono issue ? and then started digging
<FromGitter> <bararchy> I have to say that if we can add `Too many open files (could be Sockets and other file type devices)` it could maybe help people avoid confusion ?
<FromGitter> <bararchy> Or something even more verbose ?
<FromGitter> <krypton97> just got this issue now lol
<oprypin> krypton97, that's the only reason why we're talking about it
<oprypin> bararchy, that does not change anything, people will still think it's about crystal
<FromGitter> <krypton97> take a look on rust, I find it much harder even than c
<FromGitter> <bararchy> Hm... Maybe `(Check you operating system limits for maximum files)`
<FromGitter> <krypton97> I know, saw this issue on github
<FromGitter> <krypton97> and a solution as well
<FromGitter> <bew> @bararchy @oprypin: thoses errors are `Errno` exception, and usually Errno errors are not crystal's, so we could add a prefix message saying that it's a system error, or sth?
<FromGitter> <bew> (not a crystal error)
<FromGitter> <bararchy> Good idea
<oprypin> errno should not be a thing in the first place and no, it being a system error does not necessarily mean it's something wrong with the system
<FromGitter> <bew> yeah I know, but it can help redirect users I think
<FromGitter> <bew> (need better phrasing of course)
<FromGitter> <bew> @codenoid We can't do anything about it I think, the person in charge of the shard will see your issue one day, and reply to you on it
<FromGitter> <bararchy> I saw a ticket regarding removing the Errno completly right ?
<FromGitter> <bararchy> what would be instead ?
<FromGitter> <bararchy> a system specific error ?
<FromGitter> <bararchy> Windows::Error....
<FromGitter> <bararchy> Unix::Error
<FromGitter> <bararchy> etc.. ?
<FromGitter> <bararchy> Because that will also be good enough I guess
<oprypin> bararchy, no, thats worse
rohitpaulk has quit [Ping timeout: 240 seconds]
<oprypin> but i guess what we have right now is in fact Unix Error just called Errno
<FromGitter> <bararchy> So in Python they are going to have `OSError` and everything error related to the OS there ?
<oprypin> nope, the opposite
<oprypin> i should've linked that in the first place
<FromGitter> <bew> that's interesting
<FromGitter> <bararchy> Isn't it's confusing to have both OSError & SystemError ?
rohitpaulk has joined #crystal-lang
<oprypin> probably not, seeing as i've never encountered a SystemError in my life
<FromGitter> <bararchy> What is under SystemError lol ?
<oprypin> Crystal equivalent would be something like this https://github.com/crystal-lang/crystal/issues/1079
<FromGitter> <bararchy> Oh lol
<FromGitter> <bararchy> hahah
<FromGitter> <bararchy> I see
<watzon> Holy $hit I just discovered something awesome :D
<FromGitter> <bararchy> How awsome ?
<watzon> For anyone coming from macOS to Linux http://linuxbrew.sh/
<watzon> Made my day haha
<watzon> Works the same as homebrew, but is cross platform linux
<oprypin> pls
<oprypin> if you're on centos maybe you'd want that
<watzon> Definitely makes installing some packages a little easier
<oprypin> in my experience you use this when you are on a distro that you hate
<oprypin> and i was in that situation once and did use it in fact but it's not very good
<FromGitter> <bew> watzon which distro are you on?
<FromGitter> <bararchy> pacman & yaourt is enough for me :)
<watzon> Manjaro, so I won't be using it a ton because I have the beauty of pacman and AUR
<watzon> But some AUR packages just don't get updated
<FromGitter> <bew> the update them x)
<oprypin> which packages, for example?
RelaxBox has joined #crystal-lang
<watzon> No example right now. I've run into several though in the past
<watzon> And sometimes I just don't feel like updating them
<watzon> I have in the past though
office_boy has joined #crystal-lang
<FromGitter> <krypton97> Knew about linuxbrew for a while but couldnt install it
<FromGitter> <krypton97> Is it the same as homebrew?
<oprypin> yes and no
<watzon> Basically. It's a fork and I feel like they may use the same bottles
<watzon> Not 100% sure on that one though
<oprypin> yes, and at any time you're prone to run into some mac specific hack and package fails to install
<FromGitter> <krypton97> oo, it worked
<office_boy> How would one go about using spec to capture output from `put` and test it? Like for Ruby you could do something like: `expect(STDOUT).to receive(:puts).with("RSpec test")`
<office_boy> `puts`*
<oprypin> office_boy, there's no easy way. you can make your code more testable and universal by not assuming stdout
<office_boy> alrighty
<oprypin> office_boy, dev_dependencies: https://github.com/mosop/stdio
<FromGitter> <codenoid> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=599984199acddb2407adf3b2]
<office_boy> Thanks a lot @oprypin, but what you said first does make more sense I guess
office_boy has quit [Remote host closed the connection]
office_boy has joined #crystal-lang
office_boy has quit [Read error: Connection reset by peer]
Groogy has joined #crystal-lang
<Groogy> Morning!
<FromGitter> <bew> 3p.m. morning! ;)
<Groogy> heh yeah, my day-rythm is super weird since my vacation
office_boy has joined #crystal-lang
<FromGitter> <bew> ahah have a good breakfast then!
office_boy has quit []
<FromGitter> <bararchy> @codenoid , I know I'm not the first to tell you, if you want people to try and help, you need to give more info then this :\ ⏎ What code produced this ? what allocations are you doing ? are there small loops that use those allocations ?
<FromGitter> <bararchy> etc..
fenicks has joined #crystal-lang
<FromGitter> <bew> is it possible to make a fiber that waits for a started process to finish without blocking other fibers?
<Groogy> well after everytime you check you yield?
<Groogy> though it depends on that other fibers also yield
<FromGitter> <bew> they do, but I think this will check a lot per second, I'd like to be kinda notified that the process closed
<crystal-gh> [crystal] MakeNowJust opened pull request #4861: Remove 1 item Expressions normalization (master...fix/crystal/remove-1-expression-normalize) https://git.io/v5ffa
<FromGitter> <bew> not having to check every 0.1 second if it's still running
<Groogy> well if there's some milliseconds delay
<Groogy> I hardly think that's going to be a problem? :P
<Groogy> but yeah if you yield everytime you have checked
<Groogy> it means you will do a check whenever another fiber is done working
<Groogy> ie. when it yields
<crystal-gh> [crystal] MakeNowJust closed pull request #4837: Implement exhaustiveness check (master...feature/crystal/exhaustiveness-check) https://git.io/v7Aux
<Groogy> so depending on workload of the other fibers you might be checking once a second, or even more less
<FromGitter> <bew> yeah I know, the thing is, I have 1 other fiber that does work every second
<FromGitter> <bew> and currently I check after the passed second if the process is still alive
<FromGitter> <bew> and if it's not, exit
<Papierkorb> Does that other fiber take 1s to compute though?
<FromGitter> <bew> no, it tkes a few ms
<Papierkorb> Then you shouldn't notice, especially not in a release build
<Papierkorb> debug builds are noticably slower when many fibers and channels are involved
<Groogy> the slowest part is probably gonna be the kernel call itself :D
<FromGitter> <bew> when I said "without blocking other fibers", I meant "without blocking the main tread" (like when I use `process.wait` inside that fiber)
<Papierkorb> ... that blocks the thread?
<FromGitter> <bew> huh wait a minute, I may have messed up sth else
<oprypin> its not supposed to block just use process.wait
<Papierkorb> huh, Concurrent::Future isn't documented
<oprypin> lol channel isnt documented
<FromGitter> <sdogruyol> As many others like parallel
<FromGitter> <sdogruyol> :)
<Papierkorb> oprypin: Channels doc is just "meh", concurrent::future doesn't even appear in the docs
<FromGitter> <bew> nvm, I've found my issue, I was doing input stuff into the other fiber, and noticed that `Process#wait` closes that io, so it's logic it wasn't working ><
<FromGitter> <bew> I love how crystal is readable: `until lemon.terminated?; sleep 0.1; end`
<Groogy> ^^
<Groogy> When I get boleite to a more usable case I'll be going through to make shit more readable
<Groogy> Though I do love I can just read the compiler code
<Groogy> there's no overuse of dumb macros or weird conventions like redefining enums for the sake of defining enums
<FromGitter> <bew> yeah it's awesome
<Groogy> (i.e in FreeImage library, there is literally a FI_ENUM define)
<Groogy> FI_ENUM(SomeEnum) => enum SomeEnum
<FromGitter> <bew> when you need to get your code more readable, I'd love to help. Readability (and modularity) is (maybe too much) king to me, and I like to transform code to my quality standard, it's a very rewarding process
<FromGitter> <bew> Groogy ^
<Groogy> ^^ thanks
John__ has joined #crystal-lang
RelaxBox has quit [Ping timeout: 240 seconds]
<crystal-gh> [crystal] MakeNowJust opened pull request #4862: Remove unnecessary parenthesis from `Cast#to_s` result (master...fix/crystal/cast-to-s-unnecessary-paren) https://git.io/v5fUV
<FromGitter> <krypton97> Has anyone worked with time package
<FromGitter> <krypton97> I'm looking for a format pattern that could generate me the date as 20 Aug 2017
<FromGitter> <bew> What did you tried?
<FromGitter> <krypton97> Basically, Time.now.to_s("pattern here")
<FromGitter> <krypton97> But I couldnt find such an pattern
<FromGitter> <bew> you can build your pattern with the directives described here: https://crystal-lang.org/api/0.23.1/Time/Format.html
RelaxBox has joined #crystal-lang
John__ has quit [Ping timeout: 240 seconds]
<crystal-gh> [crystal] asterite pushed 1 new commit to master: https://git.io/v5fUy
<crystal-gh> crystal/master 32d7e3e TSUYUSATO Kitsune: Parser: fixed #4608, correct to parse regex after close bracket
<FromGitter> <codenoid> i just want to share it @bew , it juts warning
<FromGitter> <bew> ?
<FromGitter> <codenoid> ups
<FromGitter> <codenoid> 2000 row + looping, with 500 row + looping inside the main loop,
RelaxBox has quit [Ping timeout: 255 seconds]
<FromGitter> <bararchy> So, I guess you know why the GC is crying hahah
<FromGitter> <codenoid> 😄
<Groogy> huh I totally forgot to check for OpenGL errors in my check error code
<travis-ci> crystal-lang/crystal#32d7e3e (master - Parser: fixed #4608, correct to parse regex after close bracket): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/266514518
<Groogy> gah there's a bug in the VS Code crystal plugin with tabs that pisses me off
<travis-ci> crystal-lang/crystal#32d7e3e (master - Parser: fixed #4608, correct to parse regex after close bracket): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/266514518
<Groogy> think it is when you have nested modules it gets the indents wrong with 1
<Papierkorb> ... I only use the nested notation. Yeah I can see how that's infuriating
<Groogy> especially when I do switch cases
<Groogy> and every when goes one less in indentation
<Groogy> but hmm maybe I should just use the nested notation
<Groogy> think that's gonna be better thanks
<Groogy> does that work for classes as well?
<Groogy> i.e class Boleite::Private::GLFWOpenGLShader; end;
<Groogy> ?
<Papierkorb> it does
<Groogy> noice
<Groogy> Guess I have bunch of refactoring to do
<Groogy> (•_•) ( •_•)>⌐■-■ (⌐■_■)
<FromGitter> <bew> ^^
undy1ng has quit [Ping timeout: 255 seconds]
<travis-ci> crystal-lang/crystal#32d7e3e (master - Parser: fixed #4608, correct to parse regex after close bracket): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/266514518
<Groogy> gah how do I properly translate this into a good exception message (the exception also prints out the actual OpenGL enum name)
<Groogy> "Given when the set of state for a command is not legal for the parameters given to that command. It is also given for commands where combinations of parameters define what the legal parameters are."
<FromGitter> <bew> oO
<Groogy> i.e it is let's say if you tell it this is a TEXTURE_2D in a parameter but what you actually gave it was a 3D texture
<oprypin> what
<Groogy> that's the description for GL_INVALID_OPERATION, and I need to turn that into something that fits into a short exception message
<Papierkorb> `Invalid argument(s) given`
<Papierkorb> that's super generic, but if it's all you know..
<Groogy> no that's GL_INVALID_ENUM and GL_INVALID_VALUE
<Groogy> GL_INVALID_OPERATION is more like invalid state
<Papierkorb> Then just write that?
<Papierkorb> "Invalid operation for state of object" or "The current state forbids this operation"
<FromGitter> <bew> what is the syntax to re-raise an exception again?
<Groogy> "when LibGL::INVALID_OPERATION; "A function called with invalid state or combination of parameters.""
<Groogy> ?
<FromGitter> <bew> can't find it in doc nor in sources
<RX14> just raise the exception you caught
<RX14> ...
<FromGitter> <bew> oh, indeed ><
<FromGitter> <bew> not mentioned in the docs though
<RX14> because it's obvious?
<Groogy> raising is in essence just "pushing an object up the stack to the next handler"
<Groogy> in the simplest term
<RX14> well more accurately it's searching up the stack for a handler
<Groogy> though I think Crystal requires it to inherit from Exception?
<FromGitter> <bew> yeah maybe, I vaguely remembered the PR for that, and only remembered there were multiple proposed syntax.. Perfect then
<RX14> yes
<RX14> thing is this isn't syntax
<FromGitter> <bew> you're right, what is it then? grammar?
<RX14> raise is a method
<Papierkorb> It's nothing special in reality
<RX14> the rescue ex : Foo is syntax
<Papierkorb> But it should be mentioned, as it may indeed not be obvious to a newcomer
<RX14> really? I guess literally all the languages i've used have done reraising that way
<RX14> i don't think re-raising is anything special at all
<FromGitter> <bew> it was in #4482, and multiple "grammar" were proposed (create new exception, and attach old trace, etc..).
<RX14> I don't think of it as anything more than catching an exception then passing it to raise again
<Papierkorb> RX14: in Ruby, it's just `raise` without any error
<Papierkorb> any argument*
<RX14> yeah well ruby's weird
<RX14> and i'm pretty sure you can do it the other way
<Papierkorb> that's the canonical way. The other way may (?) rewrite the backtrace.
<Papierkorb> In C++, it's just `throw;` too
<RX14> ruby
<Groogy> well ruby saves the exception in $!
<Groogy> so raise with nothing just reraises that exception
<Groogy> or at least that was the deal back when I used Ruby
<Papierkorb> So, no, it's not always "just throw the same thing again"
<RX14> i love ruby but i really don't think it's very sensible in some of the choices it made
<oprypin> RX14, in Python `raise` means reraise the same exception, and also Python keeps the chain of exceptions that led up to this point, and so these have a different effect
<RX14> i guess i'm the weird one
<Papierkorb> RX14: I'm baffled how against you're adding a little note in the *learning material* to avoid confusion
<RX14> i just din't think it was a big deal
<RX14> clearly i'm wrong
<Papierkorb> I mean, people may just try re-raising the same error but wonder if it's the right way. At least, that'd be me
<RX14> it should be added to the docs if all those languages do it differently
<Groogy> ugh renaming every single class in the framework xD
<FromGitter> <kazzkiq> I'm trying to return a `Int32`out of a `db.scalar`, but it seems to only return boolean values.
<Groogy> it had grown way bigger faster than I expected
<FromGitter> <bew> why renaming?
<FromGitter> <kazzkiq> e.g. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5999b637578b44a046cd04ac]
<Groogy> well I am replacing module Boleite; class SomeClass; end; end; with only a class Boleite::SomeClass; end;
<FromGitter> <bew> would be nice to have a tool to rename something
<Groogy> looks prettier and easier to read
<FromGitter> <bew> ah
<Groogy> especially the classes put in the module Private
<FromGitter> <bew> gl
<RX14> @kazzkiq db.scalar returns a union of all scalar types
<RX14> you'd need to case using .as() to get the one you want
<Groogy> yeah the error you are getting I am guessing is that it says the method you want to call doesn't exist in booleans
<Groogy> as long as all types in a union responds to something you can use it as if they were the same
<Groogy> otherwise do as RX14 and cast to the type you "know" it is
<RX14> no you have to cast
<RX14> it's booleans + all numbers there's no sane method which accepts both
<Groogy> no I know I was just explainging the underlying thingy
asterite has quit [Ping timeout: 246 seconds]
jhass has quit [Ping timeout: 240 seconds]
asterite has joined #crystal-lang
<RX14> am i going crazy? https://carc.in/#/r/2kjm
<RX14> oops
jhass has joined #crystal-lang
<Groogy> well timeout is a union of Timeval and nil
<Groogy> so it also generates code to create a pointer of an nil object
<RX14> no it's not
<FromGitter> <sdogruyol> what'd be the best way if an http connection is a websocket conn?
<RX14> because i literally just restricted it
<RX14> with the if
<Groogy> maybe a bug in the parser
<RX14> parser?
<RX14> no
<RX14> typechecker maybe
<Groogy> what's the question mark in the type?
sz0 has joined #crystal-lang
<RX14> you've never seen that before after being here for a month?
<RX14> it's a shortcut for LibC::Timeval | Nil
<Groogy> nope never seen that
<RX14> that's incredible
<RX14> it's everywhere
<FromGitter> <bew> RX14, in the second Call, try `Pointer(LibC::Timeval).null`
<RX14> the error doesn't point to that line
<RX14> and nil#to_unsafe is Pointer.null
<Groogy> yepp
<Groogy> so it is probably not that
<FromGitter> <bew> oh ok
<Groogy> it seems to somehow generate code for pointerof(nil)
<Groogy> or at least thinking it should
<Papierkorb> hows the `fun` declared?
<FromGitter> <bew> I already had issues with nil not beeing recognized as the correct pointer type, so
<RX14> Papierkorb, as taking LibC::Timeval*
<RX14> as expected
<Groogy> what is Timeval defined as?
<FromGitter> <bew> ` fun event_add(event : Event, timeout : LibC::Timeval*) : Int`
<Groogy> is it a opaque type or an alias?
<RX14> the first thing where I didn't use pointerof() was more to demonstrate that the compiler thought the type was LibC::Timeval
<Groogy> because type and pointers has caused tons of issues for me
<RX14> not LibC::Timeval | Nil
<RX14> Groogy, it's a struct
<Groogy> ah then it isn't that :/
<RX14> type should only be used for Void*
<RX14> we should probably enforce that
<RX14> it's only meant to be used for opaque pointers
<Groogy> also please resolve my issue ^^
<Groogy> so I can stop hacking around it
<RX14> and using it for anything else is using it wrong
<RX14> what issue
<Groogy> a second
<RX14> well it's not a high priority: just use nil
<Groogy> well if the result of a function is null it will not be nil
<Groogy> it will be a Pointer(Void).null
<RX14> i agree it should work as you say
<RX14> but why do you need it
<Groogy> no it would just make my code look prettier
<Groogy> rather than doing Pointer(Void).null.as(Test::T)
<RX14> why not use nil then
<RX14> instead of null
<RX14> use Test::T? and then assign nil in the finaliser
<Groogy> because then I have to check both .nil? and .null?
<RX14> why
<RX14> why would it become null
<Groogy> if a function returns null?
<FromGitter> <bew> Groogy a little prettier can be written as `nil.as(Test::T)`
<RX14> when would it return null
<RX14> and in that situation you'd always want to raise
<Groogy> a lib function
<Groogy> in C
<Groogy> returning null
<RX14> but you wouldn't do that
<RX14> in your example
<Groogy> no in my example it's a case of making sure subsystems shut down in correct order
<RX14> you'd never want a wrapper for a C object to contain a null reference
<Groogy> when the finalizer kicks in
<RX14> no i understand your answer
<RX14> and i'm saying
<RX14> for that usecase nil does better than null
DeBot has joined #crystal-lang
<RX14> and you should never assign a null pointer to @ptr
<Groogy> well in my specific code where I am using this, it is a surface that needs to be destroyed before the entire subsystem destroys the native representation of the surface. So the ptr needs to be reset so it doesn't keep pointing at it. If that would be made a union of Nil and Ptr then I have to check for nil in everything while the native implementation understands a null pointer and will behave correctly
<Groogy> to that
<RX14> but in your example you check for nil
<RX14> also if you're saying that the "native implementation understands a null pointer"
<RX14> you can just pass the ivar and nill will become null
<RX14> which it understands
<Groogy> no I can't
<Groogy> because of fun definition not taking a nil
<Groogy> types don't let you pass it
<RX14> no it takes a pointer
<Groogy> eh the lib type
<RX14> nil#to_unsafe is null
<RX14> which is where we started
<Groogy> yes but type doesn't care :P
<RX14> it works
<Groogy> the type keyword
<RX14> but we've established that nil is converted proeprly
<Groogy> it doesn't take a union
<Groogy> because the type doesn't respond to #to_unsafe
<RX14> but the union will be converted into the pointer, surely
<Groogy> no
<Groogy> it is a pointer
<RX14> Pointer#to_unsafe -> self
<Groogy> and a nil
<RX14> Nil#to_unsafe -> null
<RX14> have you tried it?
<Groogy> just tested it
<Groogy> doesn't work
<Groogy> argument 'window' of 'LibGLFW3#destroyWindow' must be LibGLFW3::Window, not (LibGLFW3::Window | Nil)
<Groogy> should say "still doesn't work"
<RX14> try calling to_unsafe manually
<FromGitter> <bew> can you carc.in your example?
<Groogy> lfw_surface.cr:11: undefined method 'to_unsafe' for Nil (compile-time type is (LibGLFW3::Window | Nil))
<Groogy> ¯\(°_o)/¯
<RX14> huh weird
<Groogy> I've been through this before
<FromGitter> <codenoid> mongo datanoise work fine with my vultr 16.04 0.23.1 :/
<Papierkorb> Sometimes, it also forgets that `lib` structs have an #initialize setting all fields. Wasn't able to pinpoint it yet, it just disappears later.
<Groogy> so guessing nil is just specially handled instead of creating a pointer? I guess since you would know the return type you would want
<Groogy> you would have to know*
<FromGitter> <bew> Groogy: this works: https://play.crystal-lang.org/#/r/2kkh
<Groogy> yeah
<Groogy> but it's not the same
<FromGitter> <bew> how?
<Groogy> because it doesn't become a union
<FromGitter> <bew> oh
<FromGitter> <bew> will you open an issue?
<Groogy> I did
<FromGitter> <bew> huh don't see it
<Groogy> well I was asking specifically for opaque types to have null method accessible there
<Groogy> to solve it
<FromGitter> <bew> ah yes this one ok
<Groogy> But it would also definetly solve everything if a pointer union together with nil would be resolved correctly with external functions
<RX14> well i think it should be
<RX14> i think this is an issue and your original issue is valid too
<FromGitter> <sdogruyol> "Automatically merges the code if approved"
<FromGitter> <akzhan> it is not the trouble
<Groogy> yeah though RX14 this did make me realize the original problem lies in the special case where it won't accept a union of pointers and nil
<FromGitter> <akzhan> memory consumption on compilation phase is it :)
<RX14> well
<RX14> there are two problems
<RX14> is all
<RX14> @sdogruyol i'm just annoyed that crystal's CI bot will never have a name that good
<FromGitter> <sdogruyol> I think we can do better
<FromGitter> <sdogruyol> can't deny bors though :D
<Groogy> We ccan use Steven Universe references
<Groogy> how is that not the best?
<FromGitter> <sdogruyol> meanwhile it's oss https://github.com/graydon/bors
<FromGitter> <bararchy> Is there a way to Timeout some functions ? Like ``` Timeout.timeout(5) do; sleep 10; end ```
<RX14> not really
<RX14> because there isn't a way to "stop" fibers
<RX14> you'd only be able to stop them when they next block *anyway*
<FromGitter> <bararchy> Doesn't libevent support some kind of Timeout ?
<FromGitter> <akzhan> @RX14 btw, what prevents to approve changes to change log ?)
<FromGitter> <akzhan> ===4854===
<RX14> @bararchy for IO actions, yes
<RX14> but thats exposed in IO::FileDescriptor
<RX14> only works for select
<RX14> which only works for channels
<FromGitter> <bararchy> Oh, I thought select should be avoided at all cost because it blocks the event loop
<RX14> no that's IO.select
<FromGitter> <bararchy> Or was it IO.select ?
<RX14> which was removed
<RX14> by me
<FromGitter> <bararchy> LOL , OK wasn't sure :)
<FromGitter> <bararchy> So select != IO.select
<RX14> yes
<RX14> select case works using select actions
<RX14> which are only implemented on channels so far
<RX14> IO.select worked on IO::FileDescriptor
<RX14> using the select syscall
<RX14> which was legacy from before we had libevent, most likely
<FromGitter> <bararchy> So , if I use a Chanel with Proc so that it will take each functions and call it inside a new Fiber , I can basically have a fully functional Timeout like mechanism
<oprypin> bararchy, i told you once before about your misconception regarding `select`
<RX14> @bararchy but you won't be able to create any sort of timeout because you won't be able to stop whatever you're doing after the timeout is up
<RX14> so it'll just keep running even though it's not needed
<FromGitter> <bararchy> oprypin , I remembered now , it was with @sdogruyol , I have such a nightmare from IO.select that it keeps coming like a PTSD haha
<FromGitter> <bararchy> RX14 I see , well then , I guess I should avoid those kind of things and just set IO timeouts instead
<RX14> if you're doing IO you use IO timeouts
<RX14> if you'renot doing IO you can't use IO timeouts
<RX14> i don't get what you'
<RX14> re trying to achieve
<FromGitter> <bararchy> I mean , I should plan my patterns around IO based timeouts (socket work) and not wrapping Timeout around functions that use IO inside
<FromGitter> <bew> I want to prevent a specific field from appearing when doing `pp obj`, how do I do this?
<FromGitter> <bew> I tried to look for the method used to pp a class, but couldn't find it
<RX14> @bew pp uses the pretty printer
DTZUZU has joined #crystal-lang
<FromGitter> <bew> where is the class instance pretty_printer?
<FromGitter> <bew> it's not in class.cr
<RX14> what?
<FromGitter> <bew> oh nvm, it's in reference.cr
<RX14> it'd never be in class.cr
<RX14> that's for metaclass
<RX14> the base impl is in object.cr
<RX14> and then reference and struct probably override that
<FromGitter> <bew> I've found it, thanks!
<Groogy> need to do my dishes... but I wanna code more Crystal (¯ε¯ )
<FromGitter> <bew> Crystal is addictive ^^
<crystal-gh> [crystal] maxfierke opened pull request #4863: Don't mark ivar as nilable if super present and non-nilable (fix #4764) (master...mf-fix_issue_4764) https://git.io/v5f3u
<RX14> is this a perfect PR from a first time contributor? That's awesome
<FromGitter> <bew> which one?
<RX14> #4764
<RX14> oops
<RX14> #4863
<DeBot> https://github.com/crystal-lang/crystal/pull/4863 (Don't mark ivar as nilable if super present and non-nilable (fix #4764))
<FromGitter> <bew> just saw it
<FromGitter> <sdogruyol> Wow amazing
<FromGitter> <sdogruyol> I wonder if it's first time Crystaling
<FromGitter> <danlucraft> @cevarief presumably array[too_big_index] is not nil like in Ruby because that would make the return value of [] a nullable type and it's more useful to have [] not ALWAYS return a nullable type
w-p has quit [Quit: Lost terminal]
<FromGitter> <bararchy> How can I rand a charset between a..z ?
<oprypin> bararchy, rand(a.ord, z.ord).chr
<oprypin> >> rand('a'.ord, 'z'.ord).chr
<DeBot> oprypin: wrong number of arguments for 'rand' (given 2, expected 0..1) - https://carc.in/#/r/2kkq
<FromGitter> <bararchy> Makes sense :) thanks
<oprypin> >> rand('a'.ord .. 'z'.ord).chr
<DeBot> oprypin: # => 'n' - https://carc.in/#/r/2kkr
<oprypin> ayy
Groogy has quit [Read error: Connection reset by peer]
<FromGitter> <bew> oh, I was going on `'a' + rand(26)`, but yours is better
Groogy has joined #crystal-lang
alex`` has quit [Quit: WeeChat 1.9]
<jokke> would there be any noticable performance gain if the to_s method generated by the ecr macros did more sophisticated stuff like calculating the length of the strings that will be inserted into the template for then allocating a string of the exact length of the substituted template and overwriting the relevant bytes in the template string?
<jokke> or would thet be something llvm would do anyways
<jokke> *that
<oprypin> no performance gain
<jokke> ok
<jokke> thought so
<jokke> i havent looked into how String#+ is implemented
<FromGitter> <bew> Is it possible to prevent a private member from being accessed when including the parent container? https://carc.in/#/r/2kl8
olbat has quit [Ping timeout: 264 seconds]
olbat has joined #crystal-lang
olbat has joined #crystal-lang
olbat has quit [Changing host]
<FromGitter> <johnjansen> huh ... i think you are out of luck there @bew
<FromGitter> <bew> Yeah that's what I think too.. although I'm not sure it's the behavior people are expecting
<FromGitter> <johnjansen> its composition, and totally by design, otherwise there would be alot you couldnt achieve with composition ...
<FromGitter> <johnjansen> you are effectively cutting and pasting the code when you do `include ModuleName`
<FromGitter> <johnjansen> *effectively*
<FromGitter> <bew> hum.. makes sense, thx
<Groogy> yeah I have a couple of internal structures etc in Boleite
<Groogy> I just put them inside another module called Private
xaxisx has joined #crystal-lang
olbat has quit [Ping timeout: 248 seconds]
olbat has joined #crystal-lang
olbat has joined #crystal-lang
olbat has quit [Changing host]