<FromGitter>
<tenebrousedge> returns `-1` for less than, `0` for equality, and `1` for greater than
<FromGitter>
<ilanpillemer> it really makes the semantics of the code clearer
<FromGitter>
<ImAHopelessDev_gitlab> hmmm
alex`` has joined #crystal-lang
<FromGitter>
<ilanpillemer> oooh.. I can get rid of the ugly brackets all over the place!
<FromGitter>
<ilanpillemer> `become left.not_nil! if parent.nil?`
<FromGitter>
<tenebrousedge> you noted how I did the delete `case` statement? Not that that's something to emulate, but it's good to know the technique
<FromGitter>
<ilanpillemer> yes. I liked that.
<FromGitter>
<ilanpillemer> I didnโt know that was possible.
<FromGitter>
<ilanpillemer> using assignment for Nil checks and then pattern matching is an interesting idiom too.
<FromGitter>
<ilanpillemer> I didnt know you could pattern match on classes
<FromGitter>
<ilanpillemer> that could be really neat for simple parsers.
<FromGitter>
<tenebrousedge> yep, case equality is convenient
<FromGitter>
<tenebrousedge> did you also happen to take a look at `Enum` ?
<FromGitter>
<ilanpillemer> I skim read it.. I saw you can give them methods too.
<FromGitter>
<tenebrousedge> I suppose. It's also possible to change their type (default is `Int32`, most things probably only need `UInt8`)
<FromGitter>
<ilanpillemer> your search kind of loses the performance of binary search.
<FromGitter>
<tenebrousedge> yes
<FromGitter>
<ilanpillemer> as you make it an array and then iterate!
<FromGitter>
<tenebrousedge> I'm lazy
<FromGitter>
<ilanpillemer> lol
<FromGitter>
<ilanpillemer> same with the iterator I guess too
<FromGitter>
<tenebrousedge> I like my `Enumerable` data structures
<FromGitter>
<ilanpillemer> I guess you want iterators for infinite things
<FromGitter>
<tenebrousedge> or things of uncertain length
<FromGitter>
<ilanpillemer> kind of like a generator
<FromGitter>
<tenebrousedge> yes
<FromGitter>
<tenebrousedge> going back to the protein-encoding problem
<FromGitter>
<ilanpillemer> gnight! that was fun. tomorrow evening I will start in the react one.
<FromGitter>
<tenebrousedge> good luck :/
<FromGitter>
<ilanpillemer> have you done that one yet?
<FromGitter>
<tenebrousedge> I've wrestled with certain parts. Some things I want to do are probably impossible
<FromGitter>
<ilanpillemer> So I will start wrangling with it tomorrow evening..
<FromGitter>
<tenebrousedge> I recommend a stiff drink
<FromGitter>
<ilanpillemer> Gin, lime and tonic!
<FromGitter>
<tenebrousedge> it won't help the coding but it might take some of the pain of the problem away
<FromGitter>
<ilanpillemer> I was trying to see how drunk I could get and solve AoC problems a few weeks ago.
<FromGitter>
<ilanpillemer> Managed to do one in a bleary state.
<FromGitter>
<ilanpillemer> Admittedly not a difficult one
<FromGitter>
<tenebrousedge> well, let me know how this one goes
hypercore has joined #crystal-lang
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 246 seconds]
_whitelogger has joined #crystal-lang
chemist69 has quit [Ping timeout: 246 seconds]
chemist69 has joined #crystal-lang
alex`` has quit [Ping timeout: 240 seconds]
alex`` has joined #crystal-lang
alex`` has quit [Ping timeout: 240 seconds]
<FromGitter>
<wwselleck> Say I wanted to create a function that took an object that looked something like this (pseudocode) โ โ ```code paste, see link``` โ โ And then I'd have to construct the class, making sure to pass the argument in the correct order. [https://gitter.im/crystal-lang/crystal?at=5d9d5ef997358746731f3851]
rohitpaulk has quit [Remote host closed the connection]
<FromGitter>
<repromancer_gitlab> Trying to follow along with Scott Wlaschin's F# book using Crystal, and there's this generic type definition that looks like this: โ โ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5d9de2bf874aeb2d23170f0b]
<FromGitter>
<repromancer_gitlab> I believe that's more or less the same as Crystal's `alias`
<FromGitter>
<Blacksmoke16> can just define the initializer in the parent and it will be in the children
<FromGitter>
<repromancer_gitlab> I actually did do exactly that at first, and not that I think about it, it may the correct analog the the F# code.
<FromGitter>
<repromancer_gitlab> I'll try to explain why I thought this was wrong. One second.
<FromGitter>
<Blacksmoke16> if you need the child to define its own initializer ( say for custom ivars or something), then you would do like `super data`
<FromGitter>
<repromancer_gitlab> Originally I wrote this out, and since the book hadn't specified yet what the `ChangeOrder` and `CancelOrder` would take, I just made a union called `Order`: โ โ https://play.crystal-lang.org/#/r/7qtu
<FromGitter>
<Blacksmoke16> should they be their own types, vs another property on `Order` like `status`?
<FromGitter>
<repromancer_gitlab> When I noticed that the union `OrderTakingCommand` was only a union of two distinct types, I got all weirded out, but actually I'm pretty sure the F# type system would do the same thing at this level of specificity.
<FromGitter>
<repromancer_gitlab> Yes, that's the line of thinking in the book.
<FromGitter>
<j8r> You can use an enum
<FromGitter>
<j8r> instead of records, and then the alias can be removed
<FromGitter>
<absolutejam_gitlab> `const isEmpty = require('loadash.isempty');` โ I need to import this?!
cpt_yossarian has joined #crystal-lang
<FromGitter>
<repromancer_gitlab> Unfortunately for my purposes (following along with the book), the different order states need to actually be distinct types. XD Though I agree, if I was just doing things a conventional way, your Enum suggestion would be the best choice. :)
<FromGitter>
<Blacksmoke16> whats the reason?
<FromGitter>
<repromancer_gitlab> I think I'm actually on the right track, though, going with your original suggestion @Blacksmoke16
<FromGitter>
<absolutejam_gitlab> and getting `undefined` if I try to access an object key that doesn't exist. There's parts I start to like then I Just get sad
<FromGitter>
<repromancer_gitlab> I think I was just overthinking it
snapcase_ has joined #crystal-lang
alex``` has joined #crystal-lang
confact_ has joined #crystal-lang
woodruffw has quit [Ping timeout: 268 seconds]
mjblack has quit [Ping timeout: 268 seconds]
confact has quit [Ping timeout: 268 seconds]
badeball has quit [Ping timeout: 268 seconds]
alex`` has quit [Ping timeout: 268 seconds]
snapcase has quit [Ping timeout: 268 seconds]
confact_ is now known as confact
<FromGitter>
<j8r> @repromancer_gitlab you know you can add class methods to the enum also
<FromGitter>
<repromancer_gitlab> The thesis of the book is to have the compiler enforce business rules via the type system, "making illegal states unrepresentable", that sort of thing.
<FromGitter>
<Blacksmoke16> isnt that what an enum is
<FromGitter>
<Blacksmoke16> would prevent you from setting `status` to anything that isn't defined in the enum
<FromGitter>
<Blacksmoke16> also would handle typos as it would error if you did like `:cancelled`
<FromGitter>
<Blacksmoke16> even tho its "right"
<alex```>
does "credit" take a "s" in "Give credit to A and B" ?
<alex```>
or it's singular
<FromGitter>
<absolutejam_gitlab> singular
<FromGitter>
<repromancer_gitlab> Right, but in this case I need a struct that can contain fields.
<FromGitter>
<repromancer_gitlab> the problem is that an Enum can't be used to model several distinct Structs underneath each key
<FromGitter>
<Blacksmoke16> true
<FromGitter>
<repromancer_gitlab> I need what's called a "choice type" in ML languages, and in Crystal, a union of distinct classes/structs is closer to that than an Enum
<FromGitter>
<Blacksmoke16> also cant use an enum members as a type restriction
<FromGitter>
<repromancer_gitlab> right, exactly
<FromGitter>
<repromancer_gitlab> I'm basically trying to see how much of OCaml/F#'s compiler-guaranteed-correctness that I can get out of Crystal, which I realize doesn't have exactly this sort of thing in mind.
<FromGitter>
<repromancer_gitlab> probably the biggest hurdle will be that `case` doesn't enforce exhaustive matching for union types (and I think it's only being considered as an option for Enum types)
<FromGitter>
<Blacksmoke16> there is an issue about that atm
<FromGitter>
<repromancer_gitlab> Basically, I need the compiler to be able to warn me when I expand an existing union type.
<FromGitter>
<repromancer_gitlab> so if `Order` is `UnvalidatedOrder | ValidatedOrder`, and I have a `case order when Unvalidated etc ...` somewhere, and I add some other state to the `Order` alias, I need the compiler to tell me "hey, your new Order subtype is not handled in that case statement you wrote months ago"
<FromGitter>
<repromancer_gitlab> which that RFC will definitely solve
<FromGitter>
<absolutejam_gitlab> I ran into this a while back and saved an example
<FromGitter>
<repromancer_gitlab> That's definitely a concern, if you're only writing a library for use elsewhere, for example. I believe the consensus is ensure checking by writing a test suite.
<FromGitter>
<repromancer_gitlab> if you have tests calling your functions, they'll no longer be dead code as far as the compiler is concenred.
<FromGitter>
<repromancer_gitlab> at least when the tests are compiiled
<FromGitter>
<kinxer> That's why library shards (ideally) need to have specs with more-or-less exhaustive code coverage.
<FromGitter>
<absolutejam_gitlab> half the shards don't even have a README
<FromGitter>
<kinxer> I evidently didn't read what @repromancer_gitlab had just sent...
<FromGitter>
<Blacksmoke16> i blame gitter
<FromGitter>
<kinxer> I'll just say I'm helping lend credence to those words. :P
<FromGitter>
<repromancer_gitlab> lol, well at least I've contributed something today to make up for my bikeshedding
<FromGitter>
<ImAHopelessDev_gitlab> gitter has an annoying bug where sometimes the scroll goes down but displays only half of the message. so i click on a pm and back t the crystal chat and it fixes it lol
<FromGitter>
<Blacksmoke16> ah, then in that case it should be
<FromGitter>
<ilanpillemer> hmm.. not trying to link to a solution
<FromGitter>
<ilanpillemer> just to the exercise
<FromGitter>
<tenebrousedge> the exercise definition isn't public
<FromGitter>
<tenebrousedge> for some reason
<FromGitter>
<ilanpillemer> "mplement a basic reactive system. โ โ Reactive programming is a programming paradigm that focuses on how values are computed in terms of each other to allow a change to one value to automatically propagate to other values, like in a spreadsheet. โ โ Implement a basic reactive system with cells with settable values ("input" cells) and cells with values computed in terms of other cells ("compute"
<FromGitter>
<ilanpillemer> I think I need that drink now
<FromGitter>
<tenebrousedge> ๐
<FromGitter>
<ilanpillemer> so how do you specify one or more Int32 for the input for the Proc?
<FromGitter>
<Blacksmoke16> afaik you cant
<FromGitter>
<ilanpillemer> seems to be a tuple
<FromGitter>
<ilanpillemer> so maybe you could put int a tuple with default values
<FromGitter>
<Blacksmoke16> you can convert a tuple to an array
<FromGitter>
<tenebrousedge> tuples have a definite size
<FromGitter>
<Blacksmoke16> nvm, the other way around
<FromGitter>
<Blacksmoke16> a tuple from an array
<FromGitter>
<tenebrousedge> I don't think that there's any way of avoiding overloading initialize
<FromGitter>
<tenebrousedge> I'd like to be wrong about that
alex`` has quit [Quit: WeeChat 2.6]
<FromGitter>
<Blacksmoke16> yea idt there is a way to set the type of a tuple to be n number of T
<FromGitter>
<Blacksmoke16> er variable number of T
<FromGitter>
<repromancer_gitlab> @ilanpillemer you could define a generic `NonEmptyArray(T)` and require a `NonEmptyArray(Int32)` as one of your arguments
<FromGitter>
<repromancer_gitlab> or just an `Array(Int32)` argument type?
<FromGitter>
<ilanpillemer> will that accept an Int32?
<FromGitter>
<tenebrousedge> but I haven't found a way to make those work here
MasterdonX has joined #crystal-lang
<FromGitter>
<tenebrousedge> so I have my *sauce espagnole* and another batch of beef stock. I'm not wild about the idea of making *demi glace* tonight, but it sounds better than working on this React problem
<FromGitter>
<tenebrousedge> @ilanpillemer how's it coming?
<FromGitter>
<ilanpillemer> I am about to stop for tonight
<FromGitter>
<ilanpillemer> trying to work out if its possible using `Proc`
<FromGitter>
<ilanpillemer> I have gone down a lot of dead ends
<FromGitter>
<tenebrousedge> I think that if it is possible, it requires generics