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
rohitpaulk has joined #crystal-lang
<FromGitter> <fridgerator> does anyone, on OSX is crystal linked to an old open ssl version?
<FromGitter> <fridgerator> I'm trying to send api request to stripe, and I get back `Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later`
<FromGitter> <fridgerator> ah yeah, system openssl version is 0.9.8zh
<FromGitter> <fridgerator> i'm guessing to use the brew version I would have to re-compile crystal?
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
bjz has joined #crystal-lang
<FromGitter> <picatz> I'd imagine something like that.
<FromGitter> <picatz> Not terribly sure though.
<FromGitter> <picatz> Is it true that Crystal doesn't have a shell escape method / something to do that?
rohitpaulk has quit [Ping timeout: 276 seconds]
hightower2 has joined #crystal-lang
hightower3 has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
<oprypin> picatz, i think so. why?
<FromGitter> <picatz> Was looking for something to be able to do that. I guess I was sort of surprised I wasn't able to.
<oprypin> picatz, I'm asking about your purpose of using such a method
<FromGitter> <picatz> Untrusted user input to run a command.
<oprypin> picatz, but why use a shell then?
<oprypin> you can run a command without being afraid of shell weirdness
<FromGitter> <picatz> Maybe I'm wrong here and don't know what I'm doing. But, if I were to take input from a user and then have it run as part of a shell command, shouldn't I shell escape the user input before running it?
<oprypin> picatz, likely you are wrong in calling something a shell command when really it's just a process accepting individual arguments
<oprypin> so can i finally get a concrete example of what command you're trying to run?
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter> <picatz> Well, for example: I had `puts `echo #{gets}``
<FromGitter> <picatz> the `'` being a backtick actually
<FromGitter> <picatz> I could run:
<FromGitter> <picatz> `echo 'test' | crystal test.cr` in my shell and see it puts "test" to the screen
<FromGitter> <picatz> `echo 'test; echo "lol"' | crystal test.cr ` would also end up working because of the `;`
<FromGitter> <picatz> So it will allow the second string "lol" to be run/ printed.
<FromGitter> <picatz> If I escaped the user input before running it, if I'm not mistaken, the actual input wouldn't allow that second `echo "lol"` to work.
<oprypin> Process.run("echo", ["test"])
<oprypin> Process.run("echo ${@}", ["test"], shell: true) if you really really for whatever reason need to run a shell builtin
<oprypin> I give up on the interrogation trying to find out what you want. trying to run echo huh
bjz has joined #crystal-lang
<FromGitter> <picatz> I'd just like to have some sort of peace of mind knowing I'm shell escaping stuff that'll be run in the shell for whatever reason.
<oprypin> so the task you were trying to do is getting peace of mind and you were trying to solve that by running an 'echo' shell command with escaped arguments. gotcha.
<FromGitter> <picatz> Well, it's an example task. It's still the case of any command.
<FromGitter> <picatz> Replace `echo` with `figlet` or `toilet` for example. A simple `;` allows random code execution where it probably shouldn't.
<oprypin> use the first example i showed. you never need to use a shell, nothing to escape
<FromGitter> <picatz> I guess I'm confused on how to get the output from the `Process.run` method of doing it.
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <codenoid> why i cant do this n kilt, `render "src/views/input/" + input[i] + ".ecr"`
<oprypin> picatz, one way i see is passing output: (out = IO::Memory.new)
<FromGitter> <codenoid> why i cant do this in kilt, ⏎ `render "src/views/input/" + input[i] + ".ecr"` ⏎ `render "src/views/input/#{input[i]}.ecr"`
<oprypin> could be forgetting some easier way
krigare[m] has joined #crystal-lang
<FromGitter> <picatz> Yeah, I really don't know how to work with that `Process` class/module whatever it is.
<FromGitter> <codenoid> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=597d59f5bc4647297438ce40]
<FromGitter> <codenoid> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=597d59fe329651f46ed4917c]
<FromGitter> <codenoid> lol, puts filename, returning view[i] xD
<FromGitter> <codenoid> btw what `{{ someval }}` used for ?
_whitelogger has joined #crystal-lang
<FromGitter> <jsilverMDX> how do I get around this again
<FromGitter> <jsilverMDX> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=597d6855f5b3458e3094470c]
<FromGitter> <jsilverMDX> mongo was working before
<FromGitter> <jsilverMDX> how do I get the libbson without the patch?
<FromGitter> <codenoid> ooo,, hmm kilt doesnt support dynamic source view
<FromGitter> <codenoid> :shipit: i cant use dynamic view
snsei has joined #crystal-lang
krigare[m] has quit [Ping timeout: 240 seconds]
krigare[m] has joined #crystal-lang
watzon has joined #crystal-lang
snsei has quit [Remote host closed the connection]
Philpax_ has joined #crystal-lang
hightower2 has quit [Ping timeout: 260 seconds]
watzon has quit [Remote host closed the connection]
hightower2 has joined #crystal-lang
<FromGitter> <Qwerp-Derp> Ummm... I'm not sure if this is a bug, but for some reason this errors on `line 21: can't define def inside def`: https://play.crystal-lang.org/#/r/2g0t
<FromGitter> <konovod> @Qwerp-Derp `else if` -> `elsif`
<oprypin> Qwerp-Derp, happens because `if` needs its `end` and `else` needs its `end`
<FromGitter> <Qwerp-Derp> Whoops, I confused `else if` again for some reason :P
<FromGitter> <Qwerp-Derp> Thanks @konovod!
<FromGitter> <Qwerp-Derp> I think I've got another error: https://play.crystal-lang.org/#/r/2g0w
<oprypin> Qwerp-Derp, yeah you assigned the type to the variable a
<oprypin> need .new or something
<FromGitter> <Qwerp-Derp> Why aren't multi-line comments supported?
<RX14> @Qwerp-Derp using single-line comments on every line is clearer
<FromGitter> <Qwerp-Derp> But I want to comment out a block of say, 20 lines
<FromGitter> <Qwerp-Derp> Or maybe more
<RX14> there should be a shortcut in your editor to do that
<RX14> @Qwerp-Derp in your example you forgot .new on line 58
<RX14> oh nvm oprypin said that
<FromGitter> <Qwerp-Derp> Oh, I fixed that
<FromGitter> <straight-shoota> Here are the thoughts behind not having block comments: https://github.com/crystal-lang/crystal/pull/1401#issuecomment-138290251
<RX14> thanks @straight-shoota
<RX14> maybe we should create a wiki page with a FAQ linking to these github comments
<RX14> as there are a lot over the years of asterite's opinions on things
<RX14> such as aliases, block comments, etc.
<FromGitter> <Qwerp-Derp> Hmm, alright
<RX14> would be nice to keep a FAQ page of them
<FromGitter> <straight-shoota> yeah, they're frequently asked
<FromGitter> <Qwerp-Derp> I made a short "proof-of-concept" thing for a recursive array (i.e. a data type `Foo(T)` that either takes `T` or `Foo(T)`): https://play.crystal-lang.org/#/r/2g1e
<FromGitter> <straight-shoota> actually, the FAQ page already lists some of these questions: https://github.com/crystal-lang/crystal/wiki/FAQ
<FromGitter> <straight-shoota> @Qwerp-Derp What is this for?
<FromGitter> <Qwerp-Derp> @straight-shoota I need it for a tokeniser that I'm going to use
<Yxhuvud> qwerp-derp: Have you looked at the type definition of JSON?
<FromGitter> <Qwerp-Derp> I want to make a PEG parser, but I'm already stuck on making a tokeniser :P
<FromGitter> <Qwerp-Derp> Crystal won't allow me to have arbitrarily nested arrays
<Yxhuvud> yes it does. alias X = String | Array(X); foo = Array(X)
<FromGitter> <Qwerp-Derp> I tried that, it doesn't do what I want it to do - I want it to support any configuration of `String`s and `Array`s
<Yxhuvud> errm. .. .new
<FromGitter> <Qwerp-Derp> For example, with `["abcd"]`, it doesn't work
<FromGitter> <Qwerp-Derp> Or `[["abcd"], "abcd"]`
<FromGitter> <Qwerp-Derp> Wait NVM
<FromGitter> <Qwerp-Derp> Why won't this work? `other : Array(X) = ["abcd", ["abcd"]]`
alibby1 has joined #crystal-lang
alibby has quit [Ping timeout: 248 seconds]
<Yxhuvud> because you are assigning an array to a class. makes no sense
<FromGitter> <Qwerp-Derp> Hmm that's weird, it didn't work before
<FromGitter> <Qwerp-Derp> Now it works
<FromGitter> <Qwerp-Derp> Thanks Yxhuvud!
<FromGitter> <sdogruyol> Hey everyone
<FromGitter> <bararchy> Hi @sdogruyol :)
rohitpaulk has joined #crystal-lang
DTZUZO has quit [Ping timeout: 260 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
<FromGitter> <Qwerp-Derp> Heyo @sdogruyol
<FromGitter> <alex-lairan> hi :)
<FromGitter> <straight-shoota> if someone's interested in searchable docs: https://straight-shoota.github.io/crystal/doc-search/ (based on #4746)
<crystal-gh> [crystal] MakeNowJust opened pull request #4760: Makefile: print LLVM version to stderr instead of stdout (master...fix/makefile/llvm-version-to-stderr) https://git.io/v7l8i
<FromGitter> <bararchy> Nice !!!
rohitpaulk has quit [Ping timeout: 260 seconds]
<FromGitter> <abidon> @straight-shoota Very nice !!! 👍
rohitpaulk has joined #crystal-lang
<hightower2> muy bien straight-shoota
rohitpaulk has quit [Ping timeout: 248 seconds]
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
hightower3 has joined #crystal-lang
bmcginty_ has quit [Ping timeout: 268 seconds]
hightower2 has quit [Ping timeout: 260 seconds]
bmcginty has joined #crystal-lang
Philpax_ has quit [Quit: Leaving]
Philpax has joined #crystal-lang
<FromGitter> <codenoid> ✨
<FromGitter> <alex-lairan> Any equivalent of ⏎ ⏎ ```std::pair<T, U>``` ⏎ ⏎ for crystal? :) [https://gitter.im/crystal-lang/crystal?at=597dd25df5b3458e30956a40]
<oprypin> {T, U}
<Groogy> If I want to convert a struct into a pointer of bytes, how do I accomplish that?
<Groogy> pointerof(struct).as(Pointer(Byte))?
<oprypin> pointerof(that).as(UInt8*)
<Groogy> alright
<Papierkorb> `pointerof(that).as(UInt8*).to_slice(sizeof(ThatType))`
<Groogy> yeah was just thinking should make it a slice
<FromGitter> <alex-lairan> thx oprypin, I will try :)
<FromGitter> <faustinoaq> @straight-shoota Awesome ✨
rohitpaulk has quit [Ping timeout: 240 seconds]
<Groogy> if I need a pointer to the data in an array, how do I access that?
<oprypin> Groogy, arr.to_unsafe
<oprypin> `+ i` as needed
<Groogy> thx
_whitelogger has joined #crystal-lang
rohitpaulk has joined #crystal-lang
<FromGitter> <straight-shoota> @faustinoaq great. I didn't even know wiki pages can be edited by everyone :D
<FromGitter> <straight-shoota> Though I don't see much sense in linking to the gitter comment. It's just one simple statement that's already in the FAQ answer. If I click on the link, I would expect more detail or context which is not there
<oprypin> agree
alibby1 has quit [Read error: No route to host]
alibby has joined #crystal-lang
bjz_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
rohitpaulk has joined #crystal-lang
<FromGitter> <picatz> So I've run across this a few times recently: `undefined method '+' for Nil (compile-time type is (Int32 | Nil))`
<RX14> @picatz that means the left hand side of your addition expression could be nil
<RX14> if you have code i could probably explain it much more clearly
<FromGitter> <picatz> I guess I expect it to be 1
<FromGitter> <picatz> not 2
<FromGitter> <picatz> but ya' know
<FromGitter> <picatz> I'm working on a little command-line application library thing for fun. Getting the index of an argument off of ARGV gives me a `Int32 | Nil` type which makes sense.
<Papierkorb> picatz, `ARGV` is without the binary name. So the first argument passed to the program is the first item in there
<Papierkorb> picatz, consider the case there is no "example" anywhere in ARGV.
<FromGitter> <picatz> But, I can add to `ARGV` after I run the application, correct?
<FromGitter> <picatz> I understand that the type is going to be `Int32 | Nil` because it may not be there, so the type must be both.
<FromGitter> <picatz> But, I can't add to this type, though I sort'of expect that I should be able to do so. But, I guess I don't know enough about how the types work. But, if a type is at least "partially" `Int32`, I'd like to think I could add to it, if it makes sense to do so. But, I guess becuase of the `Nil` part, I can't.
<oprypin> well that's a mouthful
<FromGitter> <picatz> I guess what I'm getting at is that I'd like to be able to use the `+ 1` to a `Int32 | Nil` type. Though I don't entirely understand any sort of impacts / ramifications to that.
<Papierkorb> `nil + 5` doesn't sound too useful. dangerous actually.
<oprypin> picatz, well what if it is nil, what then?
<oprypin> if you did write `nil + 1`, how could it possibly work, if there's no such method?
<oprypin> and if you do the same with a union, it still cant work like that without such a method existing
<oprypin> i see that you want to move the error to runtime. that would be `.as(Int32)` or `.not_nil!`
<FromGitter> <picatz> Right. Which is also interesting about the error I'm seeing when grabbing something off of ARGV. I'd expect I could be able to add to that, but I can't for some reason. Maybe I'm totally missing something.
<oprypin> picatz, why do you think it has anything to do with ARGV?
<FromGitter> <picatz> It's totally possible I'm very confused here.
<oprypin> it's just the result of the .index method which is either a number or nil if nothing is found
<FromGitter> <picatz> https://i.imgur.com/3RhDTM4.png
<oprypin> pls no icr
<FromGitter> <picatz> :( I like REPLs
<FromGitter> <picatz> Maybe it's causing the issue?
<oprypin> apparently not but one day it might and you wouldn't know
<FromGitter> <picatz> Does the screen shot help illustrate why I'm so confused, or not?
<oprypin> yes
<FromGitter> <picatz> Ok, that's good.
<FromGitter> <picatz> And, in theory, how I'm using `ARGV.index` should work, right?
<oprypin> sure, why not, and it does work
<oprypin> picatz, how do you like this screenshot tho https://i.imgur.com/teCtSFm.png
<oprypin> when you do assignment, the possible type of the variable is always reset
<FromGitter> <picatz> All I want to work is the `ARGV.index` result to be able to have the `+` work.
<FromGitter> <picatz> I guess I'm confused, because, doesn't that example show that it doesn't work?
<oprypin> not only does `i = Int32 | Nil` has no effect after the next assignment overwrites it, it's also nonsense because you're storing a type in a variable
<oprypin> picatz, ok consider this. `ARGV << "blah"; i = ARGV.index("example"); i + 1` - what do you expect to happen?
<FromGitter> <picatz> Honestly, it's a bit confusing to me to grasp ( probably quite obviously ). I guess I'd expect it to not work, because "example" won't have a index.
<oprypin> picatz, define "not work"
<oprypin> because the compiler defines it as a compilation error
<oprypin> whether it actually has or doesn't have an index is not important. what's important is you're calling a method that doesn't exist.
<FromGitter> <picatz> Ok, that makes a bit more sense.
<FromGitter> <picatz> Of course, still a bit confusing. But, it makes more sense. Stuff like the `i = Int32 | Nil` then it just being `Int32` after `i = 0`, if I'm not mistaken.
<oprypin> so use crystal play, not icr
<Papierkorb> picatz. you see that your `i` is of `Int32 | Nil`, so either one of those - Which one, we can't know at compile time - So we have to accomodate for both at run-time! Now, if i is nil, then what should happen when you do`nil + 1`? Should it be `1` or `0` or a completely useless `NullPointerException` known from other languages? Neither of these make universal sense. In fact, Crystal enforces that you check what you have. So, you can't do
<Papierkorb> `nil + 1` - But you can check, at runtime, what you got. E.g., through an if `if i` (yes, just that). What you do isn't that important, what is important is that you only reach a code path for which all methods are defined (etc.). So, `raise "not found" if i.nil?` works too, as the code following it will not be reached if i is nil, so after that, the compiler knows that i can never be `Nil`, hence its type now becomes `Int32`, and on
<Papierkorb> there you can use + or whatever you want
<FromGitter> <picatz> I appreciate the explanation! :D
<FromGitter> <picatz> From both you of.
<FromGitter> <picatz> @oprypin Bruh, command-line REPLs make me feel 1337.
dexter1 has joined #crystal-lang
dexter1 is now known as DTZUZO
<FromGitter> <picatz> Though I may start using crystal play some more, becuase of your recommendation.
<Papierkorb> The el-cheapo solution is `Object#not_nil!` though: `i = ARGV.index("foo").not_nil!` <- not_nil! raises an exception if it's called on nil. So now, the compiler knows that `i` will always be a `Int32`, and you can go on. Only use #not_nil! if something should not be nil in any case, making it kinda a fatal error in your program if it is nil
<Papierkorb> Well, or if you're hacking on something in `play`, makes the hacky code faster to write. As long you fix that later on not much wrong with it.
snsei has joined #crystal-lang
snsei has quit [Client Quit]
<FromGitter> <picatz> How insane would it be to consider `nil` as 0 for a `+`? Like, can someone walk me through some terrible case(s)?
<Papierkorb> Completely insane
<Papierkorb> That can quickly evolve into a subtle bug turning into a severe security issue
<Papierkorb> Look at your code. Even there, i = 1 in that case doesn't make any sense anymore. it's not pointing at what you intended, but at whatever.
<Papierkorb> If you don't care (for valid reasons), you can make i default to 0. That way, this case is handled correctly and explicitly for the next guy reading it.
snsei has joined #crystal-lang
<FromGitter> <picatz> I'm also a bit curious why `nil` has a `.to_s` to get `""`?
<FromGitter> <picatz> Maybe it's probably silly, but it's like, oh, so nil can be an empty string. Or, it can be a "nothing" number `0` -- which is probably something I guess shouldn't be done / I don't really *have* to have that kind of thing.
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
<FromGitter> <picatz> I just consider adding nothing ( === `0`) to something, I should get something. Whatever something is.
<Papierkorb> nil is like floats NaN. it's nothing. 0 isn't nothing
<Papierkorb> 0 is a perfectly valid number
<Papierkorb> NaN is not a valid number, by its very definition, it's not even a number in the first place, so it can't be a valid number
Philpax has quit [Ping timeout: 258 seconds]
<Papierkorb> Nil#to_s is a kinda special case. Object#to_s returns a string representation of the object it is called on. We inherited from ruby that nothing represents itself as an empty string, as there is nothing to represent.
<Papierkorb> Though `"nil"` would've also been acceptable I guess.
<oprypin> everything must have to_s is a more relevant argument
<Papierkorb> It could raise an error
<Papierkorb> However, `nil + "foo"` is still invalid
<Papierkorb> as is `nil + nil`
<FromGitter> <picatz> I'd sort of expect `nil + "foo"` to be `"foo"`
<Papierkorb> it's not thankfully
<FromGitter> <picatz> 😅
<oprypin> picatz, you must watch https://www.destroyallsoftware.com/talks/wat though
<FromGitter> <picatz> I just finished watching it.
<Papierkorb> Oh in general, watch that. it's hilarious in its own right
<FromGitter> <abidon> Maybe I just missed something in the documentation but, is it possible to grab the IP address of the client in Kemal ?
<FromGitter> <picatz> @abidon I don't think that it's possible ( someone correct me ) : https://github.com/kemalcr/kemal/issues/319
<FromGitter> <straight-shoota> No, depends on #1722
<FromGitter> <straight-shoota> an easy workaround would be to put a remote proxy in front of kemal (this is generally a good idea) and let it set the remote IP as a header
<FromGitter> <straight-shoota> you can then simply access the header in kemal as `request.headers["X-Forwarded-For"]`
<FromGitter> <straight-shoota> nginx conf: `proxy_set_header X-Forwarded-For $remote_addr;`
<FromGitter> <abidon> You even saved me a google search by giving me the nginx conf :) Thanks !
<FromGitter> <picatz> He seems to live up to his name. 😹
<FromGitter> <straight-shoota> xD
<Groogy> oh though theif I need a pointer to a pointer of int8's, how do I accomplish that?
<oprypin> well i told you previously, wrapping that in pointerof() should work
<oprypin> put it in a variable then pointerof maybe
<Groogy> so a pointerof on a pointer?
<oprypin> ye
<FromGitter> <picatz> Pointer-ception?
<FromGitter> <picatz> The Chain Pointers?
<FromGitter> <picatz> Yo Dawg I heard you like pointers?
<Papierkorb> double pointers aren't that uncommon in C
<FromGitter> <picatz> I've never worked with pointers ( knowingly, at least ).
<FromGitter> <picatz> Or C for that matter.
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
<Papierkorb> Everything that is not a Value is a pointer to something under the hood
<FromGitter> <picatz> Sorry if I'm going back to that `Int32 | Nil` thing and that's annoying: but, if I had a type of `Int32 | Nil` could there be a method `.to_i` to get a `Int32` version, or is that not possible?
<oprypin> picatz, nil.to_i makes no sense. what are you actually trying to accomplish?
snsei has quit [Ping timeout: 240 seconds]
<Papierkorb> I'd prefer to have only `#to_s` as single (lazy) exception. "nothing" being empty string at least makes sense to some extend.
<Papierkorb> but again, zero isn't nothing, and it's not 'empty' either
<FromGitter> <picatz> I think I was just re-confusing myself.
<FromGitter> <picatz> Which I apologize for being annoying about 😟
<oprypin> picatz, crystal has tons of way to specify a default or force a runtime error, it's just that defaulting to a compile error is the best way to make you think of all possibilities instead of having a crash or some silent nonsense operation happening
snsei has joined #crystal-lang
<crystal-gh> [crystal] ysbaddaden closed pull request #4760: Makefile: print LLVM version to stderr instead of stdout (master...fix/makefile/llvm-version-to-stderr) https://git.io/v7l8i
bjz has joined #crystal-lang
<bmcginty> Is there a way to merge the definitions of two NamedTuple types from inside a macro? I've got a class that has it's own Config NamedTuple, and I want to merge it with the programs main Config NamedTuple.
<oprypin> probably but not easy, some kind of loop with checks
<Groogy> oprypin have you gotten the cube example in crsfml to work?
<oprypin> Groogy, well sure i did, why would i put it up otherwise
<Groogy> or wait no that uses fixed pipeline
<Groogy> trying to get it to work using vertex buffer objects but hmmm
<Groogy> fixed pipeline worked for me but that's only supported by older versions
<oprypin> isnt it like all backwards compatible
snsei has quit [Remote host closed the connection]
<oprypin> i have no idea about opengl, anyway
<Groogy> nah it disables the backwards compability if you turn on CORE context
snsei has joined #crystal-lang
<Groogy> and if I am gonna want to use newer shader features I'm gonna need to use a later version of OpenGL either way
<Groogy> just get a black screen with no error, so nothing wrong with the shader etc and so it feels like the data is just not uploaded as I expect it to
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
snsei has quit [Ping timeout: 276 seconds]
<bmcginty> oprypin: thanks.
<travis-ci> crystal-lang/crystal#9abbd40 (master - Makefile: print LLVM version to stderr instead of stdout): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/259121390
bjz has joined #crystal-lang
[spoiler] has quit [Quit: Cheers!]
[spoiler] has joined #crystal-lang
[spoiler] has quit [Client Quit]
<travis-ci> crystal-lang/crystal#9abbd40 (master - Makefile: print LLVM version to stderr instead of stdout): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/259121390
<travis-ci> crystal-lang/crystal#9abbd40 (master - Makefile: print LLVM version to stderr instead of stdout): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/259121390
[spoiler] has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Groogy has quit [Quit: WeeChat 1.9]
<FromGitter> <jsilverMDX> If anyone is having Mongo.cr problems on Ubuntu or Debian, I can help
<FromGitter> <jsilverMDX> and I have a package ready for xenial amd64
<FromGitter> <jsilverMDX> its obvious we need some way to patch stuff like APT from shards if you ask me
<FromGitter> <jsilverMDX> or provide a better version of stuff we use, to me it seems OS packagers can't be trusted
<FromGitter> <jsilverMDX> i had to actually edit a ubuntu package, that was a first
<oprypin> nope
bjz has joined #crystal-lang
<Papierkorb> Messing with the packages of a system is a big no no to me. Shipping your own outdated, bug ridden version is Windows level awfulness.
<Papierkorb> If people using an OS which ships with (some kind of) broken packages, let them deal with it. They can easily file a bug report with their distro manufacturer, or opt to install their own fixed version, which they then maintain themself. That's fine. But bundling a complex library in a shard for everyone? Please no.
<Papierkorb> Bad enough that many programs ship with often hilariously outdated OpenSSL libraries, which can't be updated by the user cause the programmer opted to static link it in
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
dom96 has quit [Changing host]
dom96 has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <bararchy> What's the syntax to rescue multiple errors in one statment ?
<FromGitter> <bararchy> rescue Errno::blabla, Errno:blabla2 wont rok
<Papierkorb> `rescue err : Errno | IOError`
rohitpaulk has joined #crystal-lang
<Papierkorb> bararchy
<hightower3> With Crystal, I do not need any equivalent of Node.js's "string_decoder", right? (https://nodejs.org/api/string_decoder.html)
<Papierkorb> ... what is that decoder supposed to do?
<hightower3> The description says "The string_decoder module provides an API for decoding Buffer objects into strings in a manner that preserves encoded multi-byte UTF-8 and UTF-16 characters"
<FromGitter> <bararchy> Thanks Papierkorb :)
<FromGitter> <bararchy> Is there a way to rescue specific errors under Errno ? ⏎ https://crystal-lang.org/api/0.20.4/Errno.html
<FromGitter> <straight-shoota> No you can only rescue Errno
<FromGitter> <straight-shoota> But then you can look at the value and reraise if you don't want to rescue
<FromGitter> <bararchy> Hm.... Ok, how do I get the value ? does it return an Int32 ?
<FromGitter> <bararchy> Or is there an e.value or something ?
<FromGitter> <bararchy> Ok looked at docs
<FromGitter> <bararchy> it has a cetrain vlue
<FromGitter> <bararchy> thanks :)
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
deep-book-gk_ has joined #crystal-lang
deep-book-gk_ has left #crystal-lang [#crystal-lang]
<w-p> Can someone please explain what I'm doing wrong / misunderstanding here? https://play.crystal-lang.org/#/r/2g4n
<FromGitter> <straight-shoota> as the error message says: `["a", "b", "c"]` is of type `Array(String)`
<FromGitter> <straight-shoota> but data accepts only values of type `JSON::Type` which does not include `Array(String)`
<w-p> Right. But the JSON::Type declaration includes 'Array(Type)' which recursively includes 'Array(String)'
<w-p> I thought that was the point of that type.
<w-p> Recursive union type.
<FromGitter> <straight-shoota> Yes that's it's purpose, but `Array(String)` is not `Array(Type)`
<w-p> I understand that the alias was expanded ala typeof(JSON::Type)
<Papierkorb> w-p: Crystal doesn't know in which context you're using the array. JSON::Type is an union which contains String, but many other types too, so the array has to know that. You can let it know though through the `of` keyword, like this: `["a", ..] of Json::Type`
<w-p> such that Array(Type) expanded to Array(Nil | Bool | String | etc...)
<FromGitter> <straight-shoota> `["a", "b", "c"] of JSON::Type` is a `JSON::Type`
<FromGitter> <straight-shoota> `Array(Nil | Bool | String | etc...)` is not `Array(String)`
<w-p> so `data[k] = v` where `v` is of type `String` works because the type matches one of those listed in the union type. but in my case, the type of the variable itself is `Array(String)` not `Array(JSON::Type)` - so there's no recursive type inference.
<Papierkorb> w-p: the context is not taken into account. it doesn't look how you want to use the array.
<FromGitter> <straight-shoota> If you're only reading values from the array afterwards, this is not a big deal because every item from an `Array(String)` will be a `JSON::Type`. But to an `Array(JSON::Type)` you could add values of any other `JSON::Type`. Like: `data["bar"].add(true)`. Now you'd be adding Bool to an Array of Strings!
<Papierkorb> Array(String) and Array(String | ...) are inherently different types, for the language, in memory, everywhere. They just happen to share part of the same name, that's about it
<w-p> got it. so, you need to be explicit - https://play.crystal-lang.org/#/r/2g4s
<FromGitter> <straight-shoota> exactly
<w-p> Ok. So, then why does `["a", true, 123] of JSON::Type` not work? If you parse a JSON string of the same, it's loaded fine as JSON::Any.
<w-p> I guess I need to read through the source more thoroughly.
<Papierkorb> w-p: Oh that one is quite .. err .. funny. JSON::Type contains Int64, and right now, numeric literals are *not* auto-casted. So you have to write `123i64` instead to get a Int64 literal. There's an open issue about this though
<w-p> ah ha. got it. `alias Type = Nil | Bool | Int32 | Int64 | Float32 | Float64 | String | Array(Type) | Hash(String, Type)` fixes that.
rohitpaulk has quit [Ping timeout: 240 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 258 seconds]
Groogy has joined #crystal-lang
Groogy has quit [Quit: WeeChat 1.9]
saadq has quit [Ping timeout: 276 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
saadq has joined #crystal-lang
saadq has quit [Ping timeout: 240 seconds]
saadq has joined #crystal-lang
bjz has joined #crystal-lang
deep-book-gk_ has joined #crystal-lang
deep-book-gk_ has left #crystal-lang [#crystal-lang]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei_ has joined #crystal-lang
snsei has quit [Ping timeout: 260 seconds]
snsei_ has quit [Remote host closed the connection]
snsei has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<hightower3> Heh, I get "Tuple too big" and looking into the code the limit seems to be 300 entries. My tuple has 413 :)
<FromGitter> <straight-shoota> Then make it smaller ^^
<hightower3> It's a list of some terminfo information, must be this size
<Papierkorb> No. use a struct or an array instead.
<FromGitter> <picatz> What are the benefits of using a tuple?
<hightower3> Used an array for the moment, for just this one list which is >300
<Papierkorb> Tuples are not meant to be used for large structures.
<FromGitter> <picatz> What kind of structures should I use a tuple for?
<Papierkorb> Tuples are not for storage (I count NamedTuples for that too), but for data passing
<Papierkorb> E.g., returning multiple values from a method
<FromGitter> <picatz> Interesting.
<FromGitter> <picatz> Thanks for the explanation 👍
<Papierkorb> And for immediate lists, as they're Enumerable and Indexable, like Array. E.g.: `{foo.size, bar.size}.max` to get the largest size, or `{foo1, foo2, foo3}.each(&.do_something)` to mirror the ruby idiom for the same thing.
<Papierkorb> This is much better than using an Array, as an Array is heap allocated, a Tuple is not. Even better, LLVM is very likely to optimize that immediate tuple away completely.
<FromGitter> <picatz> I do love me' some ruby idioms.
<Papierkorb> If you face such use-cases picatz, you're encouraged to use tuples as you see fit
<FromGitter> <picatz> I'll probably just use an Array simple because it's what comes to mind first.
rohitpaulk has joined #crystal-lang
<Papierkorb> waste of resources, increases stress on the garbage collector. irrelevant for much code, but highly relevant for hot-spots.
<FromGitter> <picatz> Hopefully I can find some use cases for Tuples that are appropriate to the feel for 'em and maybe use them correctly. Maybe :P
<Papierkorb> Also, using tuples in that case is just Crystal style.
<Papierkorb> Also, don't do something like this: `foo = unitialized Tuple(Int32, Int32); SomeLib.fill_foo(pointerof(foo))`. This can blow up real quick. You can't know the memory layout of a tuple, making your code inherently unsafe (Or in simpler words, bad)
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
sija[m] has quit [Ping timeout: 255 seconds]
MatrixTraveler[m has quit [Ping timeout: 255 seconds]
Lex[m] has quit [Ping timeout: 258 seconds]
werthen[m] has quit [Ping timeout: 240 seconds]
thelonelyghost has quit [Ping timeout: 240 seconds]
olbat[m] has quit [Ping timeout: 246 seconds]
krigare[m] has quit [Ping timeout: 264 seconds]
vegai has quit [Ping timeout: 255 seconds]
braidn[m] has quit [Ping timeout: 255 seconds]
jplatte has quit [Ping timeout: 276 seconds]
TheGillies has quit [Ping timeout: 276 seconds]
cyberarm has quit [Ping timeout: 260 seconds]
cyberarm has joined #crystal-lang
snsei has quit [Remote host closed the connection]
hightower3 has quit [Quit: Leaving]
olbat[m] has joined #crystal-lang
tzekid has quit [Remote host closed the connection]