ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.33.0 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <asterite> Blacksmoke16 you can use <=>. If they are not comparable you get nil
<oprypin> asterite, no, i think you get an exception? try `5 <=> "a"`
<oprypin> sorry, i mean comppilation error
sagax has quit [Remote host closed the connection]
<FromGitter> <sam0x17> so I was about to ask why crystal doesn't have generic methods but I think I realized why when I went to write the syntax -- the only thing that would make sense would be essentially the java/C++ template syntax which would look very uncrystal: ⏎ ⏎ ```def my_generic_method<T, U>(arg1, arg2) ⏎ ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e7d4ea39efda609e29df83f]
<FromGitter> <sam0x17> still, I'd use it if it were a thing, I often end up defining a one-method-module just to house a generic method
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 250 seconds]
DTZUZU2 has quit [Ping timeout: 256 seconds]
<FromGitter> <Blacksmoke16> yea exactly, so im kinda out of luck
<FromGitter> <Blacksmoke16> even if you do ⏎ ⏎ ```class Object ⏎ def <=>(other) ⏎ nil ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e7d513c08a2a012204acc38]
<FromGitter> <Blacksmoke16> ```class Object ⏎ def <=>(other) ⏎ nil ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e7d5141b05dc465027fa009]
<FromGitter> <Blacksmoke16> then complains about ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7d5155d783bb5a9d8e1ab0]
<FromGitter> <Blacksmoke16> either comparable would need to define non restricted comparison methods that default to `false`, or have them on object
DTZUZU2 has joined #crystal-lang
<FromGitter> <Blacksmoke16> @sam0x17 got an example?
<FromGitter> <sam0x17> it's bad for other reasons, but: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7d5412bf65703264df591d]
<FromGitter> <sam0x17> could be as simple as: ⏎ ⏎ ```def raises_error?<T> ⏎ ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e7d542f7b02667a722355c1]
<FromGitter> <Blacksmoke16> and the use case is like ⏎ ⏎ ```RaisesError(MyException).value? do ⏎ # Do stuff? ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e7d546528248e1cff37f9bb]
<FromGitter> <Blacksmoke16> @asterite should i make an issue about that `<=>` issue?
<FromGitter> <sam0x17> yeah but more intended for one line usage like `RaisesError(MyException) .value? { 448 / 0 }`
<FromGitter> <Blacksmoke16> hmm yea, i cant think of any other way to do it
<FromGitter> <sam0x17> I seem to generate things like that semi-frequently though
<FromGitter> <Blacksmoke16> i cant say i ever had the need :p
return0e_ has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
chachasmooth has quit [Ping timeout: 260 seconds]
chachasmooth has joined #crystal-lang
<FromGitter> <ImAHopelessDev_gitlab> Isn't the term "greater than" used in mathematics / numbers? How does it work in the context of structs?
<FromGitter> <ImAHopelessDev_gitlab> size of a object?
ur5us has quit [Ping timeout: 256 seconds]
<FromGitter> <sam0x17> well crystal allows operator overloading so it could be defined to mean anything for a particular struct
<FromGitter> <sam0x17> but usually this would happen if you want your struct/class to be sortable -- you define a custom <=> operator and I *think* that also gives you > and < out of the box
<FromGitter> <sam0x17> as well as ==, etc
_ht has joined #crystal-lang
ur5us has joined #crystal-lang
Human_G33k has joined #crystal-lang
HumanGeek has quit [Ping timeout: 240 seconds]
return0e_ has joined #crystal-lang
return0e has quit [Ping timeout: 250 seconds]
Human_G33k has quit [Quit: Leaving]
ur5us has quit [Ping timeout: 256 seconds]
postmodern has quit [Quit: Leaving]
ur5us has joined #crystal-lang
<FromGitter> <asterite> Sam you can do: de raises_error?(t : T.class) forall T
<FromGitter> <asterite> then you pass the class as just another argument
<FromGitter> <asterite> That's why we don't have generic methods, because you can already pass classes around and capture their type generically, which actually ends up creating multiple methods, just like generics in other languages
<FromGitter> <asterite> Blacksmoke16 oh, I though <=> was already defined for Object. I'll add it today
<FromGitter> <stronny> do you even need forall here?
ur5us has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
<FromGitter> <phykos> How can I get the highest number my machine can represent with an `Int`?
<FromGitter> <ImAHopelessDev_gitlab> i just don't understand how a struct can be greater than another struct. what determines it to be "greater" the size of it? amount of ivars and types it uses?
<FromGitter> <dscottboggs_gitlab> @phykos `Int` is not a type in crystal
<FromGitter> <dscottboggs_gitlab> @ImAHopelessDev_gitlab it's up to the programmer how they choose to implement the `>` method
<FromGitter> <ImAHopelessDev_gitlab> in c, i know there is sizeof, but is that what we're talking about here or something totally different
<FromGitter> <dscottboggs_gitlab> @phykos if you mean to figure out whether you should use an `Int32` or `Int64` on a given system, you could do like ⏎ ⏎ ```alias SystemInt = {% if flag? :bits32 %} Int32 {% else %} Int64 {% end %}``` [https://gitter.im/crystal-lang/crystal?at=5e7de98550e7e56b4b96533c]
<FromGitter> <phykos> Forgot about that
<FromGitter> <phykos> s/Int/Integer
<FromGitter> <phykos> @dscottboggs_gitlab what are those `{%%}`?
<FromGitter> <dscottboggs_gitlab> Macro literals
<FromGitter> <phykos> Oh, like `#define`s in C?
<FromGitter> <dscottboggs_gitlab> yes, but much more powerful and a bit more safe
<FromGitter> <phykos> Lemme check
<FromGitter> <phykos> K
<FromGitter> <dscottboggs_gitlab> but yes, this basically translates to some `#ifdefs`
<FromGitter> <toddsundsted> @stronny without `forall` there doesn't seem to be any way to rescue exceptions of the passed type (`rescue e : T`). `typeof` doesn't seem to work here (`rescue e : typeof(t)`)
<FromGitter> <phykos> Ok
<FromGitter> <phykos> I know Ruby way too much, tho I don't use Crystal since a coupe of months
<FromGitter> <dscottboggs_gitlab> that's alright :)
<FromGitter> <stronny> @toddsundsted is this a bug then?
<FromGitter> <Blacksmoke16> Thanks @asterite
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#5d3c94e (master - Compiler: Honor LIBRARY_PATH as default library path (#8948)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/667675772
<DeBot> https://github.com/crystal-lang/crystal/pull/8948 (Compiler: Honor LIBRARY_PATH as default library path)
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#f9f0dca (master - Remove redundant calls to `Object.to_s` in interpolation (#8947)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/667677284
<DeBot> https://github.com/crystal-lang/crystal/pull/8947 (Remove redundant calls to `Object.to_s` in interpolation)
sagax has joined #crystal-lang
<FromGitter> <stronny> would it be beneficial to special case method's return type `self` to implicitely return self? like: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e7e1f96770a892bfb155619]
<FromGitter> <Blacksmoke16> :0
<FromGitter> <Blacksmoke16> i would find that helpful i have some method like
<FromGitter> <Blacksmoke16> ```def whatever(@value : Int32) : SomeInterface ⏎ self ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e7e202159057617f046bccd]
<FromGitter> <stronny> yeah, basically to get rid of boilerplate `self; end`
<FromGitter> <Blacksmoke16> well in this case i would prob still want the return type to be the interface but yea
<FromGitter> <Blacksmoke16> similar to how `: Nil` makes it return nil
<FromGitter> <stronny> yep
<FromGitter> <toddsundsted> @stronny i seems like a bug. the compiler should have access to the type of `t` there and `typeof(...)` can be used to declare the type of a variable elsewhere
<FromGitter> <lbarasti> Hey folks, any pointer to statistical shards? There is one mentioned in the awesome crystal repo, but the link is dead
<FromGitter> <Blacksmoke16> which one is that/
<FromGitter> <lbarasti> I'm looking for features like generating random numbers on well-known distributions
<FromGitter> <lbarasti> > which one is that? ⏎ ⏎ eheh, the shard was removed a few days ago, I didn't know
<FromGitter> <Blacksmoke16> RIP :(
<oprypin> I don't understand what makes it so that my build of Crystal has `$ crystal env` `CRYSTAL_PATH="lib:/usr/lib/crystal"`
<oprypin> strange that this one doesn't set `lib:$(PWD)/src`
<Welog> hello. when i do multiple puts in a spawn, with a sleep, I get the putted text by groups of 41 lines and nothing until this "buffer" get this number of lines. Do you know how is it possible to avoid that to get every puts in realtime ?
<FromGitter> <Blacksmoke16> STDOUT.sync = true
<FromGitter> <Blacksmoke16> Won't buffer output
<Welog> oh thanks Blacksmoke16!
<FromGitter> <Blacksmoke16> Also next crystal version will flush on newlines by default on ttys
<FromGitter> <Blacksmoke16> So shouldn't need it then
<Welog> ok, good to know. I only do that for debug purpose, but who know :)
ur5us has joined #crystal-lang
cloaked1 has quit [Read error: Connection reset by peer]
early has quit [Quit: Leaving]
cloaked1 has joined #crystal-lang
early has joined #crystal-lang
_ht has quit [Quit: _ht]
early` has joined #crystal-lang
early has quit [Ping timeout: 265 seconds]
ur5us has quit [Ping timeout: 256 seconds]
<FromGitter> <asterite> I think sync is true right now for TTY. It's for files that's not the case. Welog: do you see this behavior in the console, or when outputting to a file?
<watzon> Is it? I'm wondering if it might be having a hard time detecting a tty inside of a container then.
<watzon> Because I'm using nsbox right now to run my development environment in a container, and if I don't set sync to true I don't get any output.
<FromGitter> <asterite> ah, yes, that can be the causee
<FromGitter> <Blacksmoke16> @watzon using docker you prob have to use `-i` flag
<FromGitter> <Blacksmoke16> er `-t`
<FromGitter> <Blacksmoke16> ` -t, --tty Allocate a pseudo-TTY`
<FromGitter> <Blacksmoke16> might have to do something similar
<watzon> Not docker in this case, but podman is being used in the background I believe