<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>
<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
<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
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]
<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>
<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> 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>
<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> @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> 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> 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> 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