RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.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
olbat__ has quit [Ping timeout: 256 seconds]
olbat has joined #crystal-lang
olbat has quit [Changing host]
olbat has joined #crystal-lang
moei has joined #crystal-lang
dragonkh has joined #crystal-lang
<dragonkh> hi - If I have myClass(T) - then when I'm working with methods inside the class everything know what T is - but if I want a convenience method of myClass.go() - the go() method can't infer T - so how do I allow a T to be provided to a def self.go() kind of method?
<dragonkh> convenience method of MyClass.go()
<dragonkh> and MyClass(T)
<dragonkh> sorry it's late - sleeeepy
<dragonkh> maybe a macro could help
<FromGitter> <ezrast> @dragonkh same way you'd specify it everywhere else: https://carc.in/#/cr
<dragonkh> ezrast - did you want me to type something in that empty carc.in ?
<FromGitter> <ezrast> oops, https://carc.in/#/r/3mva
<dragonkh> ah yes very good thanks :)
dragonkh has quit [Ping timeout: 256 seconds]
<FromGitter> <faustinoaq> > is there a clean way to evaluate an alternate condition only when the value is `nil` (not `false`)? ⏎ ⏎ @faultyserver try using if as a suffix (https://crystal-lang.org/docs/syntax_and_semantics/as_a_suffix.html) ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a920b9b888332ee3aca1673]
<FromGitter> <aisrael> Won’t `value ||= …` work as well (though, I try to avoid it myself, since I favor immutability)
<FromGitter> <aisrael> Or even `value = expr_a || expr_b || expr_c`
<FromGitter> <ezrast> No, he needs to preserve `false`
<FromGitter> <aisrael> Oh, right. I always thought `||=` only worked if `value` was `nil` . Just tried it in Ruby and it seems to evaluate even if `value` is `false`. Counter-intuitive :(
<FromGitter> <bew> Yes because `||=` (and most other boolean branching) base there condition on truthy/falsy values. And the basic things, is that only `false` and `nil` are considered falsy values, and everything else is truthy.
<FromGitter> <aisrael> Personally, I’d rather have a “reassign only if `nil`” operator. `value ?=`?
<FromGitter> <aisrael> (Ooh, `??` is in C#)
<FromGitter> <aisrael> May I open an issue on this?
<FromGitter> <bew> There's no way it could be accepted
<FromGitter> <bew> I think
<FromGitter> <bew> well you could try
<FromGitter> <bew> To see the reactions & explainations
<FromGitter> <elorest> What would be the best way to read in 2 byte (16bit) blocks as Int16 instead of bytes from an IO?
<FromGitter> <bew> @elorest `io.read_bytes(Int16, IO::ByteFormat::LittleEndian)` (with the correct endianness for you)
jxv has joined #crystal-lang
<FromGitter> <elorest> That looks right. Thanks @bew. ⏎ ⏎ Assuming a already had a var containing Bytes is there a better way than this? ⏎ ⏎ https://carc.in/#/r/3mw0 [https://gitter.im/crystal-lang/crystal?at=5a92265e888332ee3aca72e6]
codenoid has joined #crystal-lang
<FromGitter> <elorest> Or this? https://carc.in/#/r/3mw5
<codenoid> hi, how i can make, `class.somevalue.functionname(somedata)` ?
<FromGitter> <bew> You can create the `IO::Memory` with the bytes directly
<FromGitter> <elorest> @bew similar to the last carc.in i posted? https://carc.in/#/r/3mw5
<FromGitter> <bew> https://carc.in/#/r/3mw6
<FromGitter> <elorest> <codenoid> I'm assuming that by class you my like `Myclass.myclassmethod.method_on_return_value`?
<FromGitter> <elorest> Ok thanks for the help.
<codenoid> i want make something like `db.collectionname.insert(somevalue)`
<codenoid> `collectionname` is mutable
<FromGitter> <elorest> If collection name had an instance method call `insert(val)` on it that would work. If it doesn't and you know what you want it to do you could add ⏎ ⏎ ```def insert(val) ⏎ #your logic" ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5a9229eb35dd17022eed9440]
hightower2 has joined #crystal-lang
hightower3 has quit [Ping timeout: 240 seconds]
<codenoid> oh
<codenoid> that was easy actually,
<codenoid> just define [](string), to call new class
<codenoid> thanks @elorest, i use []
<FromGitter> <elorest> :)
qard_ has joined #crystal-lang
qard_ has quit [Client Quit]
qard has quit [Ping timeout: 240 seconds]
qard has joined #crystal-lang
codenoid has quit [Ping timeout: 252 seconds]
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 240 seconds]
qard has quit [Quit: qard]
qard has joined #crystal-lang
jxv has quit [Quit: my string on the can snapped off]
qard has quit [Quit: qard]
devil_tux has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Read error: Connection reset by peer]
<FromGitter> <bararchy> really cool @faustinoaq !
rohitpaulk has joined #crystal-lang
alex`` has joined #crystal-lang
frojnd has quit [Ping timeout: 276 seconds]
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter> <vlazar> HTTP::Server allows you to specify an array of handlers and a block. Is there any difference between using array argument for third-party handlers and block for application handler, or just chaining all handlers in array? Should I prefer one way over another for some reason or is it just a matter of preference? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crysta
<FromGitter> ... l-lang/crystal?at=5a9264726fba1a703a9998de]
<FromGitter> <ezrast> @vlazar I don't think it matters much. The `Handler` module doesn't add much baggage except for the `#call_next` method, which the last handler doesn't use anyway.
rohitpaulk has joined #crystal-lang
<FromGitter> <vlazar> @ezrast Thanks! My understanding is that using a block for an app handler is idiomatic way, although I wasn't sure, hence my question.
<FromGitter> <bararchy> @elorest checkout the latest version\readme of BlueCr, you can now handle services directly, I'll add more stuff, so keep an eye
<FromGitter> <elorest> thanks @bararchy
<FromGitter> <elorest> Is there a way to wrap a cli with a crystal app, send commands and print response. Seems like all I would need to do is wrap a process in an IO or something...
rohitpaulk has quit [Ping timeout: 245 seconds]
<FromGitter> <bararchy> You can use IO::Memory and pass to Process(stdin,stdout)
<FromGitter> <elorest> https://carc.in/#/r/3mx0
<FromGitter> <elorest> @bararchy Here's what I was trying to do but something is wrong it with.
<FromGitter> <bararchy> Hmmm there are some stuff that looks weird , but, I did a wrapper to GDB using Process, so let me look at it and I'll send an example of my code
rohitpaulk has joined #crystal-lang
<FromGitter> <elorest> Awesome.
<FromGitter> <elorest> I tried something a bit simpler (single input/output) close. But it still runtime errors.
<FromGitter> <elorest> https://carc.in/#/r/3mx2
<FromGitter> <elorest> @bararchy I'm going to bed but if you want to PM me or post it here I'll check it in the morning. Thanks again.
mroth has quit [Ping timeout: 276 seconds]
mroth has joined #crystal-lang
Liothen has quit [Ping timeout: 256 seconds]
Liothen has joined #crystal-lang
Liothen has quit [Changing host]
Liothen has joined #crystal-lang
pabs has quit [*.net *.split]
baweaver has quit [*.net *.split]
Vexatos has quit [*.net *.split]
jhass has quit [*.net *.split]
jwaldrip has quit [*.net *.split]
avdi has quit [*.net *.split]
f1refly has quit [*.net *.split]
pabs has joined #crystal-lang
baweaver has joined #crystal-lang
jhass has joined #crystal-lang
avdi has joined #crystal-lang
jwaldrip has joined #crystal-lang
f1refly has joined #crystal-lang
Vexatos has joined #crystal-lang
<FromGitter> <bararchy> 👍
Nik736 has joined #crystal-lang
A124 has quit [Ping timeout: 256 seconds]
<FromGitter> <philfine> Is the supportfor concurrency still experimental ?
<FromGitter> <philfine> In my application I would preferably have 3 concurrent processes, but don't seem to make spawn work
<RX14> there's support for concurrency but nor parallelism
<FromGitter> <philfine> If I have a C binding function that might take some time to reply, how can I from the C binding yield the Fiber ?
<RX14> @philfine yeah that's not really possible
<RX14> C bindings are unlikely to play well with crystal fibers even after we have parallelism
<RX14> @philfine what exact C library are you using?
<FromGitter> <philfine> Connecting to some code that uses opencv
<RX14> yeah that's not possible
<RX14> @philfine you'll have to use something like forking or spawning worker processes to achieve that
<FromGitter> <philfine> Ok ;)
<FromGitter> <philfine> Will do it by letting a thread running on the C side and retrieve the data through some safe functions
<FromGitter> <philfine> All I get from the C side will be simple data
return0e_ has quit [Read error: Connection reset by peer]
<FromGitter> <philfine> Is there a library for global event mechanism ?
<RX14> @philfine there's https://github.com/Papierkorb/cute
<RX14> but it's not *too* hard to roll your own
return0e has joined #crystal-lang
<RX14> it's really just an array of Procs
<RX14> (usually)
<FromGitter> <philfine> I was doing that
<FromGitter> <philfine> I was wondering, if I was doing something wrong there
<FromGitter> <philfine> I was more thinking of something using the chennels to safely communicate between Fiberse
<RX14> that's just a little too abstract to really comment on
<FromGitter> <philfine> :)
<RX14> channels and event architecture are pretty orthogonal
<RX14> depends if you want to process events sequentially or in parallel
<RX14> if sequentially then yes channels are what you want
<RX14> if in parallel then just smack each event handler in a new fiber
<FromGitter> <philfine> Well , I need to try it before I can comment as well :D
codenoid has joined #crystal-lang
<FromGitter> <bararchy> @philfine what are you doing with opencv ?
<FromGitter> <philfine> Just some image recognition, detecting some points in a pattern
<FromGitter> <philfine> I want it connected to crystal
<FromGitter> <philfine> to use crystal for the general purpose code
<FromGitter> <philfine> @bararchy Why do you ask ?
<FromGitter> <bararchy> Cool :) we added CNN to SHAInet (nn shard) if you wanna try it out , might help you. If you specifically need opencv then I guess a simple wrapper is cool
<FromGitter> <bararchy> @philfine I was interested , as Machine Learning in Crystal is something I try to push for
<FromGitter> <bararchy> And was happy to see you played around with the concept
codenoid has quit [Ping timeout: 240 seconds]
codenoid has joined #crystal-lang
<livcd> btw what are currently the problems with Windows port ?
codenoid has quit [Ping timeout: 240 seconds]
return0e has quit [Ping timeout: 252 seconds]
return0e has joined #crystal-lang
A124 has joined #crystal-lang
A124 has quit [Read error: Connection reset by peer]
codenoid has joined #crystal-lang
A124 has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 245 seconds]
A124 has quit [Ping timeout: 240 seconds]
LJNZXWZMB has joined #crystal-lang
<watzon> Ok I just finished what I'm pretty sure is the first third party OAuth shard for use with libraries like Halite https://github.com/watzon/easy_oauth
<FromGitter> <bararchy> cool, great job watzon
<FromGitter> <philfine> @bararchy I will survive with a simple wrapper, no need for AI
<watzon> Gracias mi amigo
<FromGitter> <bararchy> @philfine 👍
<FromGitter> <philfine> What are the coolest CNN networks to try out
<watzon> Haha. I need it for the Twitter API wrapper I'm working on. I wanted to use Halite instead of HTTP::Client, but Halite doesn't have built in OAuth support
<FromGitter> <philfine> iin your opinion
<FromGitter> <bararchy> @philfine you mean generally speaking? and you mean frameworks or architectures ? or trained networks ?
<FromGitter> <philfine> trained networks
<FromGitter> <philfine> Common user does not have enough data to train a network :)
<FromGitter> <philfine> IMHO
<FromGitter> <philfine> Currently getting invalid memory access (signal 11), reached the boundaries ... ?
rohitpaulk has joined #crystal-lang
<FromGitter> <philfine> How to use GDB with crystal ?
<FromGitter> <bararchy> well, it all depends on what your trying to achive. ⏎ I never needed a trained network as we don't really use CV in my workplace, we have Evolutional Strategies and reinforcment learning usually. ⏎ but maybe our residant ML expert is around to help point at something @ArtLinkov ?
<FromGitter> <philfine> I was just curious
<FromGitter> <bararchy> that's ok, maybe he can give you intresting info :)
<FromGitter> <bararchy> I think he played around with AlexNet
<livcd> re :)
<FromGitter> <bararchy> and some stuff in Matlab
<livcd> anyone can answer ? :F
<FromGitter> <bararchy> Windows port ?
<livcd> yea
<watzon> You can look at the issue thread on GitHub
<FromGitter> <bararchy> RX14 is the main contributor there, maybe he can shed a light, but I think mostly the "issue" is that he is the only one activly working on it hahah
<FromGitter> <bararchy> so it will take as much as the amount of time he can put on this project
<livcd> cant find it
<livcd> ah yeah
<livcd> ok
codenoid has quit [Ping timeout: 252 seconds]
<watzon> The Crystal OpenSSL implementation needs RSA support
rohitpaulk has quit [Ping timeout: 240 seconds]
<watzon> I'd add it myself, but I'm not fluent enough in C and the openssl docs really suck.
<watzon> Has there been discussion about making macros in Crystal more powerful? I feel like I could make a pretty compelling argument for allowing direct access to the AST.
<RX14> @philfine gdb should just work
<RX14> Out of the box
<RX14> Just as if you'd made the executable with c
<RX14> valgrind,callgrind too
<FromGitter> <valamorgon> do we have template literals in crystal? like in js https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals or like double quoted dollar sign in php
<RX14> @valamorgon template literals are just normal strings in crystal/ruby
<RX14> you can use #{} to interpolate expressions in any string
<watzon> valamorgon you mean for doing string interpolation?
<watzon> `"hello, #{var}"`
<FromGitter> <philfine> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a930460458cbde557c76308]
<watzon> Or `"hello, {}" % ["world"]`
<FromGitter> <philfine> Shouldn't the confition resolve the issue ?
<FromGitter> <philfine> Should the condition be different
<FromGitter> <valamorgon> @RX14 and @watzon thanks, this solves my problem
<RX14> @philfine == can be overloaded so the compiler can't use it for nil checks :C
<FromGitter> <philfine> If the condition is not there I also get it
<RX14> standard practice is to use truthiness of nil:
<RX14> `event.call(response) if response`
<RX14> if you want to be super explicit you can use `event.call(response) unless response.nil?`
<RX14> but most people use the first one
<FromGitter> <philfine> response should be a String
<FromGitter> <philfine> But because it comes from socket.gets it might be nil
<RX14> but response is a String | Nil
<RX14> yes
<RX14> gets returns nil on EOF
<RX14> how do you want to ahndle EOF?
<FromGitter> <philfine> Just not call event.call
<RX14> so what I first write
<watzon> You can use to_s
<RX14> `event.call(response) if response`
<watzon> If it's nil you'll just get an empty string
<RX14> @watzon, no thats not at all what you want
<RX14> since then you'll get an empty string
<RX14> which is not what @philfine wants
<RX14> @philfine any variable can be treated as a value in crystal, but nil is treated as false just like a null pointer in C
<RX14> so what I wrote is valid even though response is a String?
<RX14> not a bool
<RX14> hope that helps
<FromGitter> <philfine> Perfectly
<RX14> @philfine since you're working with C bindings, null pointers are also falsey in crystal
<RX14> so that might clean up some of your null pointer handling code if you have any
<FromGitter> <philfine> In crystal it is not clear what gets to be used to make type inference at compile time and what cannot be used ;)
<RX14> yeah
<RX14> there's some "pseudo methods"
<RX14> like .nil? and .as
<RX14> they can't be overridden and are defined in the compiler
<RX14> only these contribute to the type checking
<FromGitter> <philfine> Ok, good to know ;)
<FromGitter> <philfine> Thanks
<RX14> i'm not sure the language reference has any central docs on what can be used to assert type and what can't
<RX14> which is quite an omission
<RX14> it's scattered around a bit...
<FromGitter> <philfine> Although it fixed that at callee level, in the event class I still get: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a930686888332ee3ace14d7]
<RX14> but it's super not obvious to look there
<RX14> @philfine looks like @callback can be nil
<RX14> i'd need more code to suggest how best to make @callback never be nil
<RX14> but if that's not possible you obviously need to decide what to do when it's nil
<FromGitter> <philfine> Thats fine ... not real secrets here
<RX14> OK
<FromGitter> <philfine> I am trying to cook an Event mechanism to use between Fibers
<RX14> how i'd model that would be to eliminate has_callback and just test for nil
<RX14> since has_callback is only true when @callback isn't nil
<RX14> and the opposite
<FromGitter> <philfine> I am still learning this thing :D
<RX14> of course
<FromGitter> <philfine> I know ruby, but many things you cannot really do here :)
<RX14> that's how i'd write Event1
<FromGitter> <philfine> if callback = @callback
<FromGitter> <philfine> What is the purpose ?
<RX14> assigning @callback to a local variable
<RX14> it's equivalent to just: `callbcak = @callback; if callback`
<RX14> we need to assign it to a local variable to be thread safe
<FromGitter> <philfine> Ok
<RX14> since @callback could have it's type changed by another fiber between us checking it's type and using it
<RX14> so we have to assign it to a local to perform type restrictions on it
<FromGitter> <philfine> BTW Any recomendation to make Event become more generic
<FromGitter> <philfine> I mean I want to put anything in the second argument
<RX14> @philfine btw cleaned up Event1 a bit more (they're exactly equivalent, it's just syntax sugar) https://play.crystal-lang.org/#/r/3mz3
<RX14> crystal has a shortcut for assigning to ivars in the constructor
<FromGitter> <philfine> I knew about it, but with so much fiddling, I endup removing it
<RX14> lol
<FromGitter> <philfine> I had a professor that used to say "Computer Science is not experimental" ... but in practice :D
<RX14> haha
<RX14> I'm not really sure how to make events more generic
<FromGitter> <philfine> This is not Ruby ;)
<RX14> which is why I kinda recommended Papierkorb's shard: it solves this with macros https://github.com/Papierkorb/cute
faustinoaq has joined #crystal-lang
<RX14> the reason your architecture isn't really very friendly to typing is ebcause it tries to put multiple types of events in a single eventhandler
<RX14> and a single eventhandler can't really be generic on multiple types
<RX14> you really want a seperate event class, or a generic instantiation for each type of event
<RX14> you want to encode the type of the event as a type - a seperate class - instead of just using a symbol
<RX14> and then the compiler can help you a lot with spotting errors because it has a lot more information
<RX14> but if you need a class/subclass/make event generic then you can't really make EventHandler generic on multiple types of event
<FromGitter> <philfine> I see what you mean
<FromGitter> <philfine> I am either stuck by one thing or the other
<FromGitter> <philfine> Going for dinner
<FromGitter> <philfine> I have some more questions, but really need to leave :)
<FromGitter> <philfine> TTYL
<RX14> @philfine cya
<crystal-gh> [crystal] bararchy opened pull request #5746: BLUETOOTH Constants for Socket (master...master) https://git.io/vAr3O
<FromGitter> <elorest> <RX14> Any idea why this code doesn't work? I'm just trying to start a process and write to input and read from output onces as an example. https://carc.in/#/r/3mx2
<FromGitter> <elorest> Or really anyone who knows what's wrong with my code lol. I can't find a lot of documentation on Process.run.
<RX14> there you go
<RX14> :)
rohitpaulk has joined #crystal-lang
vivus has joined #crystal-lang
<watzon> Really I still don't understand the reason for this `instance variable '@options' of Tweeter::Headers must be Hash(String, JSON::Type), not Hash(String, String)`
<watzon> I need the hash to be able to accept almost anything as a value, but it just so happens to be a Hash(String, String) that's being passed in
<FromGitter> <philfine> @RX14 I think the result is a little differenc from what I first intended
<RX14> yeah
<FromGitter> <philfine> I don't see why the event type must be different from Symbol
<RX14> but I don't think you're going to get multiple event types in one
<RX14> and I'd question why you need it
<FromGitter> <philfine> The type is for having different fiber listen to the same message
<RX14> hmm?
<FromGitter> <philfine> The event_type would be what would make them match as listening to the same
<RX14> i'm sorry I don't understand
<FromGitter> <philfine> I would have multiple fiber calling: ⏎ ⏎ ```and some other fiber woud call:``` ⏎ ⏎ And both the listeners and dispatchers would be agreeing on the type ... but having the same handler for everything [https://gitter.im/crystal-lang/crystal?at=5a9322ba53c1dbb743768d46]
<FromGitter> <philfine> Had to change it a little
<FromGitter> <philfine> Is there a way to package objects, in some generic type.
<RX14> well i'm sorry but it's impossible to do something like that sanely in a statically typed language
<FromGitter> <philfine> I mean something like Box
<RX14> but why not just have a seperate handler for each type?
<FromGitter> <philfine> The hadler should be a singleton
<FromGitter> <philfine> Deosnt the Box, as used in the C binding callback, would not do just that
<FromGitter> <philfine> Only the origin and destination of the event should know its type ...
<RX14> I mean you can but it's terribly unsafe
<RX14> one messup and you get a segfault
<RX14> I strongly discourage it
<FromGitter> <philfine> I understand
<RX14> I think rethinking your architecture a bit is better
<FromGitter> <philfine> I will
<RX14> I think you should just have multiple event handlers
<RX14> multiple singletons
<FromGitter> <philfine> :)
<RX14> perhaps it'd be easier if you explained what the event handlers were used for
<RX14> and how many evets do you have?
<FromGitter> <philfine> For example: https://play.crystal-lang.org/#/r/3n00
<RX14> yeah I understand
<RX14> but I don't see why you can't easilly replace that with an eventhandler *just* for commands
<FromGitter> <philfine> For specific things it is fine to replace by specific generic even handlers, But I would like to generalize
<FromGitter> <philfine> Because I might want for example to have some other fiber that would get the same message
<FromGitter> <philfine> For that particular case I would survive with the Channel :D
<RX14> if there's some other fiber that would get the same message you just reference the same event handler
<RX14> I don't see the issue?
<RX14> at the end of the say you *must* know what event you want to recieve
<RX14> so therefore you know what eventhandler you need to use
<crystal-gh> [crystal] ysbaddaden pushed 1 new commit to master: https://git.io/vArCD
<crystal-gh> crystal/master 91a025f Olivier DOSSMANN: Missing ref to mkstemps in ARM...
<FromGitter> <philfine> Both at dispatch and listen sides, I can easily set the type
<FromGitter> <philfine> At the event "level" it is inconvenient :D
<RX14> but why would you need to do anything at the event level?
<RX14> is there anything you need to do to all events reghardless?
<FromGitter> <philfine> No but it is inconvenient to have one event handler per type
<FromGitter> <philfine> If I have, can I have some other class that will abstract that for me ?
<RX14> you can certainly have a class with all your event handlers in
<RX14> and you could probably have the sending side work pretty well
<RX14> but I don't see how you could get the same interface on the recieving side
<FromGitter> <philfine> Not with current implementation, but it would make total sense to listen for more than 1 event, even with different message types
<FromGitter> <philfine> Can I create a generic Event class, and create subclasses of Event to store the extra info ?
<FromGitter> <philfine> I guess I cannot
<RX14> hmm yeah
<RX14> yeah that'll probably work
<RX14> why didn't I think of that
<FromGitter> <philfine> I though I could not
<FromGitter> <philfine> :D
<RX14> nah if you have every type of event with a different payload it's fairly simple
<RX14> and then you just reference the abstracxt Event
<FromGitter> <aisrael> @watzon Yeah that’s interesting. Tried it now and it seems while union types are polymorphic as parameters to methods, they’re not when treated as such when used as the type parameter to a `Hash` or `Array`. Instead, you have to `.as(Type)` the individual values. See https://carc.in/#/r/3n01
<watzon> Yup. And it's a gigantic pain in the ass
<RX14> @aisrael yeah its because they have different binary representations
<RX14> there's no way to fix it
<RX14> .map(&.as()) is the best you're going to get
<RX14> and no, you can't do it without copying
<FromGitter> <aisrael> Ugh :(
<RX14> because then you'd be able to get the wrong type in
<FromGitter> <aisrael> How so?
<RX14> if it was possible you'd be able to get an A inside a B
<RX14> and thats not how type systems work
<RX14> @aisrael `a = Array(String).new; b : Array(String | Int32).new; b << 4; a # => [4]
<RX14> oh wait
<RX14> we just put a 4 inside an array(string)
<RX14> it's impossible
<FromGitter> <aisrael> Thanks, was struggling to think of a case
<RX14> oops
<RX14> I meant b : Array(String | Int32) = a
<RX14> but I think you got that
<FromGitter> <aisrael> So if we allowed that at compile-time, it’d just have to be an exception at run-time?
<RX14> no it'd be a segfault
<RX14> and we just wouldn't allow it
<RX14> ever
<watzon> Is there a better way to handle the case where you need to be able to accept a hash who's value could be anything then?
<FromGitter> <aisrael> Can’t it be caught at run-time like how `.as()` works? (am assuming that’s how `.as()` works)
<watzon> I'm considering just accepting strings lol
<watzon> I think `as.()` is compile time
<FromGitter> <aisrael> @watzon, @philfine, you and I are almost all in the same predicament
<FromGitter> <aisrael> Darn Crystal and it’s type checking! ;)
<watzon> whoops `as()` lol
<RX14> watzon, don't
<RX14> you can't
<RX14> there's no way to represent "anything" in crystal
<watzon> Right lol. I love it and I hate it
<RX14> it's called static typing
<RX14> it's so so rare that you want "anything"
<FromGitter> <philfine> @aisrael What do you mean ?
<watzon> It's times like this where I long for rust's matching and Some/None
<RX14> how does that solve anything?
<RX14> rust can't do anything we can't
<watzon> Well not "anything" per-se, but I do want to be able to accept anything that can be converted to JSON
<FromGitter> <philfine> I agree with RX14
<RX14> so JSON::Type
<RX14> ...
<FromGitter> <philfine> We are just too used to Ruby
<watzon> Yes, but that's the problem
<RX14> watzon, just force your callers to declare the hash as a Hash(String, JSON::Type) in the very first place
<RX14> that OR you have to copy it
<FromGitter> <aisrael> @philfine > Is there a way to package objects, in some generic type.
<FromGitter> <aisrael> @philfine Yeah we just wanted Ruby with strong type checking and look what we got! Uhm. *Really* strong type checking, eh?
<watzon> That's my predicament. Forcing someone to do `.as(Hash(String, JSON::Type))` to every hash they pass in doesn't make for a very good API
<watzon> I may just have to do it mysefl
<watzon> myself*
<RX14> but they don't!
<RX14> they can just declare it as the right type at the beginning
<RX14> and no converson is needed
<FromGitter> <philfine> @aisrael We got something that finds possible problems at compiile time and much faster
<watzon> But what if it's anonymous and they're not declaring it at all?
<watzon> `client.get("https://requestb.in/18h7sqd1", { "profile_link_color" => "222333" })`
<RX14> uhh
<watzon> That hash automatically becomes `Hash(String, String)`
<FromGitter> <philfine> My problems are solely for lack of experience in Crystal, and too used to Ruby and its unrestrictiveness
<RX14> `client.get("https://requestb.in/18h7sqd1", { "profile_link_color" => "222333" } of String => JSON::Type)`
<FromGitter> <aisrael> Or literals, yeah
<watzon> I'd have to do the conversion in the method
<FromGitter> <aisrael> Ahh… `of`
<RX14> you don't have to
<RX14> In the future literals could possibly be special cased
<watzon> Ahh I actually didn't know about `of`
<RX14> where they can get their arguments from the method signature
<RX14> but ehh
<watzon> That doesn't make for a very good API though
<RX14> thats a bit of magic
<RX14> yeah
<RX14> it's not a good API
<FromGitter> <aisrael> +1 for if the method signature declares the type, then check and ‘coerce’ or cast appropriately
<RX14> so you have to do it recursively in the method
<RX14> @aisrael it could never be a coerce or cast (as I explained before)
<RX14> it would just change the type of the literal
<FromGitter> <aisrael> Right, that’s what I meant. Not actually cast (parameters of different type)
<FromGitter> <aisrael> So, “infer”? the type of the literal based on method sig?
<RX14> yep
<watzon> I love that idea
<watzon> That would fix 90% of my problems
<travis-ci> crystal-lang/crystal#91a025f (master - Missing ref to mkstemps in ARM): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/346043636
<FromGitter> <aisrael> @philfine Am used to Java (and before that C/C++) so strong typing doesn’t bother me. It’s just the “impedance mismatch” of having a Ruby syntax that’s throwing me off, I guess. Am trying to avoid the class explosion and boilerplate of e.g. Java but finding that I can’t use my old Ruby tricks.
<RX14> well in Java you can deal with Object
<RX14> and in crystal you just can't
<RX14> because java runs in a vm and crystal is compiled
<FromGitter> <philfine> Should this work ?
<FromGitter> <philfine> What I am missing: https://play.crystal-lang.org/#/r/3n06
<RX14> you don't want the symbol
<RX14> you can remove the symbol entirely and make the command type be entirely based on the type of the subclass
<RX14> for example:
<FromGitter> <philfine> I do want the symbol :D
<RX14> no you don't
<RX14> watch
<FromGitter> <aisrael> > well in Java you can deal with Object ⏎ That’s another, fundamental cognitive stumbling block
<FromGitter> <philfine> I know it can be entirely without that symbol, and the symbol can be part of the event, but that doesn't seem to be my problem now, right ? :D
<RX14> like that
<RX14> removed some unneccesary: https://play.crystal-lang.org/#/r/3n0b
<RX14> just some generics and you can have it all
<FromGitter> <philfine> Ok
<FromGitter> <philfine> Thats perfection :)
<RX14> told you you don't need the symbol :)
<FromGitter> <philfine> You played with the macros ;)
<FromGitter> <philfine> You tricked me there
<RX14> it's not macros
<RX14> it's just generics on methods
<RX14> they act a little like macros but they're a lot more limited
<FromGitter> <philfine> Ok
<RX14> a lot safer
<RX14> and a lot more beautiful
alex`` has quit [Ping timeout: 240 seconds]
<RX14> and are a lot less work for the compiler
<RX14> since it doesn't have to run an interpreter either
<FromGitter> <philfine> So basically is like overloading for all types of classes extending from EventType
<RX14> if you passed anything that wasn't an eventtype you'd get an error
<RX14> but yes
<RX14> it basically templates the method
<FromGitter> <philfine> Any chance I can get this listen to look for more than a single eventtype ?
<RX14> as in you want either x or y?
<FromGitter> <philfine> yep
<RX14> thats a bit more tricky
<RX14> you can do *event_type
<RX14> and then you get a tuple of event types
<RX14> hmm
<RX14> i mean yes you can
<RX14> but the way you set up your channels in a hash is a bit uhh
<RX14> funky
<RX14> makes it a bit more difficult
<FromGitter> <philfine> Now we can get the channel in the eventype itself
<RX14> since if you have to event types you then have two channels
<RX14> two*
<RX14> and then you can't really listen to two channels
<FromGitter> <philfine> You have to have 1 per listener right ?
<RX14> but in terms of actually inside the method then sure you can
<RX14> it'd be possible if you had a single channel
<FromGitter> <philfine> We can have a chain of channels
<RX14> hmm
<FromGitter> <philfine> I mean, one listener sends the message to the next listener :D
<RX14> ...
<FromGitter> <philfine> Let me work it out
<RX14> @philfine you can totally just listen to Event though
<RX14> and then you get an Event out
<RX14> and then just case over every event type
<RX14> case event; when Event1, Event2; do_something; end
<RX14> in a loop
<RX14> and then if it's not event1 or event2 it just gets ognored
<RX14> delivered but ignored
<FromGitter> <philfine> Sure
<FromGitter> <aisrael> Am not sure am following fully, but what prevents you from calling `eh.listen(String)`? The `forall T` is unbounded, yes?
<RX14> yes
<RX14> but then T is the wtong type in the method
<RX14> it won't give you a *nice* error message
<RX14> but it fails somewhere down the line
<FromGitter> <aisrael> Anyone else asking about bounded generics? :)
<RX14> it's possible
<RX14> not too hard
<RX14> but syntax is an issue
<RX14> syntax is the main issue
<RX14> how would we write it
<FromGitter> <aisrael> @philfine I don’t know your full use case but already am thinking of actor model or e.g. GenServers from Elixir-land
<FromGitter> <aisrael> @RX14 Yeah. I don’t even know how I’d want to maybe specify it even. I just know that something like `forall T < EventType` with compiler-checking/enforcement would be nice
<FromGitter> <aisrael> Might also solve the union type thing for some folks, *if* they can transform it to a rooted class hierarchy
<RX14> well it would be technically possible to allow people to refer to Reference types
<RX14> which would serve the same as java's Object
<FromGitter> <philfine> How can I get that the case statement based on all available EventTypes ?
<FromGitter> <philfine> i mean using the generics
<hightower2> philfine, RX14 this code you came up with looks like exactly something I was looking for
<FromGitter> <philfine> 9% my inspiration 91% RX14 transpiration
<RX14> yeah I don't know why I didn't think of just making the events subclasses
<RX14> i guess I must be tired
<FromGitter> <philfine> @hightower2 What so you mean by that ?
<hightower2> philfine I needed something very similar to this code, checking if I can reuse it (for some event listening/triggering)
<FromGitter> <philfine> @RX14 Can we construct the case statement with the generics
<FromGitter> <bararchy> RX14 any feedback regarding #5746 ?
<DeBot> https://github.com/crystal-lang/crystal/pull/5746 (BLUETOOTH Constants for Socket)
<RX14> no
<RX14> @philfine ehh you could do it with macros but why?
<FromGitter> <bararchy> Cool, thanks
<RX14> case is pretty much cleaner lol
<FromGitter> <philfine> Maybe we should consider to make a shard out of this small code.
<RX14> I still prefer Papierkorb's cute
<RX14> but whatever
<FromGitter> <philfine> Than I do not understand where the case should be
<FromGitter> <philfine> I need to understand the Papierkorb's cute
<RX14> @philfine oh uhh
<RX14> listening form EventType doesn't work
<RX14> for*
<RX14> since you just get a channel for EventType
<RX14> and you never send an eventtype
<RX14> you just send it's children
rohitpaulk has quit [Ping timeout: 245 seconds]
<RX14> darn
<RX14> I got it all typed out then accidentally pressed esc on carc.in
<RX14> and then it deleted all my code
<FromGitter> <philfine> :(
<RX14> wtf jhass
<hightower2> RX14, what I keep getting stumbling into with Cute is that both the code I am trying to port and my understanding of how the event model needs to work is based around syntax like events[:event_name].emit(args) , and that's not how Cute works
<RX14> yeah i'm lucky in that I don't do ports
<RX14> I don't have any legacy ruby code i'm trying to fudge into crystal
<FromGitter> <philfine> That is not my case actually :)
<FromGitter> <philfine> Exploring the limits of the language, but for a purpose :D
<FromGitter> <philfine> Or not, in your case
<FromGitter> <philfine> Well, I am very tired.
<FromGitter> <philfine> @RX14 , @hightower2 If you make some progress on this subject, please post me about it
<RX14> that's progress
<FromGitter> <philfine> Wouldn't only the first one to listen get the message in your case
<RX14> but its broke
<RX14> no we still have an array
<FromGitter> <philfine> Ok
<RX14> just forgot the loop do
<RX14> lol
<RX14> since we want to recieve multiple events
<FromGitter> <philfine> :)
<FromGitter> <philfine> So small, so clean, so functional :D
<FromGitter> <philfine> I need to get my head around of this generics.
<FromGitter> <philfine> From what I understand you can group events by subclassing a subclass as well :D
<FromGitter> <philfine> Very cool, IMHO.
<FromGitter> <philfine> @RX14 Thanks for your help :)
<RX14> np
<FromGitter> <philfine> TTY tomorrow
Nik736 has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<watzon> How can you redirect STDERR? In ruby you can actually reassign $stderr to a new IO, can you do that in Crystal?
rohitpaulk has joined #crystal-lang
faustinoaq has quit [Quit: IRC client terminated!]
<FromGitter> <graken> How can you have a list of classes that have a specific module included? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5a934a656fba1a703a9dbc20]
<FromGitter> <elorest> I'm trying to understand the Process run command. I can't find any documentation regarding the arguments. That being said it still seems as if something like this should work. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ Could anyone point me in the right direction? [https://gitter.im/crystal-lang/crystal?at=5a934c0de4ff28713ac6fcee]