<FromGitter>
<KCreate> I haven't used it and I'm also not sure how well it works
<FromGitter>
<KCreate> Or how to use it at all :laughing:
<FromGitter>
<faustinoaq> :sweat_smile:
gloscombe has joined #crystal-lang
bjz_ has quit [Ping timeout: 260 seconds]
bjz has joined #crystal-lang
Qchmqs has joined #crystal-lang
gloscombe has quit [Remote host closed the connection]
<FromGitter>
<exts> Can anyone help me with this compile error? http://pastebin.com/raw/6nh32B3T basically was trying to use this cURL shard and it's giving me an undefined reference to symbol '_end' error ⏎ ⏎ The cURL shard I'm 'testing' https://github.com/blocknotes/curl-crystal and I've gotten the error using the 2 line print curl version snippet on that page.
<FromGitter>
<exts> and i'm on linux mint if that helps anything
<FromGitter>
<KCreate> Excuse the silly question but, is libcurl installed?
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<RX14>
@exts why are you using the cURL shard?
<RX14>
I would really not recommend it if at all possible
<Papierkorb>
huh Object#clone isn't defined by default
<jokke>
Papierkorb: how could it?
<jokke>
ruby's clone almost never behaves as you'd expect it to
<jokke>
so i think a sane default is to leave it to the programmer
<Papierkorb>
jokke: "how"? By a macro
<Papierkorb>
And it's just not useful to not being able to clone stuff, as stuff using that stuff can't be cloned either
<Papierkorb>
There's `def_clone` for this, but having to patch every class isn't fun nor clean
<Papierkorb>
jokke: We can learn from rubys mistakes
<Papierkorb>
not to mention that not being able to clone stuff advocates to not-clone-stuff which isn't great in a parallel execution environment
<jokke>
Papierkorb: is it not implemented in the stdlib's classes?
<Papierkorb>
some seem to
<Papierkorb>
I'd rather have it opt-out than opt-in
<jokke>
hm
<jokke>
well i guess it's a matter of preference. I think it's most robust the way it is.
sz0 has joined #crystal-lang
<jokke>
i guess clone _could_ be implemented so that it will clone all instance vars and set them to a new object. But think of the side effects: what if you have two an object A which has object B in an instance variable, and object B has object A in an instance variable...
<jokke>
clone would be an infinite loop
<jokke>
so you'd have to just copy references
<jokke>
which is almost _never_ what you want
<jokke>
think of ruby's clone on hashes
<Papierkorb>
It's a solvable problem, and it's a problem that already exists
<Papierkorb>
if that's useful for sockets? Probably not, but you'd most likely not clone a server or something
<FromGitter>
<bcardiff> that does a shallow copy.
<Papierkorb>
dup is useless
<crystal-gh>
[crystal] asterite pushed 1 new commit to master: https://git.io/vyjZA
<crystal-gh>
crystal/master ce3492f Ary Borenszweig: Fixed #4166: Inlinable function call in a function with debug info must have a !dbg location
<RX14>
is ary finally back?
<jokke>
where was he?
<RX14>
i don't know
<jokke>
:)
<RX14>
but he hasn't been active much the last 2 weeks
<FromGitter>
<KCreate> vacation probably
<jokke>
vacation maybe?
<Papierkorb>
In reality, I want to clone a Crystal::Program, and ASTNode probably too. Both shouldn't hold fd's or something like that, so cloning them should be fine
<crystal-gh>
[crystal] Sija opened pull request #4174: Implement Time#clone (master...add-time-clone) https://git.io/vyj8B
Qchmqs has quit [Read error: Connection reset by peer]
<FromGitter>
<Zhomart> Hi, how can I call different method by return type? ⏎ Is it possible to do something like this? Btw, is there method match like in elixir? ⏎ ⏎ ```def load(raw : String, Int64) : Int64 ⏎ .... ⏎ end ⏎ ⏎ load("123", Int64) == 123i64``` [https://gitter.im/crystal-lang/crystal?at=58d29a03a84f611959d0d5aa]
<FromGitter>
<exts> @RX14 wanted to check if external file existed, then I just gave up and found out that HTTP::Client has a head method which does what I needed.
<FromGitter>
<KCreate> @Zhomart what are you trying to do?
<RX14>
yeah, always use HTTP::Client please, the cURL bindings don't go through crystal's IO system so they suck
<crystal-gh>
[crystal] asterite pushed 2 new commits to master: https://git.io/vyj0E
<crystal-gh>
crystal/master c069957 Ary Borenszweig: Travis: don't run in verbose mode
<RX14>
@Zhomart you can't call methods by return type, mathods are matched by argument type
<FromGitter>
<exts> got my little phpstorm updater working though, going to rewrite it so i can update any of jetbrains ide's on the fly
<FromGitter>
<exts> sometime later after a brief session of mass effect ;)
<FromGitter>
<Zhomart> @KCreate I want to write a method that accepts String, but might return Int32, Int64, Time, String depending on given type. ⏎ I don't want to write multiple methods, because calling those methods would be too verbose.
<RX14>
you want the return type to depend on the parameter types?
<FromGitter>
<KCreate> you can have the method return a union type
<FromGitter>
<KCreate> `Int32 | Int64 | Time | String`
<RX14>
@Zhomart can you please give an example or be more specific in what you mean.
<FromGitter>
<Zhomart> Sure. e.g. I want to create a method `load(raw : String)` that returns String, Time or Int32. ⏎ I can give this method what I want to receive. So I want to use the method like this: `load("123", Int32) == 123i32` or `load("12/12/2018", Time) == Time.new(2018, 12, 12)`.
<RX14>
aha
<RX14>
you can do this
<RX14>
def load(raw : String, type : T.class) : T forall T
<RX14>
the forall T syntax defines a type variable for a single method
<FromGitter>
<KCreate> wouldn't that only work in a generic class?
<RX14>
much like generics for classes
<FromGitter>
<KCreate> oh
<FromGitter>
<Zhomart> I think @KCreate method works for me too `foo("123").as(my_type)`. Thank you! ⏎ And `T for all T` looks really good.
<FromGitter>
<Zhomart> Thank you!
<RX14>
i'd recommend the generic method
<RX14>
.as() with the union will probably be longer and more fragile
<FromGitter>
<KCreate> @RX14 What are the differences between using the generic method and `def foo(klass : Class)`?
<BlaXpirit>
seems like crystal actually tracks all possible exception types that a function may give
<RX14>
yeah...
<RX14>
it just confused me
<FromGitter>
<bcardiff> Yes, it tracks down the instances: https://carc.in/#/r/1qqh , it might change in the future that. Leaving that typeof(ex.value) to type to just Object.
<RX14>
yeah...
<RX14>
i think it's a little more strange and unexpected for that to be inferred
<RX14>
compared to return types
<RX14>
even though it's essentially the same as far as type inferrence I would think
fenicks has joined #crystal-lang
sardaukar has joined #crystal-lang
bjz has joined #crystal-lang
sardaukar has quit [Client Quit]
<crystal-gh>
[crystal] will opened pull request #4177: Fix TCPSocket segfault on missing host and 0 port (master...fix-tcp-segfault) https://git.io/vSedL