<FromGitter>
<kingsleyh> `type must be Pointer(Void), not Nil.class`
<FromGitter>
<kingsleyh> hmm
<FromGitter>
<kingsleyh> how do I say in my lib binding that I want EC_KEY to be either Int32 or NULL?
<FromGitter>
<kingsleyh> currently I have this: ` alias EC_KEY = Void*`
<FromGitter>
<kingsleyh> however a method call I'm using says: `return EC_KEY object or NULL if an error occurred`
<FromGitter>
<kingsleyh> so I can't do: myecc = the_meth_call() because it complains EC_KEY has to be Pointer(Void) and not Pointer(Void) | Pointer(Int32)
<FromGitter>
<kingsleyh> but also another C call I need later on says this: `return a BIGNUM with the private key (possibly NULL)`
<FromGitter>
<kingsleyh> so how can I make this work?
<FromGitter>
<kingsleyh> myecc = call_one() -> returns EC_KEY or NULL
<FromGitter>
<kingsleyh> myecc = call_two() -> returns BIGNUM or NULL
jemc has quit [Ping timeout: 246 seconds]
Renich has quit [Quit: Renich]
<FromGitter>
<kingsleyh> ok - how do I convert Slice(Int32) to Bytes
<FromGitter>
<girng> am not sure. if i knew c more i could prob help you am sorry
Renich has joined #crystal-lang
<FromGitter>
<kingsleyh> I guess each Int32 is 4 bytes - so I could convert it by grouping
<FromGitter>
<elorest> @proyb6 They use crowdsource.
<FromGitter>
<proyb6> You mean Bounty Source?
<FromGitter>
<elorest> Lol yeah
<FromGitter>
<proyb6> I have posted that in my Reddit's thread but Kickstarter could usually generate the highest amount in a timeframe
<FromGitter>
<girng> Does kickstarter have continuous payments per month, or is it just a one time donation thing?
<FromGitter>
<elorest> It's possible. Sort of an all or nothing though I think.
<FromGitter>
<proyb6> Kickstarter is one time but Indiegogo has "forever" crowdfunding, no deadline like a sales platform only for successful campaigns.
<FromGitter>
<elorest> I donate every month but I'd donate more to kickstarter if the price was getting Crystal 1.0 with multithreading. I don't even care about windows.
<FromGitter>
<proyb6> Yup, Indiegogo has flexible pledges that can be less than 100% while Kickstarter has to be 100% funded or nothing
<FromGitter>
<proyb6> I was a backers on both crowdfunding platforms but has good and bad experiences to how the campaigners wasn't able to deliver the hardware products. I decide to stop spending on risky campaigns, except Crystal is worth the investment so far.
<FromGitter>
<proyb6> @elorest I get undefined method for ```puts crossbit.power = 1```
<FromGitter>
<elorest> Thanks.
<FromGitter>
<elorest> I fixed that in a demo but forgot to push it. It will be up in a second. Need to include that in the specs.
<FromGitter>
<proyb6> Nice colours on ```to_s``` but I prefer vertical columns so any lengths can get long enough
<FromGitter>
<elorest> Thanks for catching that. It's fixed now.
<FromGitter>
<elorest> @proyb6
<FromGitter>
<elorest> I like being about the see the entire thing in binary as a line though too.
<FromGitter>
<elorest> I was thinking some sort of shell tables or something... but your suggestion might be best.
<FromGitter>
<anamba> Int64 ftw (AoC)
<FromGitter>
<girng> it's crystal time bby let's goooooooooo
<FromGitter>
<girng> @r00ster91 btw i gave up with that macro LOL. tried all day yesterday
<FromGitter>
<girng> btw why is macros so confusing? is it just me or is it hard to learn in general? because my mine just goes blank when i try to follow the gitbook on them. however, when i follow the gitbook on crystal lang itself, i can learn the language.
<FromGitter>
<Blacksmoke16> just the nature of them imo
<FromGitter>
<DanilaFe> Did anyone solve AoC part 2 in Crystal?
<FromGitter>
<girng> @Blacksmoke16 i just hope i'm not the only person :/
<FromGitter>
<Blacksmoke16> the more you use them it should get easier
<FromGitter>
<Blacksmoke16> helps to remember that they happen at compile time
<FromGitter>
<elorest> @girng the nature of meta programming is always harder than the language. Even if it's really easy like ruby keeping track of what modifies what and the scope of everything is difficult. ⏎ ⏎ Crystal is way easier than C/C++ thought
<FromGitter>
<girng> so i guess, the more you know the ins and outs of crystal, the better you are creating macros?
<FromGitter>
<Blacksmoke16> its really almost a language on its own :p
<FromGitter>
<elorest> Sort of but in crystal it is actually a separate language. But in general best practices in meta programming are the same.
<FromGitter>
<girng> i never even knew there was a thing called "meta programming" lol wtf.
<FromGitter>
<elorest> You could probably pick up on it really fast if you looked a few libraries in crystal that are macro heavy: ecr, slang, amber, that lib I just linked above. Or even look at ActiveRecord in Ruby/Rails.
<FromGitter>
<Blacksmoke16> i make good use of them and annotations
<FromGitter>
<Blacksmoke16> switch to the v0.5.0 branc tho
<FromGitter>
<girng> now that brings up a good point. i'm going to see if anyone has done videos on crystal macros. because since you mentioned the c/c++ macro, when i was learning c++ i was watching the cherno project's tutorials and then created a tcp server and it worked quite well. his macro tutorials have helped me a lot.
<FromGitter>
<girng> i don't feeel AS confused as i now... weird
<FromGitter>
<elorest> @Blacksmoke16 Could you look over https://github.com/elorest/bitfields for me. ⏎ It solves a use case for me but there might be a cleaner way to do it.
* FromGitter
* Blacksmoke16 googles what a bit field is
<FromGitter>
<Blacksmoke16> would be better to follow style guide in your readme
<FromGitter>
<Blacksmoke16> i.e. instead of `puts crossbit.temp` do `crossbit.temp # => what_it_prints`
<FromGitter>
<Blacksmoke16> makes it more clear when just reading thru it vs having to run it
<FromGitter>
<girng> okay i can't find 1 video on yt about crystal macros
<FromGitter>
<Blacksmoke16> :(
<FromGitter>
<girng> you know what would be really COOOL (imho). if Ary, Juan, or RX14, or anyone who is well versed in crystal can do a tutorial on them
<FromGitter>
<girng> that would be super helpful!!
<FromGitter>
<elorest> @Blacksmoke16 That's a good suggestion. Thanks.
<FromGitter>
<codematix> hello, i guess u get this a lot, but can somebody suggest me how i can debug my crystal programs? is there a debugger or REPL available?
<FromGitter>
<r00ster91> do you want the solution to read an instance var with a macro? it's actually quite simple
<FromGitter>
<r00ster91> you keep using def somehow but you can solve the problem by having only one macro in the class and the instance vars, nothing else
<FromGitter>
<girng> i almost got it
<FromGitter>
<r00ster91> ok
<FromGitter>
<girng> don't even need a def??
<FromGitter>
<r00ster91> nope
<FromGitter>
<r00ster91> you need to pass a created `Player` object to a `macro`
<FromGitter>
<r00ster91> and then generate code in this macro which operates on the `Player` object and modifies its instance variables
<FromGitter>
<girng> ok gonna try more
<FromGitter>
<r00ster91> I'd start with defining an `obj` argument
<FromGitter>
<girng> i feel like i'm so close with this
<FromGitter>
<dscottboggs_gitlab> I think this is what you're missing
<FromGitter>
<dscottboggs_gitlab> it's kinda like using ECR to write crystal on the fly
<FromGitter>
<girng> oh wow @r00ster91 you're just using the parameter values and basically copying and pasting them
<FromGitter>
<girng> i was looking at the macro api to see where those names came from lol
<FromGitter>
<girng> clever.....
<FromGitter>
<r00ster91> yea you just generate something with the arguments
<FromGitter>
<girng> '.id' removes the double quotes.. that's good to know!
<FromGitter>
<r00ster91> but do you know why there
<FromGitter>
<girng> does it add quotes to the integer too?
<FromGitter>
<girng> is that why .id is needed for that as well?
<FromGitter>
<r00ster91> no it doesn't do anything with `value`! try running it without ".id" after `value`. ⏎ It's just a bit safer because now what if the user wants to set the speed variable to a string instead? Well then the ".id" after `value` is needed
<FromGitter>
<girng> oh it works
<FromGitter>
<girng> without `.id` after value. oh i get it, safer. yeah
<FromGitter>
<girng> good point
<FromGitter>
<girng> okay this about my max peak of macro learning. i'm done wth macros for a while, ty all for the help / encouragement !
<FromGitter>
<dscottboggs_gitlab> so `"string".id` gives you `string`, `:symbol.id` gives you `symbol`.
<FromGitter>
<girng> where does the value get set then? to what??
<FromGitter>
<girng> what instance variable is it choosing
<FromGitter>
<mpcjanssen> Note the unused parameter help
<FromGitter>
<girng> strength or dexterity
<FromGitter>
<mpcjanssen> neither
<FromGitter>
<bew> `@name`
<FromGitter>
<girng> WTF LOL
<FromGitter>
<mpcjanssen> it's using the instance var name which is written as @name
<FromGitter>
<girng> but that's my return...
<FromGitter>
<girng> i'm returning the instance variable (last line of a method)
<FromGitter>
<mpcjanssen> you are always setting or retreiveing the name instance variable
<FromGitter>
<mpcjanssen> the string you pass to [] is not used at all
<FromGitter>
<mpcjanssen> the instance variables you define in the beginning are also not used at all
<FromGitter>
<girng> and i never did `property name`
<FromGitter>
<mpcjanssen> not needed
<FromGitter>
<mpcjanssen> property names is only needed if you want to access it outside of the class
<FromGitter>
<girng> i thought only instance variables can be created in initialize, or property macro. they can be created on the fly in random methods? wtf??
<FromGitter>
<bew> Iirc it's ok when they are nilable
<FromGitter>
<bew> (i personally don't like that but hey..)
<FromGitter>
<girng> TIL
<FromGitter>
<bew> Try to use `crystal tool expand` on a `property` macro, so you understand what it exactly does
<FromGitter>
<bew> Spoiler, it generates a getter and a setter
<FromGitter>
<mpcjanssen> as soon as you try to do something with this @name instance variable, Crystal will tell you this can be nil. See https://play.crystal-lang.org/#/r/5qj6
<FromGitter>
<mpcjanssen> the only way to prevent this | Nil in the type is to initialize the instance var in the constructor or class body.
<FromGitter>
<mpcjanssen> it would be nice if Crystal would give an unused parameter warning when compiling though
<FromGitter>
<bew> What if you don't need it?
<FromGitter>
<mpcjanssen> then why is it in the signature then?
<FromGitter>
<girng> ima craft something up with rooster's macro code one second
<FromGitter>
<mpcjanssen> other languages use the _ name to indicate you really don't need it (for example in callbacks)
<FromGitter>
<bew> And you have to have it somehow (abstract class, inherited signature (override)
<FromGitter>
<bew> The compiler don't give warnings, only errors, but for warning or style hints you could use ameba
<FromGitter>
<mpcjanssen> I would even be OK with this being an error. It will prevent @girng 's issue. I'll check ameba
<FromGitter>
<girng> i'm special nn to make other people suffer warning over my brain
<FromGitter>
<mpcjanssen> if you want to document what parameters you are not using _name is also allowed.
<FromGitter>
<mpcjanssen> ISTR OCaml does it like that
<FromGitter>
<mpcjanssen> elixir as well
<FromGitter>
<mpcjanssen> +1 on not generating warnings by the compiler.
<FromGitter>
<girng> omg i'm really getting sad. i thought i found a solution and everything. i did EVERYTHING wrong
<FromGitter>
<bararchy> yuo can use `ameba` it tells you about unsued params
<FromGitter>
<girng> as usual with everything i try to do in real life, i always get screwed over can't do anything by myself always have to have others helping me. can NEVER do it
<FromGitter>
<bew> Don't worry too much, you're learning and mis-mixibg everything @girng, it's normal when you're starting with a new thing
<FromGitter>
<bew> Maybe try this, try to do a `my_property` that does the same as the normal `property`
<FromGitter>
<bew> And younre not allowed to use the macros from the stdlib
<FromGitter>
<girng> grrr
<FromGitter>
<girng> back to watching ary's macro video
<FromGitter>
<girng> i can do this
<FromGitter>
<mpcjanssen> sounds like you are trying to run before you can walk. Do you understand. 1) Why getters and setters are needed. 2) How you would write your own? Only then it would make sense to look into how the getter,setter and property macros abstract this away.
<FromGitter>
<girng> how the hell do we access the property value with an index operator???
<FromGitter>
<girng> (that accepts a string)
<FromGitter>
<bew> This exact thing you're trying to do is not possible in macros, and is a limitation of crystal: you can't use macros like instance methods
<FromGitter>
<bew> Try something simpler, it'll be more rewarding
<FromGitter>
<girng> went through that 2 hours ago, i thought i found the solution and then found out i've been bamboozled!
<FromGitter>
<girng> i'
<FromGitter>
<mpcjanssen> @girng why do you insist on p["property"] instead of p.property ?
<FromGitter>
<girng> @mpcjanssen i have a skill tree system for my game on the server and the nodes modify the player's values. i jut want to do it in one loop instead of hundreds of ifs
<jokke>
ah never mind
<FromGitter>
<dscottboggs_gitlab> @gring I posted the only valid solution for using `# ()` to access instance variables earlier
<FromGitter>
<mpcjanssen> @girng if you map the skills as a hash, you don't need all this magic
<FromGitter>
<girng> yes ik
<FromGitter>
<bew> @girng note that he's using `Player.modify`, not `player.modify`
<FromGitter>
<girng> i don't want to use a hash for my player's stats i like to do dot notation in code
<FromGitter>
<dscottboggs_gitlab> I would also strongly recommend trying to do @bew's excercises
<FromGitter>
<girng> that's why i like property...
<oprypin>
the macro is entirely inconsequential for the goal you're starting
<oprypin>
stating
<FromGitter>
<dscottboggs_gitlab> understanding what `property` does is like step one to understanding macros in crystal
<FromGitter>
<dscottboggs_gitlab> did you read the macros section of the Crystal Book?
<FromGitter>
<girng> yes....
<FromGitter>
<girng> and i am waatching ary's video now about 2 times now
<FromGitter>
<dscottboggs_gitlab> have you played with `crystal tool expand` at all?
<FromGitter>
<dscottboggs_gitlab> There isn't any way to add a macro as an instance method, right?
<FromGitter>
<dscottboggs_gitlab> (I'm asking)
<FromGitter>
<girng> how do i use that, like `crystal tool expand property`?
<FromGitter>
<girng> doesn't work on WSL
<FromGitter>
<dscottboggs_gitlab> hang on I'll send a bash one-liner in a sec
<oprypin>
girng, if you want to explain what you're actually trying to do, we might find a very simple solution. right now you seem to be deep in XY problems
<oprypin>
this was a promising start: <558b2f@girng> i don't want to use a hash for my player's stats i like to do dot notation in code
<oprypin>
no I mean this one <558b2f@girng> @mpcjanssen i have a skill tree system for my game on the server and the nodes modify the player's values. i jut want to do it in one loop instead of hundreds of ifs
<FromGitter>
<mpcjanssen> @girng just use a hash for the skills instead of trying to wrap it in instance variables and macros
<FromGitter>
<dscottboggs_gitlab> @gring run this cat << EOF > /tmp/crystal-expand-example.cr && crystal tool expand -c "/tmp/crystal-expand-example.cr:2:3" /tmp/crystal-expand-example.cr master * ] 5:19 AM ⏎ class Tester ⏎ property test_val = "a value" ⏎ end ⏎ EOF [https://gitter.im/crystal-lang/crystal?at=5c0cec35178d7860a1ab598c]
<FromGitter>
<girng> all i want do it access a property value with a string. and be able to set it using index notation (that accepts a string). i thought i first found a solution to it here: https://play.crystal-lang.org/#/r/5qik/edit but that's now what the code is doing. and the macro solution from @dscottboggs_gitlab seems to be it, but it's a lot of macro code that i don't understand and if i just use his code, i feel like i
<FromGitter>
... have not learned anything in this process. and the code from @r00ster91 works perfect, but it's different because it's doing `Player.modify(player, "speed", 12)`. i am just trying to do `player["speed"] = 12`
<FromGitter>
<dscottboggs_gitlab> really, TBH, @girng, you shouldn't be accessing variables by their string refernces because at compile time they are no longer referenced by name but by memory location.
<oprypin>
I strongly suspect that it's not actually what you want to do and is not helping you do what you actually want
<FromGitter>
<mpcjanssen> you have two issues here, running without knowing how to walk and an x-y problem
<FromGitter>
<mpcjanssen> macros are almost never the solution
<oprypin>
ALWAYS remember that macros are only a way to reduce boilerplate.
<FromGitter>
<girng> omg oprypin yes it does because skill tree nodes in my game can have multiple things that modify the player's properties. increase hp, str, dex, or whatever. there are hundreds of nodes that a player can choose from. if i were to do it manually it would be hundreds of if statements. if i could just access them by a string, then i can just do 1 loop and boom. if i change my player stats to hashes, then i can't
<FromGitter>
... use DOT NOTATION in my code, which is my preferred way of accessing property values
<oprypin>
if you can write out the repetitive code manually, you can probably simplify it with a macro
<oprypin>
if not, well, then you literally can't do it in any way
<FromGitter>
<mpcjanssen> Girng is you skill set fixed?
<oprypin>
ok, don't change anything to hashes, use properties
<FromGitter>
<dscottboggs_gitlab> the code you are trying to write is something that is from interpreted languages. ⏎ ⏎ in an interpeted lanugage, when you write a method/function, it's stored as a function pointer in a hash table so that it can later be referred to by its string value in a semi efficient way. In a compiled language, it simply looks for all of those references to that method name and replaces it with a function
* FromGitter
* mpcjanssen confused you are trying to use [] access but now you say you prefer . notation
<FromGitter>
<dscottboggs_gitlab> yeah that too
<oprypin>
please write out the feared repetitive code that you want to simplify, then we'll find a way to apply macros
<oprypin>
mpcjanssen: i think girng is just struggling to use any of the two as long as it somehow works
<FromGitter>
<mpcjanssen> mixing the two is breaking it
<FromGitter>
<mpcjanssen> just keeping it simple just works
<FromGitter>
<girng> i mean i like to use dot notation throughout my code.. and if i were to switch to hashes i'd have to use stats["xx"] instead of stats.speed or whatever. i like dot notation. but if i'm doing 1 loop to modify my player's stats, i can't do that with dot notation it has to be a STRING! i mean, i guess i can just do rooster's macro? it works but i just really want the index operator way personally.
<FromGitter>
<girng> i could do it with dot notation, but i twould be a LOT OF if statements!
<oprypin>
ok write them out
<FromGitter>
<mpcjanssen> why if statements?
<FromGitter>
<girng> cause dot notation
<oprypin>
i don't know and i just want to see them
<FromGitter>
<mpcjanssen> how is player.speed = 0 different from player["speed"] = 0 unless you have a skills.each somewhere ?
<oprypin>
yes, it is not different at all
<FromGitter>
<girng> cause `speed` is from `property speed`
<FromGitter>
<mpcjanssen> so?
<FromGitter>
<girng> i can't do player["speed"]
<FromGitter>
<girng> if it's a property speed
<FromGitter>
<dscottboggs_gitlab> @girng
<FromGitter>
<mpcjanssen> no you do player.speed
<FromGitter>
<mpcjanssen> what does that break?
<FromGitter>
<dscottboggs_gitlab> please. take a deep breath
<FromGitter>
<dscottboggs_gitlab> sorry
<oprypin>
this is all pointless omg.
<FromGitter>
<girng> yeah but that means i need to write out tons of if statements to handle all the nodes from the skill tree. i'd rather prefer 1 loop
<oprypin>
macros only simplify existing repetitive code
<oprypin>
until you know exactly what that code is, everything you're trying is pointless
<oprypin>
i want to see that code
<FromGitter>
<mpcjanssen> @girng that conclusion doesn't follow
<FromGitter>
<mpcjanssen> you mean p.speed = value if skill == "speed"
<oprypin>
with all those 100 ifs (well, just 5 is enough for an example) - and make the code as realistic as you can
<FromGitter>
<dscottboggs_gitlab> could you explain what you mean by "handle all the nodes in the skill tree"? like what would you do to each node as you were iterating over them?
<FromGitter>
<mpcjanssen> just use p[skill] is value and get over your dot preferemce
<oprypin>
@mpcjanssen pls
<FromGitter>
<girng> @mpcjanssen am sorry not good at explaining things
<FromGitter>
<mpcjanssen> I think you are worried about doing: p.speed = value if skill == "speed" etc.
<oprypin>
I'm not asking you to explain BTW
<FromGitter>
<mpcjanssen> I know, just trying to help @girng to explain
<FromGitter>
<dscottboggs_gitlab> I agree with oprypin, I'd like to see a minimal example
<FromGitter>
<dscottboggs_gitlab> no rush I've got my own code to write :p
<FromGitter>
<j8r> @girng you can also learn more on macros from the stdlib. You may be interested in JSON.mapping and Serializable implems. What you're trying to do is probably lying somewhere. I can recommend your to read even more others Crystal code, we learn a lot 😄
<FromGitter>
<girng> @mpcjanssen yeah that's exactly it. i'd have to write out separate if statements for every diff node then. using that code you have. cause each node, could have 1 or multiple player properties it modifies. for example, i have a node that gives increased hp, and strength. i'd have two ifs, just to handle that 1 node, which would do player.strength += 10, and player.health += xxx. and that's just ONE node! the
<FromGitter>
... player can choose up to 100+ nodes for their tree.
<FromGitter>
<girng> does that help explain it better?
<oprypin>
ok we're wasting time tho. show the 100 ifs without macros, pls.
<FromGitter>
<girng> i havn't written them yet lol
<FromGitter>
<j8r> Minimal example to fix?
<oprypin>
that's where you start when trying to apply macros
<oprypin>
your end goal is to get the same code that you would have written manually, but in an automated way
<FromGitter>
<girng> either i ahve to write them all out, or i can use a macro. i guess i can use rooster's macro, it should work but i just feel like i've cheated myself. cause i spent all this time and i still can't create a index operator macro :( :(
<oprypin>
so you need to have a good idea of what the code actually is
<FromGitter>
<mpcjanssen> @girng yes. 1) You want to use instance variables because you prefer. player.strength. 2) You have modifications to a lot of skills where the skill names are strings. 3) You don't want player.skilla = value if skill = "skila"
<oprypin>
I'm sure it would be quicker to write out at least 5 ifs and show us, rather than finding excuses
<FromGitter>
<mpcjanssen> changing any of the 3 requirements will make the solution easier
<oprypin>
mpcjanssen pls
<Yxhuvud>
@DanilaFe Yes. Deque FTW
<FromGitter>
<girng> sure, i'll just use rooster's macro. so much for me trying to LEARN then. all i do is spend time and try to learn how to do something MY way and guess what it never happens. ever. everything i've ever done in my life has NEVER been by myself, always relying on someone else. i'm an online beneficiary it seems like, i hate it
<oprypin>
girng, just so u know, rooster's macro is entirely pointless
<FromGitter>
<girng> how????
<oprypin>
it rewrites `modify(player, "speed", 12)` to `player.speed = 12` but "speed" must be constant, if you change it to a variable it will break
<oprypin>
if you want to actually get anywhere, you must post an example of repetitive code that you want to reduce. if that's too much to ask, you can continue ignoring me and never actually learn anything
<FromGitter>
<girng> i don't mean to ignore you and i apologize if it comes off that way
<oprypin>
i understand that it's not targeted at me
<FromGitter>
<girng> @mpcjanssen interesting. now that i'm thinking of thatlooking at that
<FromGitter>
<dscottboggs_gitlab> @gring write what you want to without using any macro. If you can't do that you won't be able to write a macro to do it at all, because macros have to expand to valid code.
<FromGitter>
<girng> the amount of if statements i have can never supersede the amount of property xxxx's i have
<oprypin>
that is actually a good example, i missed that. just that @mpcjanssen did the work of making an example instead of you (including guesswork)
<FromGitter>
<girng> oprypin i already knew
<FromGitter>
<girng> that's what i HAVE TO DO
<FromGitter>
<dscottboggs_gitlab> what?
<oprypin>
yeah YOU knew but none of us knew
<oprypin>
(only mpcjanssen bothered to guess)
<FromGitter>
<j8r> @elorest i'd recommend not to use inheritance for such a small lib: it forces people to either choose a struct or a class. (But it doesn't matter if you are in the end application)
<oprypin>
girng, and that is the problem with many of your questions
<oprypin>
we don't know what you know
<FromGitter>
<j8r> Just give us an example to fix
<FromGitter>
<girng> @op
<oprypin>
now that we have a good example (and this does actually happen to be the only way to achieve this effect), we can proceed to simplify repetitive code
<FromGitter>
<girng> @oprypin if you log on gitter, and scroll up to 2,3,4 + hours ago (and look at my post from yesterday about the macro question), you'd see that i was trying to do things on my own instead of merely posting ""this is my problem, plz fix!!"". wouldn't you rather have me try to learn on my own?
<FromGitter>
<dscottboggs_gitlab> @girng I was there and I posted the only solution that is going to provide the syntax you want
<FromGitter>
<dscottboggs_gitlab> as I also mentioned a while ago
<oprypin>
girng, step 1 is stating your problem. I looked slightly above but did not see statement of the problem you're trying to solve. you were only stating problems with implementing one particular way of solving your problem (which happens to be impossible)
<oprypin>
trying to do impossible things is not exactly the best way to learn
<FromGitter>
<girng> yeah i appreciate it dearly. i was just trying to figure it out on my own too. and i can't do it and i would feeel guilty / cheated if i were to use your code
<FromGitter>
<j8r> Here the problem isn't there is one, but what it is exacly? We better understand Crystal than English
<FromGitter>
<dscottboggs_gitlab> well if there's something you don't understand about what I posted I'd be glad to help you understand
<oprypin>
yes, this solution by @dscottboggs_gitlab can work. it would just be nice to get to it from the bottom up
<FromGitter>
<dscottboggs_gitlab> it's just frustrating what we're all struggling to communicate this simple example
<oprypin>
what's frustrating is that we're not even sure if this example is applicable because we have no base example to work with
<FromGitter>
<girng> it is bcz we can access property xx by string
<FromGitter>
<dscottboggs_gitlab> true.
<FromGitter>
<girng> that's all i asked
<FromGitter>
<dscottboggs_gitlab> My example wouldn't apply if @gring were attempting to access only a particular subset of ivars
<FromGitter>
<dscottboggs_gitlab> but do you get how/why it works?
<FromGitter>
<girng> nope
<FromGitter>
<dscottboggs_gitlab> is there a particular part you don't get?
<FromGitter>
<girng> tons of things i don't understand let me list them 1 second
<oprypin>
if you have the time to explain each separate component, sure, go for it
<oprypin>
but I think that @girng will come out of this only understanding how this particular example works but still being unable to work with different cases
<oprypin>
what I'm aiming to do is have an example with 0 macros in it and then building up to increasingly better ways to apply macros to reduce boilerplate
<FromGitter>
<dscottboggs_gitlab> that's a fair point
<FromGitter>
<proyb6> I suggest it's best to write out the specifications in plain text and then discuss before implement it
<FromGitter>
<girng> 1) why is there {% and {{ ⏎ 2) the first def[] operator doesn't even return anything, so how is it returning the value? ⏎ 3) the []= operator doesn't return a value as well (from what i can see) ⏎ 4 i just tried to use {{}} in my example (https://play.crystal-lang.org/#/r/5qll) earlier (from Ary's video) trying to do my custom index operator, and it said variable not found. but you are using {}'s with no
<FromGitter>
<girng> that's just off the top of my head on why it's so confusing
<FromGitter>
<girng> what differentiates between {% and {{ and why are they different
* FromGitter
* mpcjanssen suspects a big part of the answer is moving the update_skills part into the player class instead of updating all the skills at each and every point. After that a macro is probably not even needed anymore.
<oprypin>
nah the macro is fine
<FromGitter>
<dscottboggs_gitlab> ok so lets take this one at a time...
<FromGitter>
<proyb6> It'd
<oprypin>
when taking one at a time, i'd start with https://play.crystal-lang.org/#/r/5qln - this is what i've been begging @girng to provide for the last hour
<oprypin>
girng, do you understand this code?
<FromGitter>
<girng> problem with that is it will bloat my player class on each instantiation with a huggggee skill_tree update method
<oprypin>
methods are not duplicated during instantiation.
<FromGitter>
<dscottboggs_gitlab> 1: `{%` delimits macro statements. These statements change whether code is generated or how much of it. `{% if false %} "this code would not be a part of the final compiled code" {% end %}`
<oprypin>
oh my
<FromGitter>
<mpcjanssen> @girng and reducing the huge update method might be a possible use for a macro, but no way to know until you try
<FromGitter>
<dscottboggs_gitlab> inside of macro statements, one can access macro variables in regular statements using `{{`
<FromGitter>
<dscottboggs_gitlab> you can only work with constants inside macro statments
<FromGitter>
<dscottboggs_gitlab> But like he said he already read that
<FromGitter>
<girng> @oprypin wouldn't it be better to just create a function then, and just pass the player obj. then not every single player class will have a huge method attached to it
<FromGitter>
<mpcjanssen> there is only one player class
<oprypin>
mpcjanssen, yes, the point is to end up with that, but actually understand it
<FromGitter>
<mpcjanssen> there are multiple instances of player
<FromGitter>
<mpcjanssen> but that huge method is not attached to every instance
<FromGitter>
<girng> multiple
<FromGitter>
<girng> @dscottboggs_gitlab thank you. so {% is for conditional statements only
<FromGitter>
<girng> and {{ is to use variables
<FromGitter>
<dscottboggs_gitlab> I don't think `applySkills` works as you think it does @mpcjanssen
<FromGitter>
<girng> why can't we just do {{}} why even have a {% that makes it extremely confusing
<FromGitter>
<girng> i don't understand how that is "returning a value"
<FromGitter>
<girng> all it is is a case, when and raise
<FromGitter>
<girng> so confusing >_<
<FromGitter>
<dscottboggs_gitlab> so if the class that that contains has the instance vars `strength` and `agility` then that macro would expand to the following code at compile time
<FromGitter>
<dscottboggs_gitlab> this would change based on which instance variables the class has, but would not be changeable after the source has compiled
<FromGitter>
<girng> okay that makes sense
<FromGitter>
<girng> that code example
<FromGitter>
<dscottboggs_gitlab> and the whole case returns whatever the return value of whatever branch it follows
<FromGitter>
<girng> ohhh i see
<FromGitter>
<girng> the `then`
<FromGitter>
<girng> `You may use then after the when condition to place the body on a single line.`
<FromGitter>
<girng> so it is returning @{{ivar.id}}
<FromGitter>
<girng> you just did it in one line
<FromGitter>
<mpcjanssen> nope
<FromGitter>
<dscottboggs_gitlab> yes
<FromGitter>
<dscottboggs_gitlab> sorry
<FromGitter>
<mpcjanssen> the macro expands to @{{ivar.id}}
<FromGitter>
<girng> wait ima try something with ur example
<FromGitter>
<mpcjanssen> which then evaluates to for example @strength
<FromGitter>
<girng> makes sense now. okay was thinking wtf it returning lolz
<FromGitter>
<bew> \o/
<FromGitter>
<girng> @dscottboggs_gitlab ❤✌✌
<FromGitter>
<girng> omg. that's what i was thinking @name was doing
<FromGitter>
<girng> the `@{{ivar.id}}` part, returning the `@name`
<FromGitter>
<girng> but that aint in a macro.. herp a derp
<FromGitter>
<dscottboggs_gitlab> haha
<FromGitter>
<dscottboggs_gitlab> so, here's my thing
<FromGitter>
<girng> okay i'm go back to mine and see if i can do this now. i think i got it
<FromGitter>
<dscottboggs_gitlab> (deviating from our discussion but kinda related)
<FromGitter>
<dscottboggs_gitlab> doing that is super ineficcient. wouldn't it be better to sort the branches and find the one that you're trying to access using the sorted conditonal branch than iterating over all of them one at a time? I.E. wouldn't it be better to store a `Hash(String, ???)` where `???` is a way of pointing to the method you wish to call. However, as far as I know, there's no way to store a reference to a method
<FromGitter>
... as a variable in crystal?
<oprypin>
dscottboggs_gitlab, you understand that your solution throws everything at once and is hard to explain. you understand that just explaning the building blocks doesn't work. you understand that I was trying to explain it from the other direction. please also understand that by directly presenting your explanation (which is more attractive on the surface) you removed my opportunity to explain.
<oprypin>
dscottboggs_gitlab, for that scenario you could do a double-pronged approach and have a hash from string to integer, and then `case` on integers, which should have a direct/efficient implementation. needs verification (by inspecting generated code). and who knows, maybe strings also have an efficient implementaton
<FromGitter>
<dscottboggs_gitlab> oh, shit, I'm sorry, I didn't mean to step on your toes!
<oprypin>
well, my attitude didnt help either
<FromGitter>
<proyb6> @rx14 We like to have the forums soon 😕
<FromGitter>
<dscottboggs_gitlab> it's okay we were all getting frustrated and trying to talk too fast.
<FromGitter>
<dscottboggs_gitlab> it happens
<RX14>
forums are coming in the next week
<FromGitter>
<proyb6> 👍
<RX14>
probably sooner rather than later
<FromGitter>
<girng> @dscottboggs_gitlab so what's going on here? https://play.crystal-lang.org/#/r/5qly shouldn't it return the list of my instance variables?
<FromGitter>
<dscottboggs_gitlab> > then case on integers, which should have a direct/efficient implementation. ⏎ ⏎ by this you mean that at compile time the language handles the cases by sorting them rather than picking one at a time as if it were `if..elsif..else`?
<FromGitter>
<proyb6> The first post would be sponsor 😎
<FromGitter>
<bew> I guess it's using the getter method
<FromGitter>
<bew> But it's very unintuitive
<oprypin>
dscottboggs_gitlab, sorting doesn't really help. the way that `switch` is implemented in C (and the whole point of it, and the reason why it works only for integers) is that it's basically using `goto`. it doesn't translate to `if`s, it just immediately jumps to an address corresponding to the incoming value
<oprypin>
dscottboggs_gitlab, it just happens to have a string representation `[strength]`
<FromGitter>
<girng> terry davis implemented a faster c switch in holy c i heard
<FromGitter>
<bew> *how to mix everything*
<FromGitter>
<girng> @dscottboggs_gitlab i used p! and it shows
<FromGitter>
<girng> @dscottboggs_gitlab should i use p! when debugging / fiddling around in macro code for now on?
<FromGitter>
<girng> cause obviously puts doesn't like me
<FromGitter>
<dscottboggs_gitlab> YES
<FromGitter>
<bew> @girng `puts` and `p!` and variants are runtime debugs
<FromGitter>
<girng> yah was just saying puts basically nukes @type.instance_vars
<FromGitter>
<dscottboggs_gitlab> p! is a macro which displays the variable's string representationa and reeturns the value of that variable. `puts` displays the variables value converted to a string and returns `nil`
<FromGitter>
<girng> p! shows the correct output of @type.instance_vars on my playground, puts only shows [5]
<FromGitter>
<dscottboggs_gitlab> they each do different things and you should use them for what they do
<FromGitter>
<dscottboggs_gitlab> @oprypin thanks that helps a alot
<FromGitter>
<girng> i think it'd be nice to mention p! in gitbook macro area
<FromGitter>
<dscottboggs_gitlab> I think it's mentioned elsewhere but it would make a good example for that section
<FromGitter>
<girng> i thought {% was for conditional statements
<FromGitter>
<dscottboggs_gitlab> yes conditional generation of code
<oprypin>
:D
<FromGitter>
<girng> hmmm
<FromGitter>
<dscottboggs_gitlab> *every macro must expand to valid crystal code before being inserted back into the code at the place where it was referenced*
<FromGitter>
<girng> FFS
<FromGitter>
<dscottboggs_gitlab> in the case of macro literals they just get reinserted back in in place of the macro literal
<FromGitter>
<dscottboggs_gitlab> statements delimited with `{% %}` denote the beginning and end of macro literals
<FromGitter>
<girng> so we can continue to put regular crystal code
<FromGitter>
<dscottboggs_gitlab> yes
<FromGitter>
<girng> even if it's inside a {% conditional statement
<FromGitter>
<girng> so think of the conditional statements as separate lines, and it's your own world in between them
<FromGitter>
<girng> where regular crystal code is legal
<FromGitter>
<dscottboggs_gitlab> the stuff inside the {% conditional determines wehther or not to generate the code. It's instructions to the compiler, not a part of the resulting code
<FromGitter>
<girng> and {{ can only be used inside the {%, correct?
<FromGitter>
<dscottboggs_gitlab> yes or between `macro...end` statements
<FromGitter>
<girng> the block yah
<FromGitter>
<girng> okay i think i got it
<FromGitter>
<girng> i was thinking every conditional statement had to be inside {% lol
<FromGitter>
<girng> hey @dscottboggs_gitlab thanks man ttyl!!
<FromGitter>
<dscottboggs_gitlab> np hope to talk more another time! :)
<FromGitter>
<girng> 👍✌
<FromGitter>
<proyb6> Win a Macro badge!
<FromGitter>
<kingsleyh> so the C library I'm trying to use says it returns BIGNUM `const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *key);`
<FromGitter>
<kingsleyh> but the bindings I created with crystal_lib gave this: `fun EVP_PKEY_get_raw_private_key(pkey : LibC::Int*, priv : UInt8*, len : LibC::Int*) : LibC::Int`
<FromGitter>
<kingsleyh> how do I correctly get the contents out ?
<FromGitter>
<kingsleyh> it's returning a pointer currently
<oprypin>
kingsleyh, are u sure you're looking at the right thing? because you named two different funcctions. EC_KEY_get0_private_key, EVP_PKEY_get_raw_private_key
<FromGitter>
<kingsleyh> sorry sorry I meant this one: ` fun EC_KEY_get0_private_key(pkey : LibC::Int*) : LibC::Int*`
<FromGitter>
<kingsleyh> how do I get a bignum out of it in Crystal?
<FromGitter>
<kingsleyh> I don't know what to do with the Pointer(Int32)
<FromGitter>
<kingsleyh> obviously the_pointer.value.to_big_i - is not what I want
<oprypin>
i have no idea what crystal_lib does
<FromGitter>
<kingsleyh> Crystal_lib generates bindings for C libs
<oprypin>
anyway.. kingsleyh, it is quite clear here that libssl doesn't want you to know or care what exactly BIGNUM is. i would recommend `type BigNum = Void*` and change the wrong occurrences like this `Int32*` to just `BigNum`
<FromGitter>
<kingsleyh> Hmm I’ll try that
<FromGitter>
<kingsleyh> It seems strange that the return type should be Void*
<oprypin>
the point here is that it returns some pointer that you don't care what it is but you can pass it to other things that expect the same kind of pointer
<oprypin>
`type` then ensure some type safety to not intermix different kinds of `void*`s
<FromGitter>
<kingsleyh> I see
<oprypin>
i still dont know why crystal_lib calls it an int32
<jokke>
asterite: you already finished day 9?
<jokke>
just so i know: is there another way than inserting and deleting from an array? part 2 is running for ages already.
<jokke>
i don't want to know the solution
<jokke>
but only if it's possible
<oprypin>
jokke, btw what metric does the leaderboard track?
<jokke>
it is explained under ordering
<jokke>
or ordre
<jokke>
*order
<oprypin>
so is it only who solves it first? what about time zones
<jokke>
it's tough luck
<jokke>
i would have to get up at 5 am to be among the first
<jokke>
or 6
<oprypin>
thats dumb then. killed any last spark of interest
<jokke>
👍
<jokke>
because you think timezones can't be faked :P
<Yxhuvud>
proyb6: I used them last in todays advent of code! they are effective alternatives to arrays if you only edit in the end or start. Queues for example do well based on a Deque.
DTZUZO has joined #crystal-lang
<FromGitter>
<proyb6> I saw that and I think a similar one in Go AOC
<FromGitter>
<kingsleyh> @proyb6 well now I'm getting back a Bignum struct :) but not sure how to get the value out of it
<FromGitter>
<proyb6> @yxhuvud Ring buffer is the fastest among the languages but what could be a good use case?
<oprypin>
kingsleyh, i'm telling you, you're not supposed to get the value from it. use one of the other API functions that accept BIGNUM
<oprypin>
it says, use BIGNUM as an opaque value and stop digging around
<jokke>
Yxhuvud: hm
<oprypin>
bignum_st is not defined anywhere in /usr/include, meaning that even if you managed to get its members, you'd be relying on undocumented / incompatible implementation details
<FromGitter>
<kingsleyh> oprypin - but there are not any other functions on ec.h that look like they will take a BIGNUM and return the private key - also the function does say it supposed ot return BIGNUM with the private key!
<jokke>
Yxhuvud: i recognized the pattern of how marbles are inserted but it's broken each time a multiple of 23 comes along. so even if i used this max 22 elements long chain and merged it efficiently with the existing marbles i would "only" have an improvement by factor 22
<FromGitter>
<kingsleyh> unless you mean something like this: BN_bn2hex
<oprypin>
BN_bn2dec could get you there, sure
<FromGitter>
<kingsleyh> gah - why is it so complicated!
<oprypin>
is C
<Yxhuvud>
jokke: Perhaps you should try to figure out what part of what your code is doing that is slow and fix that, instead of overthinking number stuff.
<jokke>
well the inserting and deleting is slow i guess. i'm only iterating once after all
<jokke>
because it will have to shift the elements
<Yxhuvud>
Right. So how do you make that faster?
<FromGitter>
<kingsleyh> oprypin - so this gives me back a Pointer(UInt8)
<FromGitter>
<proyb6> Oh I see, I forgot about String.new(n)
<FromGitter>
<proyb6> Thank for the code!
<oprypin>
kingsleyh, could also add BigInt.new from that
<oprypin>
but i dont know what you're looking to do with the private key next
<oprypin>
if it's just to pass to another libssl function, you dont need to get a crystal value from it. because now that you have this as a crystal value, to pass it to something in libssl you'll have to convert it back to libssl's bignum!
<FromGitter>
<kingsleyh> I want the hex value of the private and public keys - but also I will need to sign and verify using them
<oprypin>
ah, well then BN_bn2hex will be the hex
<FromGitter>
<kingsleyh> then after that I want to do some diffie-hellman stuff to encrypt data using the curve
<FromGitter>
<kingsleyh> I think I get it now though - I had the wrong mindset
<FromGitter>
<kingsleyh> I'm going to assume that if a return type is a Void* that I have to pass it on to another function to get the value out
<oprypin>
yes
<oprypin>
it is typical that C apis don't let you mess around with their structs but only provide functions to work with them
<FromGitter>
<girng> `TreeDataMainNodeTypes = Hash(String, Hash(String, String | Float32 | Hash(String, String | Float32))).from_json(File.read "./Data/tree_data_main_node_types.txt")` ⏎ trying to clean up that union a bit
<oprypin>
that example is obsolete.
<oprypin>
recursive aliases themselves were not removed (barely) but all usage was removed
jemc has joined #crystal-lang
<FromGitter>
<girng> i was thinking of something when i made my csv to dictionary script in gdscript. i think JSON.parse is amazing. and imo it would be really cool and make the life of the developer a lot easier, if we could simply specify which key/values are what types when using JSON.parse. either during, or after. i was reading over the 5155 issue and read the `dig` part, but not sure if that's the same thing
<mps>
I'm trying to upgrade crystal on Alpine Linux but build command 'abuild check' which call 'make spec' fails with '14988 examples, 5 failures, 0 errors, 12 pending' message
<mps>
four of these errors are ' raises when port is negative'
<mps>
can I remove these checks from build system and have crystal 0.27 for next stable Alpine Linux
<FromGitter>
<greenbigfrog> 1) 27.0 is broken on alpine linux. ⏎ Should be able to build master AFAIK
<mps>
officially there is no 0.27.0 on Alpine
<mps>
last is 0.26
jemc has quit [Ping timeout: 240 seconds]
<FromGitter>
<greenbigfrog> yes, there is no 0.27.0 because it didn't build on alpine... You'll need to build master
<mps>
I built 0.27, only these five tests fails. I'm not sure if the master will be accepted in the next stable Alpine release
<mps>
would be nice to have 0.27 in next stable Alpine
S0bait has joined #crystal-lang
<RX14>
0.27.0 builds on alpine
<RX14>
and i know that, because the official releases are built on alpine
<mps>
RX14: yes, it builds but five test fails
<RX14>
meh
<RX14>
they fail on my machine too
<RX14>
just do whate everyone else does and ignore them
<mps>
I do, but build system doesn't
<RX14>
comment it out in the APKBUILD
<mps>
is that safe?
<RX14>
do you have an alternative?
<mps>
well, no. I thougt to remove these tests from spec
<mps>
so the rest can be tested
<RX14>
i'd s/it/pending them
<mps>
actually I made apk by skiping test
<RX14>
if you were a distro packager i'd say make them pending
<RX14>
if you're building it for yourself then just skip tests
<mps>
I'm trying to have it in next stable Alpine
<mps>
it is quite fine works on my box
<RX14>
then you'll want to see if any of the spec failures have been patched upstream, and backport any patches, and then make the rest pending using another patch
<mps>
yes, a lot of work
<mps>
RX14: btw, you are one of the core devs of crystal?
<RX14>
yeah
<mps>
and you develop on Alpine?
<RX14>
no, i develop on arch
<mps>
ah, ok. but you build official crystal on Alpine, if I understood you correctly?
jemc has joined #crystal-lang
<RX14>
yes, so we can statically link correctly
<RX14>
because glibc makes that stupidly difficuly with nss
<RX14>
and "just build on alpine" is the easiest way to use musl
<mps>
good, another reason for me to try to push new version on next stable
<RX14>
the binaries built by the official crystal compiler are for the standard glibc triple however
<RX14>
so we only really validate 1 binary works on alpine: the compiler
<RX14>
we don't use the official distro crystal packages in the build process either
<mps>
ofc, have seen on download page
<mps>
good, will see what I can do. thanks for help and explanations
<RX14>
if any of the spec failures aren't already reported on the issue tracker, please do
<RX14>
and a list of the spec failures would be helpful so I can chase them up to be fixed
<mps>
four of them are about negative ports in socket/server tests
<mps>
one is from http test
<RX14>
if you could pastebin the output that'd be the most useful
<mps>
I can post issue numbers here in about one hour. I'm not behind my working box now
<mps>
ofc, I can but in a hour, approximately
<RX14>
ah, ok
<RX14>
thanks
<mps>
thank you!
<RX14>
sorry about being grumpy
<mps>
don't worry, I have thick skin ;)
<mps>
didn't even noticed that you are grumpy
<mps>
thought that you are kind
<FromGitter>
<kingsleyh> Oprypin thanks for your help earlier was very useful :)
<oprypin>
np :)
<FromGitter>
<kingsleyh> Btw I was in Silicon Valley last week exhibiting and speaking at a blockchain conf - and when I started talking about Crystal people were very interested in learning more
jemc has quit [Ping timeout: 246 seconds]
DTZUZO has quit [Ping timeout: 246 seconds]
<FromGitter>
<j8r> one minute I thought grumpy was a Python frameworks, but that's numpy (and also the mood of RX14) ;D
<FromGitter>
<bhargavrpatel> Whats the ideal way to document modules and classes? Coming from Python world, typically,we use an unused multiline string which is magically attached to object.__file__
<FromGitter>
<j8r> @bhargavrpatel just comments above
<mps>
eh, and I remember that when started to learn crystal that was a first serious problem I had with crystal :)
<RX14>
what problem?
<mps>
HTTP graceful shutdown
<RX14>
oh, that's easy, just call .close on the server object :)
<mps>
well, I reported problem here but solved it by counting opened connections
<mps>
IIRC, you and straight-shoota helped me about that
<RX14>
hmm
<mps>
straight-shoota even put it as issue on github
<mps>
five-six months ago, IIRC
<RX14>
mps, there's some really weird coupling between the HTTP server integration specs
<RX14>
@straight-shoota if you run HTTP specs in a random order i bet they wont pass half the time
<RX14>
this needs fixing
S0bait has quit [Quit: Connection closed for inactivity]
<RX14>
mps, basically, you making one spec pending has made the next spec fail, which is insane
<FromGitter>
<straight-shoota> that's bad
<FromGitter>
<j8r> ideally each spec should be independent
<FromGitter>
<j8r> but not sure it's always possible
<RX14>
no, it's always possible
<RX14>
if it's not true it's bugged
<FromGitter>
<markrjr> @straight-shoota I'm a little confused, isn't ``hostname`` already a macro in the system spec?
<FromGitter>
<markrjr> What exactly is the hack?
<FromGitter>
<j8r> but if we test deleting something, we depend on the adding method?
<FromGitter>
<markrjr> And for number of processors, should I use the env macro or the ENV module? Just curious about common practice there.
<FromGitter>
<straight-shoota> @markrjr No, it executes at runtime. That won't even compile on win32 because the backtick method ``` #`` ``` isn't omlemented
<FromGitter>
<j8r> obviously cpu count can't be compile time
<FromGitter>
<j8r> you can put the binary in various systems (even more if statically linked)
<FromGitter>
<straight-shoota> Specs always need to use runtime values. They must be able to execute on a different system than they're compiled on.
<FromGitter>
<markrjr> Gotcha.
<FromGitter>
<straight-shoota> the workaround is to replace `` `hostname` `` with ``{{ `hostname`.stringify }}``
<RX14>
@straight-shoota if you make the HTTP::Server "handles exception during SSL handshake" pending you can reproduce the closes gracefully check
<RX14>
i'm pretty sure it's some kind of file descriptor reuse
<FromGitter>
<elorest> @j8r ⏎ ⏎ > @elorest i'd recommend not to use inheritance for such a small lib: it forces people to either choose a struct or a class. (But it doesn't matter if you are in the end application) ⏎ ⏎ Thanks. I had gone with a class since I needed to have some non attribute instance methods (`to_slice`, `to_s`) which didn't seem appropriate on a struct. Maybe in Crystal that's fine though?
<RX14>
@straight-shoota it literally works if you add a Fiber.yield before the closes gracefully spec :/
<FromGitter>
<straight-shoota> @RX14, ooops, there's a `server.close` missing
<RX14>
where?
<RX14>
in the spec that we just didn't run? yeah there is
<FromGitter>
<straight-shoota> in the `handles exception during SSL handshake` spec
<RX14>
so the one which we just made pending
<FromGitter>
<straight-shoota> right
<RX14>
so which isnt the problem
<FromGitter>
<j8r> @elorest huh? diffs between struct vs class is passing by value/reference, and stack/heap allocation
<FromGitter>
<straight-shoota> however, on my machine the specs still pass with that one pending
<RX14>
what is your machine?
<RX14>
wsl?
<FromGitter>
<straight-shoota> probably a WSL issue
<RX14>
eugh
<RX14>
wsl is terrible
<FromGitter>
<j8r> @elorest in you lib both can be used, I don't see malocs, pointers
<FromGitter>
<straight-shoota> yeah
<FromGitter>
<straight-shoota> > so which isnt the problem ⏎ ⏎ But it might help masking it
<RX14>
no, the fact that the spec inbetween yields is whats masking it
<RX14>
which i proved by adding Fiber.yield at the start of the spec and everything working fine
<RX14>
it's an FD being reused i'm sure of it
<RX14>
since FDs are allocated sequentially, specs end up reusing FDs often
<FromGitter>
<elorest> @j8r Thanks. While your here I'd like to hear your opinion on my current method of breaking it all out into instance variables in initializers and dumping the new slice with a method. ⏎ ⏎ vs ⏎ ⏎ parsing bytes each time a getter/setter is called. [https://gitter.im/crystal-lang/crystal?at=5c0d722426de6f0822ab01ba]
<RX14>
so if there's a FD which is closed, and then the next spec recreates the FD
<RX14>
a fiber from the old spec - if it isnt woken up - can end up using the new fd
<FromGitter>
<j8r> @elorest sounds a bit strange to be a class/struct because there is no ivar shareds across methods. Except if I missed something
<FromGitter>
<straight-shoota> So part of the issue is leftover fibers hanging around?
<RX14>
yes
<RX14>
and probably 2 IO::FileDescriptor objects with the same FD
<FromGitter>
<straight-shoota> If we only had something like #6468 ... :P
<FromGitter>
<elorest> @j8r Are you talking about how it currently is or my other suggestion?
<RX14>
wouldnt solve the root cause, just make the specs pass
<RX14>
crystal shouldn't require perfect concurrency management not to get weird bugs
<RX14>
it should be able to cope with errors
<FromGitter>
<straight-shoota> It would help to isolate specs. Makes sure no fibers of other specs are still running
<RX14>
i know
<RX14>
but my point is that thats not going to happen in real programs
<RX14>
and we both know it
<FromGitter>
<j8r> @elorest currently. For your suggestion, I don't know yet 😅
<FromGitter>
<straight-shoota> Not arguing against that
<RX14>
so by making the specs *correct* we are masking over the real bug
<RX14>
which is that crystal isnt reporting this error
<FromGitter>
<straight-shoota> yeah
<FromGitter>
<elorest> > @elorest sounds a bit strange to be a class/struct because there is no ivar shareds across methods. Except if I missed something ⏎ ⏎ @j8r Maybe I don't get what you're saying. ⏎ ⏎ Currently `initialize` breaks up all of the bytes into currect instance variables. ... [https://gitter.im/crystal-lang/crystal?at=5c0d73fd8b656e2b04eacbf0]
<FromGitter>
<kingsleyh> seems I can either free the EC_KEY or the EC_POINT but not both
<FromGitter>
<elorest> @j8r I tried something similar to that while testing this but I'll read through that code and rethink it. Thanks.
<FromGitter>
<elorest> Are there any documents on using Annotations? They seem new in the last few months.
<FromGitter>
<Blacksmoke16> tl;dr
<FromGitter>
<Blacksmoke16> are accessed like `ivar.annotation(MyAnnotation)`
<FromGitter>
<Blacksmoke16> where `ivar` would be from a like `{% for ivar in @type.instance_vars %}`
<FromGitter>
<Blacksmoke16> but `@type.instance_vars` only works within the context of a method
<FromGitter>
<vladfaust> I'm sorry ro interrupt; ama trying to extend all `Enumerable`s with class static method, got no luck. Any clues of how to do it right? https://carc.in/#/r/5qse
<FromGitter>
<Blacksmoke16> can add some data into the anotation like `@[MyAnnotation(name: "Foo")]`
<FromGitter>
<Blacksmoke16> when you can then get from like `ivar.annotation(MyAnnotation)[:name]`
<FromGitter>
<Blacksmoke16> which will be a `NilLiteral` if it isnt set
<FromGitter>
<elorest> @Blacksmoke16 Ok. So i'm still sort of missing the point I guess. Is this sort of a replacement for storing values in constants?
<FromGitter>
<markrjr> @straight-shoota Should I also comment out the check `$?` using the status variable since the CI tests fail and Process isn't available on Windows?
<FromGitter>
<markrjr> It looks like $? is nil if you execute the command from a macro.
<FromGitter>
<j8r> @elorest sadly annotation aren't very documented. Excepting @asterite , @Blacksmoke16 is one of the most advanced sensei 😄 . I hope someone will add a section in crystal docs :|
<FromGitter>
<j8r> @vladfaust is good in annotations too of course!
<FromGitter>
<vladfaust> Indeed I am 😏 They are not hard, and you know that, @j8r
<FromGitter>
<DanilaFe> @Yxhuvud I considered it, but I thought it wouldn't work as well since some deletions are 7 past the current. In retrospect, you could probably pop from one end and insert into the other to keep the circularity going.... but a linked list seemed like a more suited solution for the problem, especially a circular one.
<FromGitter>
<DanilaFe> I'm a little upset though because last time AoC bumped in the input size, it was because there was an algorithm that wasn't simulation-based. So I spent quite some time trying to find a better solution rather than optimizing my code
<FromGitter>
<elorest> @vladfaust So is length now going to return 42 for all ivars I annotate with it? Or can I dynamically set that somehow?
<FromGitter>
<elorest> I'm going to play with that snippet you sent over.
<FromGitter>
<vladfaust> @elorest it's going to be set for `@foo` only
<Yxhuvud>
@danilafe: well. there is a #rotate method to keep it doing well. And it is plenty fast enough - I clock my 17 lines in at 100ms for both solutions.
<FromGitter>
<elorest> Seems similar to what were previously called attributes? I don't see how this could replace what I'm currently doing. Must be missing something but my current macro syntax is pretty clean. ⏎ ⏎ ```# bf value : type, size ⏎ bf name : UInt8, 15``` [https://gitter.im/crystal-lang/crystal?at=5c0d81a51e86c30823513243]
<FromGitter>
<elorest> I'll try to put together a similar example in carc.
<FromGitter>
<elorest> @vladfaust I've simplified this a lot for the sake of an example. How would I use annotations to accomplish the same thing. ⏎ ⏎ https://carc.in/#/r/5qsy
<mps>
that is main reason I'm trying to make it work on the next stable, as you know alpine is switching to openssl from libressl
<RX14>
@vladfaust idk
<RX14>
all that time and broken releases to add libressl support and alpine switches back as soon as it's merged
<mps>
probably I could just rebuild 0.26 but I like to have new crystal release in new alpine
<RX14>
of course
<mps>
well, there were long thread on alpine-devel ML about that
<FromGitter>
<vladfaust> @elorest huh. You cannot define `def {{name.id}}` with `for ivar in @type.instance_vars` because it's empty in macros (but not empty withing methods). You could have defined a `def bit_count` method instead
<RX14>
i'll add mbedtls support to crystal :P
<mps>
eh, interesting
<RX14>
i probably wont for a long while unfortunately
<mps>
would be nice option, I think
<RX14>
kaniini convinced me it was the only ssl library which didnt suck
<mps>
I would like it to run on armv7, but will wait till it be ready
<mps>
RX14: now I have to prepare some official works, thank you for the help and good night
<RX14>
no problem
<RX14>
have a good one
<mps>
probably I will contact you again if I need help for making crystal packaged for next stable alpine
<RX14>
cool, i'd love to help
<mps>
good night, again :)
<FromGitter>
<elorest> @vladfaust Thanks. I think I'm understanding the usefulness of annotations now. I don't think my current project is a good use case for them though.
<FromGitter>
<vladfaust> One day there will be no dynamic constants in the language, and your shard will not work
<FromGitter>
<elorest> At that point most of the ORM's and half of awesome-crystal will stop working too. Do we know when that point will be? I'm not apposed to using it but it doesn't seem possible to accomplish what I'm trying to accomplish using annotations. As you said it was possible to get a total count but not individual methods for where they began and ended.
<FromGitter>
<elorest> Could I set and create annotations from within macros?
<FromGitter>
<vladfaust> Yes, you can
<FromGitter>
<vladfaust> So you can make your DSL wrap annotations
<FromGitter>
<vladfaust> > At that point most of the ORM's and half of awesome-crystal will stop working too ⏎ ⏎ As *someone* said, "maybe every second shard shouldn't abuse macros then" 😏
<FromGitter>
<elorest> Ok I'll start playing with that then. Could I do something similar to my example but store my values in an annotation instead of a constant? In some cases it's useful to have the constant because I use it at run time too.
<FromGitter>
<elorest> > As someone said, "maybe every second shard shouldn't abuse macros then" ⏎ ⏎ Many things aren't possible without macro's for instance ECR or Slang. Is there an alternative other than just not using them?
<FromGitter>
<elorest> It's not like macro syntax is actually fun or anything...
<FromGitter>
<vladfaust> Unfortunately, modifying annotations isn't possible (yet?) https://carc.in/#/r/5qta
<FromGitter>
<bhargavrpatel> I am trying to start multiple TCP Server on a random port; I'd like to retry if port is already in use. However, from what I see, the exception raised is not easily "exceptable".
<FromGitter>
<Blacksmoke16> sorry had to step away for a bit
<FromGitter>
<Blacksmoke16> can also add annotations to methods
<FromGitter>
<elorest> @bhargavrpatel If the port is already in use it's error is probably in e : Errno
<FromGitter>
<Blacksmoke16> but i dont think there is an easy to like know what annotations are on a specific method, unless you can get the name of the current method you're in atm using a macro
<FromGitter>
<bhargavrpatel> @elorest *Facepalm* I actually had that but I saw a different error and assumed "it didn't work". Thanks.
<FromGitter>
<elorest> For sure.
<FromGitter>
<elorest> @Blacksmoke16 ok. Possibly my whole paradigm is off but I'm trying to create usibility similar to bitfields in c. Using similar syntax to `getter`, `property, `setter` etc makes a lot of sence from a end user DSL perspective. In the past I'd seen a lot of projects which stored values in Constants from macros and then figured out how it all worked together in the codegen in `finished`. ⏎ ⏎ If macro dynamic
<FromGitter>
... constants are going to be removed I need to figure out another way of doing this but I'd really prefer to keep the same DSL.
<FromGitter>
<elorest> @Blacksmoke16 is there a way to achieve something like this simple example using annotations. https://carc.in/#/r/5qsy
<FromGitter>
<Blacksmoke16> can look thru my branch, been working on moving granite over to annotations
<FromGitter>
<elorest> Ok.
<FromGitter>
<Blacksmoke16> bbiaf food
<FromGitter>
<elorest> Thanks for your help. I'll keep working on that but need to take the kids to the park before it gets dark.
<FromGitter>
<j8r> @vladfaust At the end, I think only libs need to be fully typed to benefit for incremental compilation
<FromGitter>
<vladfaust> I agree with you on that, @j8r
<FromGitter>
<j8r> Like C libraries, we could compile our shards dependency and link them to our main app :)
<FromGitter>
<j8r> the solution would be to separate our monolithic app to libraries to improve compile time
<FromGitter>
<j8r> BTW good libs are already more or less fully typed @elorest , to generate good docs; Don't worry much about that @elorest
<FromGitter>
<Blacksmoke16> bk
<FromGitter>
<kingsleyh> hi - in my C binding - my binding is clashing with the openssl binding - is there a way I can resolve this?
<FromGitter>
<kingsleyh> ```code paste, see link```
<FromGitter>
<kingsleyh> one solution would be to edit the C files and add a variation but that seems overkill - there must be a way to override the fun
<FromGitter>
<j8r> you can use a different lib name
<FromGitter>
<kingsleyh> I tried that but didn’t seem to help
<FromGitter>
<kingsleyh> no matter what I do - it always complains about the redefinition with different signature - e.g.