<FromGitter>
<watzon> Hmm maybe a macro limitation from those dats
<FromGitter>
<watzon> You should be able to now, no problem
<postmodern>
does crystal have a better way of doing ruby select->maps? some kind of dynamic array builder method?
<FromGitter>
<tenebrousedge> there is an array.build
<FromGitter>
<tenebrousedge> is there some specific code you're trying to optimize?
<postmodern>
tenebrousedge, iterating a four element array, selecting C struct elements based on a type enum, then wrapping the C struct element. Feels like doing a select { }.map { } would be a bit wasteful.
<FromGitter>
<tenebrousedge> maybe `compact_map` and return `nil` for the ones you don't want to munge
<FromGitter>
<watzon> There's also reduce
<FromGitter>
<tenebrousedge> `reduce` can be used to write all other higher-order iterators, but I'd pick a more specialized iterator given the option
<FromGitter>
<watzon> Because `(i - 1) / Nk` should be a float
<FromGitter>
<watzon> And you're using that to access an index
<FromGitter>
<watzon> Doesn't compile in Crystal
<FromGitter>
<tenebrousedge> I'm not a big C expert, but are you sure that's a float?
<FromGitter>
<watzon> Maybe not. Tbh idk, just seems like it should be.
<FromGitter>
<watzon> But since Nk is a `uint8_t` maybe not
<FromGitter>
<watzon> Also in Crystal `key[4 * i].to_u32 << 24` overflows
<FromGitter>
<tenebrousedge> where is that?
<FromGitter>
<tenebrousedge> oh I see
<FromGitter>
<watzon> Maybe it's supposed to overflow :shrug:
<FromGitter>
<watzon> But that wouldn't make much sense
<FromGitter>
<watzon> C is weird
<postmodern>
hmm doesn't look like you can define spectator "it" specs within an .each block? suppose I need to use a macro
<FromGitter>
<watzon> Yeah. I think `it` specs create a `def`, so a macro would be the way to go.
<FromGitter>
<watzon> `{% for i in SOME_CONST %} ... {% end %}
<postmodern>
hmm .map(&->Operand.new) doesn't do what i expected it to do. isn't there a quick way to convert a an other classes class-method to a proc?
<FromGitter>
<tenebrousedge> usually you need to supply some type after `new`
<FromGitter>
<watzon> Fuck. The Crystal one is returning a `UInt8`
<postmodern>
is there a way to tell crystal to unroll loops at compile time? like say i want to convert an enum into a lookup table of enum element => Symbol, at compile time?
<FromGitter>
<watzon> Yep you can do that. `YourEnum.constants` inside of you macro will give you a list of the enum's values. Idk off the top of my head how you'd make the hash, but I know you can.
<postmodern>
siiiick
<FromGitter>
<watzon> Actually did something similar here
<FromGitter>
<watzon> But that's just making an array. The `"Tourmaline::UpdateAction::" + c.stringify` is necessary because `.constants` only returns the constant name, not the full path.
<postmodern>
hmm how do you read ASCII binary data with File.read?
<postmodern>
US-ASCII is still giving me `Caused by: Invalid multibyte sequence`
<FromGitter>
<watzon> That one I don't know. @bew might if he's still around, but iirc US-ASCII is a Ruby specific thing. I remember needing it before while porting a library and looking it up.
<postmodern>
where can i see the list of encodings?
ua has joined #crystal-lang
<FromGitter>
<bew> Hmm no idea, string encoding is managed by the iconv lib, you can find the list of encoding on there website i guess
<FromGitter>
<watzon> As far as I can tell it's basically just accessing the value at the given pointer. I'm not using pointers, so I just pass in an array and a index, access the value at the given index, and call swap on it. But I'm getting some *very* slightly different values than the C code gives
<postmodern>
how do you define a multi-dimension array?
<postmodern>
in a C struct, that is
return0e has joined #crystal-lang
return0e_ has quit [Ping timeout: 260 seconds]
HumanGeek has joined #crystal-lang
Human_G33k has quit [Ping timeout: 258 seconds]
<postmodern>
also odd that you can't define enum elements starting with a _
alexherbo26 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 268 seconds]
alexherbo26 is now known as alexherbo2
<postmodern>
if you pull in a shard, will it's dependencies also get pulled in as well?
alexherbo23 has joined #crystal-lang
alexherbo2 has quit [Ping timeout: 240 seconds]
alexherbo23 is now known as alexherbo2
return0e has quit [Remote host closed the connection]
<FromGitter>
<Blacksmoke16> Yes
return0e has joined #crystal-lang
return0e has quit [Ping timeout: 258 seconds]
return0e has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
return0e has quit [Ping timeout: 258 seconds]
return0e has joined #crystal-lang
return0e has quit [Read error: Connection reset by peer]
return0e_ has joined #crystal-lang
<FromGitter>
<dscottboggs_gitlab> @watzon what is the type of `p` in this case? Is it a `Pointer(UInt32)` or `Slice(UInt32)`? Or some other type which returns a `UInt32*` in response to `#to_unsafe`? β β Additionally, is there any chance `#as` is having a side effect here? What happens if you change it to `#unsafe_as`? β β Side note, I found it slightly confusing that you indexed the pointer instead of using `#value` but I
<FromGitter>
<dscottboggs_gitlab> postmodern, I think a two-demensional C-array would be a `Pointer(Pointer(ValueType))`. Or is it statically defined how many of each dimension there is?
<FromGitter>
<dscottboggs_gitlab> doesn't look like we can do StaticArray in libs? https://carc.in/#/r/8lxj
wakatara has joined #crystal-lang
<postmodern>
dscottboggs_gitlab, it's statically defined as uint8 foo[2][24]
<FromGitter>
<dscottboggs_gitlab> fack
<FromGitter>
<Blacksmoke16> @watzon you'll appreciate this
<FromGitter>
<Blacksmoke16> guess i finally found a use for `TypeNode#instance` ha
<FromGitter>
<dscottboggs_gitlab> @postmodern is that 24 pairs or 2 sets of 24?
<wakatara>
I am scratching my head over what should be a simple recursive function. I think it is perhaps something I do not get about ES6. Sure it's a "oh, it's this" type anser, can someone take a quick boo?
<wakatara>
I have a gist. I do not get why it is not returning the correct answer. :-/
<FromGitter>
<tenebrousedge> why are you using `sort`?
<wakatara>
tenebrousedge: lexographic double checking. Eventually this gets used in a frequency array to make a single base over a very large DNA sequence. It is just defensive programming.
<postmodern>
dscottboggs_gitlab, 2 rows of 24 elements. I suppose I could either define two fields of 24, or one field of 2 * 24
<wakatara>
(in case someone re-declared the base pairs out of order at some point in the future.
<FromGitter>
<tenebrousedge> wakatara you're returning 0 for the base case, which is going to make that entire term zero
<FromGitter>
<dscottboggs_gitlab> @postmodern yeah I think that's the only type-safe way to go about it here. For example https://carc.in/#/r/8lxm
<wakatara>
tenebrousage: that should be the final call for the function and what I was hoping returned a zero to the recursed function. But yeah, I know this approach works in python or similar, I am reimplmenting in js to make sure I understand all the algos. But I am hardly an expert in js.
<FromGitter>
<tenebrousedge> so what is the output supposed to be, and what are you getting instead?
<wakatara>
tenebrousage: Sorry, I meant the terminal function should return 0 to the "last" recursive call I would have thought. So, yeah, I do realize it is overriding all returns, rather than the third one made by the function (which obviously mens I don't understand return that well in js.)
<wakatara>
Tenebrousage: the function should recurse to give a 003 which I'd then convert to the integer 3. The output is in comment at the bottom.
<wakatara>
tenebrousage: It peels the last base, converts that and then recurses down the stack returning the value to the first retiurn (I would have thought) not returning 0 in total.
<FromGitter>
<tenebrousedge> wakatara why should this be recursive?
<wakatara>
tenebrousage: So, if I look at an example of a recursive factorial expression in js, it is similarly formed, the terminal condition does not override the value of the rursive return. :-/
<wakatara>
tenebrousage: It is vastly more efficient recursively when used with a frequency array.
<wakatara>
example a pattern of 9 bases has 4^9 combos to check. If you sort lexographically you can create an index and then just count the occurrences with one pass through the genome rather than sliding a 9 base window each base position.
<wakatara>
tenebrousage: The answer of 3 is if the bases were AAT. 3. 3 + (4 * 0) + (4 * 0) for the three passes.
<wakatara>
I guess my real question is why is js/node returning a 0 for the last recursive call that overrides the previous values?
<FromGitter>
<tenebrousedge> because `indexOf("A") == 0`
wakatara has left #crystal-lang ["ERC (IRC client for Emacs 26.3)"]
<FromGitter>
<tenebrousedge> maybe you want to add these numbers as strings instead, but I tend to doubt it
<FromGitter>
<636f7374> How to implement WebSocket automatic ping? Use fiber? I don't think it's time to wait for the official Crystal, this problem has been for some time.
return0e has quit [Remote host closed the connection]
<FromGitter>
<andrewc910> Can child classes be passed into methods where the type is a parent class? IE: method defines type string, you pass in a class that inherits from string.
<FromGitter>
<Blacksmoke16> yes
<FromGitter>
<Blacksmoke16> i wouldnt actually inherit from stdlib primitive types tho
<FromGitter>
<wakatara> Does anyone have any particularly strong examples of solid, small cli apps in Crystal they can point me at? I'm thinking of redeveloping 3 diff small apps to get my toes more than wet and could use some "best examples" to help me out before starting.
<FromGitter>
<tenebrousedge> @christopherzimmerman :plus1: super impressive
<FromGitter>
<636f7374> After solving the problem of automatic pong for WebSocket, I will temporarily suspend Crystal, switch to Rust, and research smoltcp & TUNTAP & IPsec.
<FromGitter>
<watzon> @postmodern I'd say it depends. If it's just a direct wrapper over a library and not adding much functionality on top of it I'd make sure to use the name of the library in the title so people know what it is. Like for my libfreetype wrapper I called it freetype.cr. If you're extending the C library I'd say call it whatever you want π€·π»ββοΈ
<FromGitter>
<watzon> Damn @asterite is on fire haha
<FromGitter>
<christopherzimmerman> Yea, opencl is pretty much done, just need to go through and write the bindings for the clblas and stuff for linear algebra, but custom kernels work great.
<FromGitter>
<christopherzimmerman> My graphics card doesn't have enough VRAM to really benchmark stuff well, but it's still neat to use
<FromGitter>
<watzon> That's awesome man. Very good work on all of this. I'm going to have to look through my projects and see where I'm using Apetite and swap it out for Bottle. I think my Cadmium/GloVe library will benefit heavily from OpenCL integration.
<FromGitter>
<watzon> Sure you could map over the Array, create a new Array of key value pairs, and then use `to_h`. But not only does that overcomplicate things and make for less readable code, it also performs unnecessary allocations in the middle.
<FromGitter>
<tenebrousedge> @watzon what's the difference there? what does the class method get you?
<FromGitter>
<watzon> Yeah probably pretty similar. I'm actually not a huge fan of `Array.build` the way it is now. With `Hash.build` I can't see any reason why the `Hash(K, V).new` part would be necessary though. It should be able to just point to the internal buffer. Basically I'm imagining something like this: β β ```def self.build(capacity, &block : Hash(K, V) ->) β hash = new β end```
<FromGitter>
<watzon> Yeah probably pretty similar. I'm actually not a huge fan of `Array.build` the way it is now. With `Hash.build` I can't see any reason why the `Hash(K, V).new` part would be necessary though. It should be able to just point to the internal buffer. Basically I'm imagining something like this: β β ```code paste, see link``` β β Basically it comes down to convenience and readability
<FromGitter>
<watzon> So I think I figured out the C macros I was having a hard time with last night, I just don't know how to do this in Crystal
<FromGitter>
<Blacksmoke16> recursion is going to be big, be much easier to do argument resolution for my DI shard
<FromGitter>
<Blacksmoke16> i dont know C so i wont be much help :p
<FromGitter>
<watzon> Basically the idea of the macros I was dealing with is thus: we're taking an array (which in C is a pointer) of 8 bit unsigned integers and inserting a 32 bit unsigned integer into it, so that one integer should take up 4 of those 8 bit slots in the array.
<FromGitter>
<watzon> So very very close. The top is the C output, bottom is Crystal.
<FromGitter>
<watzon> Got it!
<FromGitter>
<watzon> Holy fuck
<FromGitter>
<tenebrousedge> :plus1:
<FromGitter>
<oren> I creating a tiny static site generator and I don't want to rely on external html file that exist when running it. I would like to embed this file during compilation. How do I that?
<FromGitter>
<tenebrousedge> I think that someone has a shard for that, or you could use the `read_file` macro
<FromGitter>
<oren> interesting. so outside of the class?
<FromGitter>
<tenebrousedge> or wherever
<FromGitter>
<oren> and TEMPLATE will be available?
<FromGitter>
<tenebrousedge> it will have the contents of the file as a string
<FromGitter>
<oren> amazing!!
<FromGitter>
<watzon> Just make sure to do it outside of a function
<FromGitter>
<watzon> It's basically like copy pasting whatever you load in, so if it's inside a function it's going to be reallocating that string every time the function gets called
<FromGitter>
<watzon> Afaik anyway
<FromGitter>
<oren> Error: can only assign to variables, not Path
<FromGitter>
<oren> it doesn't like the TEMPLATE. it's ok with html_template
<FromGitter>
<tenebrousedge> you should assign it to a constant
<FromGitter>
<watzon> Where are you trying to do that? Have a code snippet?
<FromGitter>
<watzon> Compiler question: from a compilation standpoint is having one file that imports all the other files in your project different from having a user import things explicitly?
<FromGitter>
<watzon> And yes @oren, that lol
<FromGitter>
<oren> who is the user of your app/library? what does it do?
<FromGitter>
<oren> explain to me like i am 5 please (:
<FromGitter>
<Blacksmoke16> i doubt it? prob would take a tiny more amount of time, but in the end stuff that isnt used isnt included
<FromGitter>
<watzon> Well for now, me. I'm attempting to make a Telegram Client API framework, and the Telegram Client API uses an interesting form of encryption that isn't used basically anywhere else. IGE encryption, which is a derivative of AES. So I'm porting a well known C library to Crystal so that I can have it be *pure* Crystal, because stupid things like that are important to me for some reason.
<FromGitter>
<watzon> @Blacksmoke16 I figured as much
<FromGitter>
<watzon> CBC is an interesting algorithm
<FromGitter>
<oren> @watzon i just googled for telegram. it's a cloud-based messaging app. What API are you building for it and who is the user of this API?
<FromGitter>
<oren> "Telegram rolls their own βencryptionβ, which hasnβt been peer reviewed or attacked on a massive scale yet. I highly doubt that itβs actually secure. Signal uses well known and open protocols that have stood up over their lifetime." - https://www.reddit.com/r/privacy/comments/7fq16e/telegram_vs_signal/
<FromGitter>
<watzon> It has two API's. Their bot API is used for making bots that users can interact with, and the client API is used for making clients that users can log in to. The client API is also good for building userbots, or bots that are using a user account. I don't expect many people to use my library to begin with tbh since Crystal isn't very well known, but Crystal's speed is perfect for stuff like this, and post v1
<FromGitter>
... hopefully it will start getting more users.
<FromGitter>
<oren> (I did a quick google search since I use Signal and never heard about telegram)
<FromGitter>
<watzon> Also I've seen that article about Telegram vs Signal, but Telegram does have a pretty large reward for anyone that manages to break their encryption, and none have so far
<FromGitter>
<oren> ok. so if i want to build a crystal command line app that talks to my friends on telegram, am I a user for your library?