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
<postmodern> there's a C macro called __REDIRECT_NTH which sets up an alias using __ASMNAME (defined in /usr/include/sys/cdefs.h). Trying to replicate that in crystal the best i can.
<FromGitter> <tenebrousedge> crystal doesn't generally do aliases, and the PR/RFC for reusing bits of macros was opened like yesterday
<FromGitter> <tenebrousedge> at the moment if you want two macros with the same content you have to copy/paste :/
ur5us has joined #crystal-lang
<postmodern> ah __THROW is a C++ism
<postmodern> untangling these aliased macros is painful
<postmodern> appears if __USE_FILE_OFFSET64 is enabled, off64_t is typedefed to off_t, and mmap is __REDIRECT_NTH aliased to mmap64... man, C
dwdv has quit [Quit: quit]
<FromGitter> <watzon> C is a massive pain in the ass
<FromGitter> <watzon> Can confirm
_ht has quit [Quit: _ht]
<FromGitter> <watzon> So does the expectation `eq` have trouble with arrays?
<FromGitter> <watzon> Because right now `val1 == val2` returns true, but `val1.should eq(val2)` fails.
<FromGitter> <Blacksmoke16> :thinking: example?
<FromGitter> <watzon> This is so weird. This fails as well, but prints true. ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e5324328e726c7dc5c3a856]
<FromGitter> <tenebrousedge> o_______o
<FromGitter> <Blacksmoke16> dont suppose reading it alters its state or something
<FromGitter> <watzon> `encrypted.should eq(ciphertext)` also returns true
<FromGitter> <watzon> Nope
<FromGitter> <watzon> Ahh wait
<FromGitter> <watzon> I'm an idiot. It's the spec that comes with a new project that's failing lol.
<FromGitter> <Blacksmoke16> PEBKAC
* FromGitter * tenebrousedge makes Korean fried chicken (https://www.epicurious.com/recipes/food/views/korean-fried-chicken)
* FromGitter * watzon wants some
<FromGitter> <tenebrousedge> there will be extra, because I suck at portioning
<FromGitter> <watzon> Ok I'll be right over
DTZUZU has quit [Ping timeout: 268 seconds]
return0e has quit []
return0e has joined #crystal-lang
DTZUZU has joined #crystal-lang
oprypin has quit [Remote host closed the connection]
oprypin has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 2.7]
<FromGitter> <tenebrousedge> [Noms] (https://ibb.co/cvDrHb0). Plus some coconut rice
<FromGitter> <watzon> It would be kind of nice if you could allow integer overflowing for a specific block
<FromGitter> <tenebrousedge> what's the block?
<FromGitter> <watzon> ```if (iv[0] += 1).zero? ⏎ break ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e534770b662483a875f3b77]
<FromGitter> <watzon> Basically `iv` is an `Array(UInt8)` and if it overflows I want it to break
<FromGitter> <watzon> But not before incrimenting `iv[k]`
<FromGitter> <tenebrousedge> why not do `(a = a &+ 1)` ?
<FromGitter> <tenebrousedge> or rather
<FromGitter> <tenebrousedge> `if (iv[k] = iv[k] &+ 1).zero?`
<FromGitter> <tenebrousedge> it also has built-in job security
<FromGitter> <watzon> Huh, that works. Interesting. Never used `&+` before.
<FromGitter> <tenebrousedge> yeah it just wraps on overflow
<FromGitter> <watzon> So theoretically, this: ⏎ ⏎ ```for (k = AES_BLOCK_SIZE - 1; k >= 0; --k) ⏎ if (++iv[k]) ⏎ break;``` [https://gitter.im/crystal-lang/crystal?at=5e53498a89f30b1265281134]
<FromGitter> <tenebrousedge> `(0...AES::BLOCK_SIZE)` please
<FromGitter> <watzon> Ahh yeah, duh
<FromGitter> <tenebrousedge> but surely there's a better way
<FromGitter> <watzon> If only I understood C better
<FromGitter> <watzon> Right now I'm just trying to get the code transitioned and working, then I'll worry about making things a bit more Crystally
<FromGitter> <watzon> For now this is what I have: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e534a93c2c73b70a45566c1]
ur5us has quit [Ping timeout: 240 seconds]
<FromGitter> <watzon> Let me know if you see any obvious errors. ⏎ `def self.xcrypt(data : Indexable(UInt8), key : Indexable(UInt8), iv : Indexable(UInt8), state : Indexable(UInt8) = [0_u8]) : Array(UInt8)`
<FromGitter> <tenebrousedge> is the `to_unsafe` necessary?
<FromGitter> <tenebrousedge> it looks like you could do `^= chunk[state.first.succ]`
<FromGitter> <watzon> Idk if the `to_unsafe` is fully necessary. Arrays do get passed by reference right?
<FromGitter> <watzon> If so then probably not
<FromGitter> <watzon> But unfortunately `^= chunk[state.first.succ]` doesnt' work in this case
<FromGitter> <tenebrousedge> D:
<FromGitter> <tenebrousedge> it looks like it should 😢
<FromGitter> <watzon> Right now the first iteration works, but sequential iterations don't give the right result
DTZUZU has joined #crystal-lang
<FromGitter> <watzon> For instance
<FromGitter> <watzon> The first 16 bytes match, but after that it is all wrong
<FromGitter> <tenebrousedge> hmmmmmmm
* FromGitter * tenebrousedge shrugs
<FromGitter> <tenebrousedge> be smarter?
<FromGitter> <tenebrousedge> I have to prep another meal for tomorrow
<FromGitter> <tenebrousedge> shit, I don't have an orange
<FromGitter> <tenebrousedge> I have some grand marnier
<FromGitter> <watzon> Lmao trying to be smarter
<FromGitter> <watzon> I'll get this sooner or later
<FromGitter> <watzon> Ohh awesome. I can do this `iv[k] &+= 1`
<FromGitter> <watzon> Weird syntax, but it works
ur5us has joined #crystal-lang
DTZUZU has quit [Quit: WeeChat 2.7]
DTZUZU has joined #crystal-lang
* FromGitter * tenebrousedge shudders
ur5us has quit [Ping timeout: 240 seconds]
<Nilium> OK, I think I figured out my weird cache corruption issue -- if I run `crystal spec` via entr (or just run it twice in parallel), sometimes it'll start crystal spec once, kill it, and then start it again. This results in a cache that has to be destroyed if crystal can't figure out what it produced last time.
<Nilium> Wonder if there are any locks being checked on the cache
<FromGitter> <watzon> Fucking finally!
<FromGitter> <watzon> It lives!
<Nilium> Nice, I think.
<FromGitter> <watzon> Yes lol
<FromGitter> <watzon> Gotta write some more specs and then I'll push this code
<FromGitter> <watzon> Man this was a pain
ur5us has joined #crystal-lang
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
alexherbo2 has joined #crystal-lang
HumanG33k has quit [Ping timeout: 240 seconds]
<FromGitter> <ImAHopelessDev_gitlab> hi
<FromGitter> <mavu> Morning! ⏎ I need to generate some HTML from array-data, and I was wondering if there is a nice elegant way of doing "data.each do |x|" but get 2 values per iteration?
<FromGitter> <j8r> @mavu from where the array comes from?
<FromGitter> <mavu> Its possible settings, but never mind, I fond the documentation for Enumerable and .each_slice
<FromGitter> <mavu> The standard lib is the unnamed hero of Crystal.
_ht has joined #crystal-lang
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 260 seconds]
<FromGitter> <mavu> is this weird? ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5e53b7401ec15e021199aac3]
<FromGitter> <mavu> I would have expected both to be hashes?
<FromGitter> <straight-shoota> In Ruby the `{symbol: value}` is an alias for hash literals, but in Crystal its a NamedTuple literal.
<FromGitter> <straight-shoota> However, both named tuples and hashes with symbol keys are not really recommended in Crystal as arbitrary data containers.
<FromGitter> <straight-shoota> You should consider explicit struct/class type when the properties are known at compile time or a string based hash when properties are dynamic.
<FromGitter> <straight-shoota> These are strictly better solutions for the Rubyism of symbol keys in a hash
<FromGitter> <mavu> @straight-shoota But isn't symbol a type that is clearly defined at compile time? ⏎ I like to use symbols, because it visually distinguishes hash keys from some random string.
<FromGitter> <straight-shoota> Yes, symbols are defined at compile time. But that also means that instead of using a hash with symbol keys, you can typically use a dedicated type instead. For example using the `record` macro. That's way more performant than a hash and offers lots of additional features.
<FromGitter> <mavu> I'll have a look at that.
<FromGitter> <mavu> There is no equivalent to rubys ".send", is there?
<FromGitter> <straight-shoota> No
<FromGitter> <straight-shoota> That can't work with dynamic values because method calls are resolved at compile time.
<FromGitter> <mavu> I think I'm conceptualy stuck. cant see the forest through all the trees. ⏎ I have a class that holds the configuration of a service in its properties. ⏎ I am currently trying to itterate over all properties and do things. ⏎ how do I do that? [https://gitter.im/crystal-lang/crystal?at=5e53c2601ec15e021199d66e]
ht_ has joined #crystal-lang
_ht has quit [Ping timeout: 272 seconds]
ht_ is now known as _ht
<FromGitter> <mavu> Is there a way to iterate over properties of a struct? (or record?)
<FromGitter> <j8r> it is possible to iterate over ivars with a macro
<FromGitter> <cserb> Why is the type for @port at URI Int32 and not UInt32? (port will never be -3000) https://github.com/crystal-lang/crystal/blob/612825a53c831ce7d17368c8211342b199ca02ff/src/uri.cr#L107 (genuine question)
<FromGitter> <Blacksmoke16> `Int32` is just the default Int type
<FromGitter> <mavu> @j8r I'll see if I can make it work that way. Thanks.
<FromGitter> <j8r> @mavu https://carc.in/#/r/8m7e
<FromGitter> <Blacksmoke16> only works in context of a method tho ^
_ht has quit [Remote host closed the connection]
_ht has joined #crystal-lang
<FromGitter> <mavu> @j8r Thanks! That is nicer than mine i think (edited : https://carc.in/#/r/8m7h)
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
alexherbo2 has joined #crystal-lang
postmodern has quit [Quit: Leaving]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
chachasmooth_ has joined #crystal-lang
chachasmooth has quit [Ping timeout: 272 seconds]
<FromGitter> <j8r> @mavu you're welcome 😄
<FromGitter> <tenebrousedge> I want `reduce(0, &.+)` to be a thing. Can't we just capture the block, check its arity, and use either `yield` or `with memo yield` as appropriate?
<FromGitter> <watzon> I feel like that should be possible
<FromGitter> <watzon> Hmm, `#**` fails with `Int128` ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e53eb411c4f1707f8c9529a]
<FromGitter> <Blacksmoke16> `Int128` isn't fully supported atm iirc
<FromGitter> <watzon> Yeah I know :(
<FromGitter> <watzon> Just figured basic math would work haha
<FromGitter> <watzon> I'm writing a prime number generator based off of Ruby's so I can make a pure Crystal RSA implementation too
<FromGitter> <watzon> Was hoping I could go as high as `Int128`
<FromGitter> <Blacksmoke16> UInt64`?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/8m7z or use `UInt128` 😆
<FromGitter> <watzon> Damn it lol
chachasmooth_ has quit [Quit: Quit]
chachasmooth has joined #crystal-lang
<FromGitter> <watzon> I wish there was auto casting for ints. Like if something requires a UInt8 and you give it an Int32 that fits into a UInt8 it should work.
<FromGitter> <straight-shoota> @watzon see #8286
<DeBot> https://github.com/crystal-lang/crystal/issues/8286 (undefined reference to `__muloti4' (crystal 0.31.1-1))
<FromGitter> <watzon> Ahh ok I gotcha
<FromGitter> <asterite> Regarding "I want reduce(0, &.+)" . There's `sum`. What other use cases that's not `&.+` and `&.*` are there?
<FromGitter> <tenebrousedge> I had an array of procs that I wanted to reduce using `reduce([] of String, &.call)`
<FromGitter> <tenebrousedge> but capturing the block to check its arity seems to require explicitly typing it, as well
<FromGitter> <tenebrousedge> unless there's some macro method for that that I'm missing
<FromGitter> <watzon> @christopherzimmerman does `num.cr` have any implementation of the extended Euclidean algorithm?
<FromGitter> <watzon> I can't find it mentioned
<FromGitter> <j8r> Working on Swagger support - looking good so far! ⏎ I need to figure out how to have optional `class_getter` for a set of class subtypes of `T`, maybe with `macro finished`
<FromGitter> <Blacksmoke16> hm?
<FromGitter> <j8r> for instance, fo `QueryParameter`, having an optional description for this type
<FromGitter> <Blacksmoke16> annotation?
<FromGitter> <j8r> it is an abstract type, so for all its subtypes
<FromGitter> <j8r> Annotation? Good idea!
<FromGitter> <j8r> Annotations are perfect for optional things
<FromGitter> <Blacksmoke16> indeed
<FromGitter> <Blacksmoke16> i was more so imagining like `@[QueryParam(description: "some string")]`
<FromGitter> <Blacksmoke16> but yea
ur5us has joined #crystal-lang
<FromGitter> <watzon> Gonna be streaming some live coding on Twitch (https://www.twitch.tv/insomniaticdev) in about 30 minutes if anyone cares
<FromGitter> <watzon> Don't expect too much lol
<FromGitter> <mavu> "Alright Crystal, now you're just showing off. Tune it down, you're embarassing the neighbours." ⏎ ⏎ ```GET /xevit_logo.png - 200 (57.31µs)``` [https://gitter.im/crystal-lang/crystal?at=5e54334cd7bb4e179c9c74e3]
<FromGitter> <watzon> 😂
<FromGitter> <watzon> This coming from your framework @mavu?
<FromGitter> <mavu> its not a framework, just a bare https server serving minimal config interface, and thats one of the static files.
<FromGitter> <watzon> Ahhh ok
<FromGitter> <watzon> Yeah Crystal's HTTP server is insanely fast
<FromGitter> <mavu> the https is rendered in a more reasonable ⏎ ⏎ ```GET /webconfig - 200 (1.57ms)``` [https://gitter.im/crystal-lang/crystal?at=5e5433ca9aeef6523217586d]
<FromGitter> <mavu> :)
<FromGitter> <mavu> *html not https
<FromGitter> <Blacksmoke16> @watzon i thought of another cool thing you could do with that macro method PR
<FromGitter> <watzon> What's that?
<FromGitter> <Blacksmoke16> sec
<FromGitter> <christopherzimmerman> @watzon nope, never added it. I'm assuming you need it for private keys? Do you need just the gcd, or the coefficients as well?
<FromGitter> <watzon> Coefficient as well. It's for RSA.
<FromGitter> <watzon> I'm going to attempt to implement as many cryptographic algorithms as I can in pure Crystal
<FromGitter> <Blacksmoke16> @watzon so, symfony has a concept of compiler passes (https://symfony.com/doc/current/service_container/compiler_passes.html) for its DI container
<FromGitter> <Blacksmoke16> tl;dr you can alter the arguments/add/remove services from the container
<FromGitter> <Blacksmoke16> i.e. container is built => run compiler passes that can alter it => cache it
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e5459cd3e6ef64161722820]
<FromGitter> <Blacksmoke16> i essentially could do something similar, where imagine `ctx_hash` would be a hash of services and their arguments or ssomething
<FromGitter> <watzon> Hmm interesting concept
<FromGitter> <Blacksmoke16> yea, could prob do some pretty cool stuff with it
<FromGitter> <christopherzimmerman> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e545c64d7bb4e179c9ce0f1]
<FromGitter> <christopherzimmerman> @watzon do you have any test cases so I can verify?
<FromGitter> <watzon> Not currently, but that's awesome. Good work.
<FromGitter> <christopherzimmerman> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e545cbffa9f20553b4bf782]
<FromGitter> <christopherzimmerman> Scales to `n` dimensions as well
<FromGitter> <christopherzimmerman> Also broadcasts input efficiently
<FromGitter> <christopherzimmerman> I'll merge it into master if you want to test it out, I just glanced over the algorithm from wikipedia so it may need to be tweaked.
<FromGitter> <watzon> Yeah that would be great. Working on adding alternate AES implementations right now, but I'll be working on RSA soon.
<FromGitter> <watzon> This is so annoying. I'm getting an error about dynamic constant assignment, but it's not showing me where.
ur5us has quit [Ping timeout: 255 seconds]
<FromGitter> <watzon> Nvm I found it. Just a huge file.
<FromGitter> <Blacksmoke16> @watzon ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e545f4c9aeef6523217c16f]
<FromGitter> <Blacksmoke16> contrived example, but would be something like that i think
<FromGitter> <Blacksmoke16> 💯
<FromGitter> <Blacksmoke16> is macro time as well so you dont have any type issues, but they would still be caught, i.e. if you tried to set 2nd arg to `2` for example