RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
<FromGitter> <kingsleyh> how do I make a `Pointer(Void)`
<FromGitter> <j8r> @kingsleyh you want to convert from C to Crystal?
<FromGitter> <kingsleyh> I want to default a var which in C is a Pointer(Void)
<FromGitter> <kingsleyh> ```myecc : LibSSL::EC_KEY = Nil```
<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> <kingsleyh> aha got it: `b.each { |x| salt_io.write_bytes(x, IO::ByteFormat::LittleEndian) }`
<FromGitter> <girng> nice job @kingsleyh ! :D
<FromGitter> <girng> is the forum ready for registration yet?
Renich has quit [Quit: Renich]
_whitelogger has joined #crystal-lang
<FromGitter> <proyb6> Before we approach 2019 and said goodbye to 2018 soon
<FromGitter> <proyb6> I have start a thread to spread the awareness on funding Crystal on-going development.
<FromGitter> <proyb6> What is missing is the ```voices``` of your impression about Crystal so far and post in that Reddit's thread
<FromGitter> <girng> https://manas.tech/staff/ ary is not there anymore??
<FromGitter> <elorest> That's been a couple years now. @girng
<FromGitter> <girng> did he move to a new company?
<FromGitter> <elorest> Yeah. There was a blog post about it last spring or something.
<FromGitter> <girng> Interesting, I'd have to read up about it. I was just surprised cause I usually see him there lol
<FromGitter> <proyb6> I'm thinking if the team have ever though about running a Kickstarter crowdfunding to raise enough fund?
<FromGitter> <elorest> Here's a Bit Field library I wrote with the help of <oprypin> ⏎ ⏎ https://github.com/elorest/bitfields ⏎ ⏎ It solves my use case very well but I'm interested in feedback. [https://gitter.im/crystal-lang/crystal?at=5c0c98fd26de6f0822a604ec]
<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> <elorest> https://vimeo.com/190927958
<FromGitter> <girng> @elorest thanks, watching now. i should try vimeo next time i search..
<FromGitter> <elorest> @Blacksmoke16 is there any easy way to get those return values or do I need to do those manually/regex.
<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> <girng> okay i'm following the macro video. https://play.crystal-lang.org/#/r/5qbd why is it printing 5 but not 'stength'?
<FromGitter> <girng> okay i'm getting closer... https://play.crystal-lang.org/#/r/5qdh how can i get the value of the instance variable?
<FromGitter> <girng> i tried `self[name]` but it returns a stack overflow
dannyAAM has quit [Ping timeout: 268 seconds]
JuanMiguel has joined #crystal-lang
<FromGitter> <girng> O_o this actually returns `strength` https://play.crystal-lang.org/#/r/5qdz/edit, but bcz i removed the `property` part
JuanMiguel has quit [Client Quit]
dannyAAM has joined #crystal-lang
<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> <r00ster91> you cannot call macros on objects btw, you need to call the macro on the Player class
<FromGitter> <r00ster91> it's like as if you define a `def self.`
<FromGitter> <girng> OMG
<FromGitter> <r00ster91> wow! amazing
<FromGitter> <girng> i freaking did it!! massive goosebumps that felt goood bahwaahhahaah
<FromGitter> <girng> what a mess LOL
<FromGitter> <dscottboggs_gitlab> I'm sorry, what the hell?
<FromGitter> <r00ster91> yea this could be way smaller though
<FromGitter> <dscottboggs_gitlab> what's @name?
<FromGitter> <girng> no idea
<FromGitter> <girng> i jsut kept trial and erroring until it worked ahahha
<FromGitter> <elorest> @girng Presumably you're just doing this to figure things out. Just so you know you can use getter, setter, property
<FromGitter> <girng> thank you @r00ster91
<FromGitter> <r00ster91> I could send you slightly smaller solution with comments for explanation
<FromGitter> <girng> if you got time i'd appreciate that =]
<FromGitter> <dscottboggs_gitlab> so here's where I'm confused https://play.crystal-lang.org/#/r/5qfl
<FromGitter> <dscottboggs_gitlab> AYY @girng I got it https://play.crystal-lang.org/#/r/5qfp
<FromGitter> <girng> haha O_o
<FromGitter> <dscottboggs_gitlab> complete example https://play.crystal-lang.org/#/r/5qfp/edit
<FromGitter> <dscottboggs_gitlab> wait waht
* FromGitter * dscottboggs_gitlab should pay closer attention before posting
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/5qfv
<FromGitter> <dscottboggs_gitlab> @gring are you aware of `crystal tool expand`?
<FromGitter> <girng> ic, interesting. seems like i'm looking at a totally new language almost lol
<FromGitter> <r00ster91> I hope this is understandable: ⏎ @girng https://play.crystal-lang.org/#/r/5qfx
<FromGitter> <dscottboggs_gitlab> interesting
<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> https://play.crystal-lang.org/#/r/5qik/edit why is it setting strength and dexterity to `55`?
<FromGitter> <girng> i'm only modifying `strength` :/
<FromGitter> <dscottboggs_gitlab> because @name isn't anything special it's just an instance var
<FromGitter> <girng> i'm so confused >_<
<FromGitter> <mpcjanssen> any string in your call will access this same instance var
<FromGitter> <mpcjanssen> change it to p["dasjdsajdjkahds"] -> 55
<FromGitter> <girng> that will give error right
<FromGitter> <mpcjanssen> no
<FromGitter> <mpcjanssen> try it
<FromGitter> <mpcjanssen> https://play.crystal-lang.org/#/r/5qj1
<FromGitter> <mpcjanssen> you need this ^
<FromGitter> <mpcjanssen> you are always setting or returning the name instance var regardless of the name parameter
<FromGitter> <girng> i don't have a `strengthgregegregeg` property............
<FromGitter> <bew> @girng your code is wrong
<FromGitter> <bew> You're not doing what you think you are doing
<FromGitter> <girng> wtf how does that work
<FromGitter> <mpcjanssen> Girng name and @name are not related at all
<FromGitter> <bew> The name argument in your methods is not used..
<FromGitter> <girng> isn't `@name` grabbing the string, applying @ to it (which grabs the instance variable)
<FromGitter> <bew> No
<FromGitter> <bew> This isn't ruby
<FromGitter> <bew> (or some weird thing)
<FromGitter> <mpcjanssen> Ruby also doesn't do that
<FromGitter> <mpcjanssen> Does this help? https://play.crystal-lang.org/#/r/5qj4
<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> <bew> @girng i did something for you: https://carc.in/#/r/5qju
<FromGitter> <bew> 3 exercises
<FromGitter> <bew> You can comment the exercises you didn't do yet
<FromGitter> <bew> You have to code in `my_property`
<FromGitter> <girng> wait i look in a bit
<FromGitter> <bew> And at the end you run the exercise 1, 2, or 3 (or all), and it should work
<FromGitter> <bew> (please do it, i wrote all this on my phone ^^)
<FromGitter> <girng> why can't i use the index operator inside the MACRO
<FromGitter> <girng> grrrr !!!!!!!!!
<FromGitter> <mpcjanssen> Girn
ashirase has quit [Ping timeout: 240 seconds]
<FromGitter> <mpcjanssen> Sorry
<FromGitter> <girng> go to 8:04 [here}(https://vimeo.com/190927958) from ary's video. now check my code here https://play.crystal-lang.org/#/r/5qk5
<FromGitter> <bew> index operator? What are you doing?
<FromGitter> <girng> i can't EVEN use the index parameter inside the MACRO
<FromGitter> <bew> Ah
<FromGitter> <bew> You're in a merhod, not a macro
<FromGitter> <bew> Macros can't acces arguments of normal methods
<FromGitter> <girng> but in ary's video he's using {{}} inside the def method
<FromGitter> <girng> well, crap
<FromGitter> <bew> In ary's video, he's in a macro
ashirase has joined #crystal-lang
<FromGitter> <bew> (that defines a method)
<FromGitter> <girng> okay i give up ima just post everything i tried. try 1: stack overflow: https://play.crystal-lang.org/#/r/5qk6, try 2: https://play.crystal-lang.org/#/r/5qk7 undefined macro variables try 3: https://play.crystal-lang.org/#/r/5qk8 undefined macro again
<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 ?
<jokke> today's AoC is bugging me
<FromGitter> <girng> i'm trying to use rooster's macro here https://play.crystal-lang.org/#/r/5qfx and incorporate it into an index operator
<FromGitter> <mpcjanssen> why?
<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> @girng which leads to https://play.crystal-lang.org/#/r/5qkg
<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> ... pointer. ⏎ ⏎ The only way to add the kind of syntax you're looking for is add the Hash of string names of methods/ivars back into the class manually [https://gitter.im/crystal-lang/crystal?at=5c0ced6a26de6f0822a7d6c7]
* 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
<FromGitter> <mpcjanssen> @girng is the when part in the following example the part you would like to simplify? https://play.crystal-lang.org/#/r/5ql5
<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
<oprypin> at the very bottom of https://crystal-lang.org/docs/syntax_and_semantics/macros.html we have an example of producing a `case` statement in macros
<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)
<FromGitter> <dscottboggs_gitlab> this is my solution from earlier https://play.crystal-lang.org/#/r/5qfv
<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
<oprypin> dscottboggs_gitlab, maybe you can copy the content of this page and just paste it? https://crystal-lang.org/docs/syntax_and_semantics/macros.html
<FromGitter> <dscottboggs_gitlab> yeah you're right
<FromGitter> <mpcjanssen> @girng and the I think you'll end up with something similar to https://play.crystal-lang.org/#/r/5qlj
<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
<oprypin> yeah it actually doesn't. @dscottboggs_gitlab's solution works though. https://play.crystal-lang.org/#/r/5qfv
<FromGitter> <girng> also makes it look very unaesthetic
<FromGitter> <dscottboggs_gitlab> dude.
<FromGitter> <girng> imo, it should be optional to just use {{ for conditions and variables
<FromGitter> <dscottboggs_gitlab> idk, maybe
<FromGitter> <dscottboggs_gitlab> but like
Vexatos has quit [Remote host closed the connection]
RX14 has quit [Remote host closed the connection]
<oprypin> this convention is at least 15 years old, it is familiar to people
<FromGitter> <mpcjanssen> @dscottboggs_gitlab it doesn't?
<FromGitter> <dscottboggs_gitlab> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0cfafc5e409525033bbafb]
<oprypin> the 15 year old example is django. https://tutorial.djangogirls.org/en/django_templates/
<oprypin> may be others
<FromGitter> <girng> anyway @dscottboggs_gitlab i appreciate you explaining some of my confusion
<FromGitter> <dscottboggs_gitlab> this iterates over delta and loops `delta.size` times
<FromGitter> <mpcjanssen> yes
RX14 has joined #crystal-lang
<oprypin> that's intentional, it's supposed to accept an array of updates and perform them
<FromGitter> <mpcjanssen> right
<FromGitter> <girng> @dscottboggs_gitlab so the big confusion is how are the macros returning a value lol
<oprypin> but i guess maybe best to leave the loop out of it
<FromGitter> <dscottboggs_gitlab> @gring Implicit returns?
Vexatos has joined #crystal-lang
<FromGitter> <girng> last line ?
<FromGitter> <mpcjanssen> macros don't return anything
<oprypin> yes
<FromGitter> <mpcjanssen> macros expand to code.
<FromGitter> <dscottboggs_gitlab> yes the macros don't return, the code they expand to does
<FromGitter> <girng> the macros don't return code
<oprypin> ok fml
<FromGitter> <mpcjanssen> they expand to code
<FromGitter> <dscottboggs_gitlab> the macros *generate* code at compile time
<FromGitter> <girng> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0cfb8080986419d562c6c0]
<FromGitter> <dscottboggs_gitlab> as I've said several times
<FromGitter> <dscottboggs_gitlab> sorry
<oprypin> explaining macros by their building blocks doesnt help, otherwise reading https://crystal-lang.org/docs/syntax_and_semantics/macros.html would have helped
<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> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0cfc188b656e2b04e7e300]
<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> OHHHHHH
<FromGitter> <girng> GOT IT
<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> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/5qm0 I'm not sure I quite get it?
<FromGitter> <girng> hmmmm
<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> <girng> p! makes it work correctly
<FromGitter> <bew> No
<FromGitter> <bew> It's the same
<oprypin> dscottboggs_gitlab, maybe this https://stackoverflow.com/a/1837703
<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> <dscottboggs_gitlab> that's interesting, I wonder what `%prefix` is
<FromGitter> <girng> i think i rmemeber using p! before for json or hash printing
<FromGitter> <girng> nice format in console
<FromGitter> <dscottboggs_gitlab> indeed
<FromGitter> <girng> i want to use p! for everything now lolz
<FromGitter> <girng> but my mind subconsciously types puts
<FromGitter> <girng> oh maybe was thinking of pp! (pretty print)
<FromGitter> <girng> so....
<FromGitter> <dscottboggs_gitlab> oh
<FromGitter> <girng> if i got this right. {{macrovariable}} can only be used inside a macro method, or inside conditional blocks? if i got that right?
<FromGitter> <dscottboggs_gitlab> I never mentioned what `@type` is for
<FromGitter> <dscottboggs_gitlab> yeah you can embed macro literals into code wherever to add contitional or iterated compilation
<FromGitter> <dscottboggs_gitlab> sorry, did I make that too dense?
<FromGitter> <girng> nope i understand ty
<FromGitter> <dscottboggs_gitlab> so @type returns one of these https://crystal-lang.org/api/0.27.0/Crystal/Macros/TypeNode.html which is where `instance_vars` comes from
<FromGitter> <dscottboggs_gitlab> just learned that the other day from @Blacksmoke16
<FromGitter> <dscottboggs_gitlab> lots of other useful stuff in ther
<FromGitter> <girng> yeah was glancing over that earlier
<FromGitter> <girng> okay @dscottboggs_gitlab i'm stuck again :/
<FromGitter> <girng> https://play.crystal-lang.org/#/r/5qmh `undefined macro variable 'name'` what have i done now
<FromGitter> <dscottboggs_gitlab> you can only work with constants inside of macro statements
<FromGitter> <girng> so i can't use if statements on variables?
<FromGitter> <dscottboggs_gitlab> you can but the if statement has to be in the generated code not a part of the macro
<FromGitter> <dscottboggs_gitlab> https://play.crystal-lang.org/#/r/5qmi
<FromGitter> <girng> WAT
<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 * dscottboggs_gitlab has to go ✌️
<FromGitter> <girng> one LINE IF GOT It bahwhahah
<FromGitter> <dscottboggs_gitlab> yes exactly!
<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
<FromGitter> <kingsleyh> ```a = LibSSL.EC_KEY_get0_private_key(myecc) ⏎ p typeof(a) #Pointer(Int32)``` [https://gitter.im/crystal-lang/crystal?at=5c0d0953e4787d16e36c0b7f]
<FromGitter> <bararchy> is the Int32 overflows ?
<FromGitter> <kingsleyh> did the crystal_lib create the wrong kind of binding for that C function? I don't see why it's a Pointer(Int32)
<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> which returns BIGNUM
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0d0a018d4f3a2a7c94b079]
<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
<FromGitter> <girng> https://crystal-lang.org/api/0.27.0/Float.html is there any floats smaller than 32bits?
<jokke> that would make the ranking even less useful than what it is now
<FromGitter> <bew> @girng not in Crystal
<FromGitter> <girng> @bew will use 32bit then, ty
<FromGitter> <kingsleyh> Jokke - what competition is this?
<jokke> advent of code
<RX14> you really dont want anything less than a 32bit float
<Yxhuvud> jokke: Yes, there are different ways. Some of the different (but efficient) ways do use arrays under the hood though.
<FromGitter> <kingsleyh> BIGNUM as Void* didn't work
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0d179f4808192b030c7961]
<FromGitter> <proyb6> When is ```Deque``` api is use and what is the use case?
<FromGitter> <proyb6> For example if it's in gaming?
<FromGitter> <kingsleyh> I'm really struggling to get something useful out of the C binding
<FromGitter> <proyb6> @kingsleyh I'm not sure if it's useful for your case
<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> `/usr/include/openssl/ossl_typ.h:typedef struct bignum_st 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
<oprypin> kingsleyh, ??? https://bpaste.net/show/643b3d524aa6
<FromGitter> <kingsleyh> maybe I have to convert it to a EVP_PKEY first or something
<FromGitter> <kingsleyh> yeah none of those commands take BIGNUM and give back the private key as far as I can see
<oprypin> the bignum *IS* the private key
<oprypin> say, 1347143471647126541326734512645127641254736561244r
<oprypin> uh minus the "r"
<oprypin> what do you want to do with it now?
<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> <kingsleyh> ```bn = LibSSL.EC_KEY_get0_private_key(myecc) ⏎ n = LibSSL.BN_bn2dec(bn)``` [https://gitter.im/crystal-lang/crystal?at=5c0d1c7fe4787d16e36c805d]
<jokke> well deleting could be sped up by setting nil or something instead maybe
<oprypin> kingsleyh, yeah that's a C string. you can use `String.new( )` on that
<jokke> but inserting would still be a problem
<oprypin> also note >The string must be freed later using OPENSSL_free().
<FromGitter> <kingsleyh> oprypin - ah finally!!! something works
<FromGitter> <kingsleyh> do I need to call a free() for each container I used e.g. EC_KEY_free(myecc)
<oprypin> likely so. check the documentation on a case by case basis.
<FromGitter> <kingsleyh> ok
<FromGitter> <proyb6> @kingsleyh How did you manage to get it work?
<FromGitter> <kingsleyh> instead of trying to get a value of the function: LibSSL.EC_KEY_get0_private_key(myecc)
<FromGitter> <kingsleyh> I had to pass the return into LibSSL.BN_bn2dec(bn)
<FromGitter> <kingsleyh> and then get the value from that
<FromGitter> <proyb6> simply print n?
<oprypin> no
<FromGitter> <kingsleyh> heres my code
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0d1d7c8336e22a7d063aea]
<Yxhuvud> jokke: think harder.
<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
<oprypin> think of those functions as getters ;)
<FromGitter> <kingsleyh> :)
<FromGitter> <girng> https://play.crystal-lang.org/#/r/5qpb why doesn't my recursive alias work here?
<oprypin> i dont know why it's giving this particular error, but anyway, recursive aliases are not supported by anything in standard library
<FromGitter> <girng> i see. i was just browsing https://github.com/crystal-lang/crystal/issues/5155 and figured i'd try it
<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
<oprypin> girng, that's JSON::Serializable
<FromGitter> <girng> @oprypin yeah, I tried that but still found some issues. ex: https://play.crystal-lang.org/#/r/5qpq
<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
Renich has joined #crystal-lang
DTZUZO has joined #crystal-lang
<FromGitter> <kingsleyh> hey - if anyone is familiar with C - would you mind checking my C binding is ok and that I'm freeing up everything I've been using at the end - Gist is here: https://gist.github.com/kingsleyh/822b56de16f444e27371da30e9aa8365
DTZUZO has quit [Ping timeout: 246 seconds]
<oprypin> kingsleyh, you're not freeing the string from BN_bn2hex , at least
<oprypin> same for EC_POINT_point2hex
<mps> RX14: I'm here: http://tpaste.us/8VXy
DTZUZO has joined #crystal-lang
<RX14> mps, can you provide the whole error output?
<mps> 'abuild check' log is to long so I pasted just end
<RX14> it should give a list of errored specs at the end
<mps> it is in tmux terminal and I tried to go back, but beggining is scrolled out
<RX14> also, it shouldn't be really long unless it's in -v mode
<RX14> mps, just paste your whole tmux buffer pls
<mps> I can post log from line 'Failures:'
<RX14> yes please!
<mps> to paste full I have to rerun it, and it takes about half an hour
<RX14> mps, just from Failures is perfect
<RX14> but also is vaguely a non-bugfix change so you might just want to patch that specific spec to be pending
<mps> here is a longer 'tail' of the log: http://tpaste.us/roez
<RX14> thanks, that's super helpful
<mps> so, I should 'git clone' master and take that commit with cherry-pick?
<RX14> i actually think you should just patch the specs to make all of the failing specs "pending"
<RX14> since both of the commits you need to cherry-pick to fix the specs failing make sematic changes
<mps> ah, ok. would you mind to tell me make it 'pending'
<RX14> but both change the way errors are raised
<RX14> mps, replace the "it" with "pending"
<RX14> and that's it
<mps> ah, thanks, will do right now
<RX14> make sure to make a note in the patch comment of those commits :)
<mps> will do, but first to see if it helps. Will take about 30 minutes
<RX14> it'll definitely help because it just wont run those specs
<RX14> since all those spec failures have been investigated and it turns out to be minor error-handing and spec deficiencies
<mps> ok, understand. will inform you about results.
<mps> btw, it needs a lot of cpu and memory to build
<RX14> yeah
<RX14> half an hour seems long though, unless thats for the entire clean package build
<mps> no problem, I'm testing on I7 with 6GB. Will see how it will go on aarch64
<RX14> surprised you got it to work with 6gb ram at all
<mps> I'm trying to make it reproducible build
<RX14> unless you're not running any desktop on the machine
<oprypin> RX14, hooooold on.... what if... crystal spec was split into several processes?
<oprypin> 1) it would probably use less RAM 2) it would run in parallel
<mps> yes, it is my primary desktop with firefox and a lot of tabs open
<RX14> oprypin, it would take much longer to compile
<RX14> since you'd have to compile each part sequentially
<RX14> or you'd use *more* ram if you compiled in parallel
<RX14> it'd have to be an optional mode for crystal's specs or other large spec suites
<oprypin> compile sequentially, run parallel
<oprypin> yeah, longer to compile..
<RX14> oprypin, it'd very much depend on the spec suite which would be faster
<RX14> and if you *did* have the ram you'd want to compile in parallel too
<FromGitter> <straight-shoota> It would be great to run the compiler specs on alpine in CI. This would help avoiding such issues in the future.
<RX14> it'd be great to do a lot of things with CI
<FromGitter> <straight-shoota> ... building on win32 =)
<FromGitter> <straight-shoota> But adding alpine should be pretty easy
<mps> straight-shoota[g]: for musl GB2312 encoding should be removed
<RX14> the specs for*
<mps> musl doesn't support GB2312 encoding
<mps> in iconv
<RX14> yeah, we don't explicitly support it
<RX14> we just need to remove the specs
<RX14> that assume that inconv supports it
<RX14> iconv*
<mps> not sure, but without patch whicj removes GB2312 encoding from crystal it fails to build
<mps> s/whicj/which/
<RX14> it remioves the specs
<RX14> doesnt touch the stdlib
<RX14> if you look at the patch
<mps> I can paste patch for you if you like to see it
<RX14> i've seen it
<mps> ah, ok
<RX14> i've known about it for a long time
<RX14> i remember every issue
<RX14> :P
<RX14> it's my jov
<RX14> job*
<mps> you have very good memory
<RX14> depends on the subject :P
<RX14> i think random crystal trivia takes up the common sense part of my brain
<mps> heh, good assurance for crystal future ;)
<FromGitter> <j8r> setting the scheduler to performance instead of economic can help
<FromGitter> <j8r> on Linux, to improve build time
jemc has joined #crystal-lang
DTZUZO has quit [Ping timeout: 272 seconds]
<mps> j8r[g]: what is the /sys file? i forgot
<FromGitter> <j8r> IIRC that where you can set kernel configuration stuff like set the kernel scheduler to perf
<FromGitter> <j8r> often that's files with 0/1 values (no always)
<FromGitter> <j8r> I noticed we *can* set a password for system groups... seems to be nearly never used
<mps> maybe /sys/devices/system/cpu/cpufreq/policy0/scaling_governor, etc
<FromGitter> <j8r> exactly
<mps> it is 'performance' in my case
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Remote host closed the connection]
jemc has quit [Ping timeout: 250 seconds]
<FromGitter> <j8r> `/sys/devices/system/cpu/cpu*/cpufreq/scaling_governor`
<FromGitter> <j8r> I've a little perf.sh script that I run each time I compile something :)
<mps> RX14: no luck, left is one error. http://tpaste.us/P0M1
<mps> should I add 'pending' for it, also?
<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
<FromGitter> <j8r> take stdlib as example
<RX14> mps, thats one i havent seen before
<FromGitter> <bhargavrpatel> Thanks.
<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
<DeBot> https://github.com/crystal-lang/crystal/issues/6468 ([RFC] Structured Concurrency)
<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> <j8r> @elorest I think you could use something like https://github.com/crystal-lang/crystal/blob/master/src/json/serialization.cr
<FromGitter> <j8r> there is a macro to iterate over ivars
<FromGitter> <j8r> an use a annotation to tell what is the length
<FromGitter> <j8r> or you can use the JSON.mapping approach
<mps> RX14: now it passed without errors.
<mps> Finished in 31:14 minutes
<mps> 14988 examples, 0 failures, 0 errors, 18 pending
<RX14> nice
<mps> you helped a lot
<RX14> @straight-shoota there's a spurious listen() being called on the wrong FD
<RX14> in the middle of the spec's execution
<RX14> which somehow triggers this
<FromGitter> <kingsleyh> oprypin - I can't seem to free the ec_point or the private_key_pointer or private_key
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0d77d68b656e2b04eae2a6]
<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> <elorest> For instance in this code: ⏎ https://github.com/elorest/bitfields/blob/master/src/bitfields.cr#L16 ⏎ ⏎ How would I use annotations instead? [https://gitter.im/crystal-lang/crystal?at=5c0d7e76178d7860a1aedb3a]
<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> <vladfaust> @elorest ⏎ ⏎ ```@[BitField(length: 42) ⏎ @foo``` [https://gitter.im/crystal-lang/crystal?at=5c0d7ea9178d7860a1aedc66]
<FromGitter> <vladfaust> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0d7eea8336e22a7d089f14]
<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> <vladfaust> https://carc.in/#/r/5qsl but https://carc.in/#/r/5qsm and https://carc.in/#/r/5qsn. Is that a bug? /cc @RX14
<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> <vladfaust> ```@[BitField(length: 15)] ⏎ @name``` ⏎ ⏎ Your syntax is may be clear, and the superiority of annotations over DSLs is another topic [https://gitter.im/crystal-lang/crystal?at=5c0d81fcf4880a60a251e786]
<FromGitter> <vladfaust> But annotations allow better composition than DSLs
<RX14> mps, will you be rebuilding crystal against openssl now that alpine is switching away from libressl?
<FromGitter> <vladfaust> Is that also a bug, @RX14 -- https://carc.in/#/r/5qss? I'm asking you here to avoid issues creation
<RX14> no
<RX14> {% begin %}/{% end %} is required
<FromGitter> <vladfaust> Wrapping in verbatim doesn't work as well: https://carc.in/#/r/5qst
<FromGitter> <vladfaust> It's so unobvious
<FromGitter> <vladfaust> > https://carc.in/#/r/5qsl but https://carc.in/#/r/5qsm and https://carc.in/#/r/5qsn. Is that a bug? /cc @RX14 ⏎ ⏎ What about this one?
<mps> RX14: yes, I'm building it with openssl
<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> eh, kaniini ;)
<RX14> same ;)
<FromGitter> <vladfaust> @elorest https://carc.in/#/r/5qt0
<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> <bhargavrpatel> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0d8e8df992693c7a4ac1b4]
<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.
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0da4b2f4880a60a252c075]
<FromGitter> <kingsleyh> if I run that - then it complains
<FromGitter> <kingsleyh> if I comment out require "openssl" then it's fine
<FromGitter> <kingsleyh> changing to `lib LibSomethingElse` does nothing to remove the error
<oprypin> kingsleyh, this function is defined somewhere in standard library ......
<FromGitter> <kingsleyh> yes but with a different signature - the signature of the std lib one doesn't work with my code
<oprypin> why not
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0da59af4880a60a252c542]
<FromGitter> <kingsleyh> and I want:
<FromGitter> <kingsleyh> ```fun EC_KEY_new_by_curve_name(i : LibC::Int) : LibC::Int*```
<FromGitter> <kingsleyh> because I do this:
<FromGitter> <kingsleyh> ``` myecc = LibSSL.EC_KEY_new_by_curve_name(eccgrp_id) ⏎ LibSSL.EC_KEY_generate_key(myecc)``` [https://gitter.im/crystal-lang/crystal?at=5c0da5dcf4880a60a252c6e9]
<oprypin> and the problem is ...?
<FromGitter> <kingsleyh> If I use the one in the std lib - this EC_KEY_generate_key does not work
<oprypin> "does not work"?
<FromGitter> <kingsleyh> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c0da6418336e22a7d098231]
<oprypin> please also open an issue about this, this restriction is not ok. it means that binding more functions can arbitrarily break other libs
<oprypin> kingsleyh, so make it be Pointer(Void)
<oprypin> you should realize by now that all of these generated `LibC::Int*` are bogus and should have been `Void*`
<FromGitter> <kingsleyh> ah ok
<FromGitter> <kingsleyh> got it working now
<FromGitter> <kingsleyh> I did not realise that LibC::Int* should be Void* - I've changed them all to be Void* now
<oprypin> btw there could be legitimate usages of it, who knows if the blanket replacement is ok
<oprypin> uh oh, there are
<oprypin> ` egrep '\bint *\*' /usr/include/openssl`
<FromGitter> <kingsleyh> well my code is working - so I guess the ones I changed did not impact anything