RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.1 | 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> <Blacksmoke16> xD
markoong has quit [Quit: Konversation terminated!]
<FromGitter> <anamba> so i'm trying to figure out some issues with memory usage that appears to grow without bound over a period of several hours. i tried to see if `GC.collect` would help, but it causes a segfault within a few minutes. as i understand it, ideally, GC.collect should not need to be called manually, but... doing that should not cause segfaults, right?
<FromGitter> <iambudi> > I actually checked out https://github.com/robacarp/mosquito and it was really easy to add in! ⏎ The name remind me of MQTT
<FromGitter> <iambudi> @anamba on my microservice app, i even add a scheduler to just call GC.collect every 5 minutes.
<FromGitter> <konung> Hello. I'm playing with Crystal and love it very much. I'm looking into macros and I'm trying to wrap my head around making it work for namespaced constants. Something similar to Rails's / Ruby's `contantize / Object.get_const` . Here is a somewhat contrived Ruby example ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ I tried various approaches with macros, but so far I hit a wall.
DTZUZO has joined #crystal-lang
ashirase_ has quit [Ping timeout: 246 seconds]
ashirase has joined #crystal-lang
<FromGitter> <konovod> https://carc.in/#/r/6948
<FromGitter> <konovod> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c668f784003460b2d54f584]
DTZUZO has quit [Ping timeout: 268 seconds]
markoong has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> @konung Crystal macros are very different from ruby metaprogramming. Its more like a templating language that outputs code.
<mps> to me, crystal macros more like C macros
<mps> or, if you like, more like assembly languages macros
jemc has joined #crystal-lang
<FromGitter> <drum445> Anyone know what I'm doing wrong here please
<FromGitter> <j8r> @drum445 https://play.crystal-lang.org/#/r/696z
<FromGitter> <j8r> macros takes strings as arguments
<FromGitter> <drum445> @j8r I want it to actually perform the .to_i
<FromGitter> <j8r> StringLiterals
<FromGitter> <drum445> or whatever the operation is, could be "to_s"
jemc has quit [Quit: WeeChat 2.2]
<FromGitter> <j8r> Or, you have to use a macro variables
<FromGitter> <j8r> not a classic crystal variables available at compile time
<FromGitter> <j8r> macros are done before code compilation
<FromGitter> <drum445> so if I want my operation to be "to_s"
<FromGitter> <j8r> or with debug https://play.crystal-lang.org/#/r/6978
<FromGitter> <drum445> ah right cheers, I don't think this is going to work then, as operation will be passed through to a method as a string
<FromGitter> <j8r> basically you want to do like Object#send
DTZUZO has joined #crystal-lang
<FromGitter> <j8r> I've experimented with https://github.com/j8r/crystal-object-send
<FromGitter> <j8r> (I don't recommend to use it through :) )
<FromGitter> <drum445> haha
<FromGitter> <j8r> just use a case/when in your case
<FromGitter> <drum445> I'll have a browse, ta
<FromGitter> <j8r> to_i isn't supported because of missing type restrictions in https://github.com/crystal-lang/crystal/blob/d83fe1c139b1404a7532de056b2834704b1f7f59/src/string.cr#L341
<FromGitter> <j8r> but this work https://play.crystal-lang.org/#/r/697l
<FromGitter> <j8r> I don't know - is it possible to get the the inferred type of a variable with macros?
<FromGitter> <Jens0512> What do we call ourselves?
<FromGitter> <Jens0512> Crystallers? Sounds weird
<FromGitter> <Jens0512> I dunno, I think we need a proper name :D
<FromGitter> <j8r> Crystians haha
<FromGitter> <j8r> For Crystal evangelists :)
<FromGitter> <alex-lairan> Elixir dev are Alchemists, we don't need the Crystal in our name :p
<FromGitter> <j8r> that's well found!
<FromGitter> <konung> @j8r "Ballers" as in "looking into a Crystal ball"
<FromGitter> <konung> :D
<FromGitter> <konung> @konovod Excellent! Thank you I will look into it and specifically what `id` does. I wast trying to use stingify and but would get nowhere trying to `stringify` `Var & Call`
<FromGitter> <Jens0512> 👀
<FromGitter> <konung> @j8r In case you are not familiar with US idiom, this should clear it up :) - Ballers -> https://proxy.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.whats-on-netflix.com%2Fwp-content%2Fuploads%2F2017%2F08%2Fis-ballers-on-netflix-770x433.jpg&f=1
<FromGitter> <straight-shoota> @Jens0512 Methheads, obviously :P
<FromGitter> <konung> @konovod @dscottboggs_gitlab Still running into the same issue. I didn't explain it right. The problem is that macro setup that way expects a StringLiteral. But I'm trying to pass a Var. And I'm not sure how I can cast it as String literal if at all possible. See this example
<FromGitter> <vlazar> lol, straight-shoota
<FromGitter> <j8r> @konung macros aren't methods
<FromGitter> <j8r> think about them a way to avoid writing boilerplate by hand. Use `{% deug %}` to this how they expand
<FromGitter> <j8r> Also an enum looks like to be a good fit
<FromGitter> <j8r> enum value must be interger :/
<FromGitter> <j8r> @konung https://play.crystal-lang.org/#/r/699s 🎉
<FromGitter> <j8r> In Crystal you do the interpreter, unlike in Ruby where we can use it's interpreter to convert Strings to method calls: https://play.crystal-lang.org/#/r/699u
<FromGitter> <r00ster91> what are those comment pragmas like `#<loc:pop>#<loc:push>` for? Are macros implement using these?
Raimondi has quit [Ping timeout: 240 seconds]
<FromGitter> <konung> @j8r Lightbulb moment . Thank you
<FromGitter> <konung> So even thou some sights say that Crystal's macros are an answer to metaprogramming. They are not really. That's what was confusing. I see you can use them to - *pre-generate* code instead of writing it out by hand, but the not to eval it dynamically. Am I getting that right?
<z64> well, it *is* metaprogramming - it is code that generates more code. but it does not have some of the features of ruby's metaprogramming; that can be only "emulated" as you saw above, in a "strict" manner. and yes, that's a way to think about it - pre-generating code instead of writing it out
<z64> highly recommend asterite's talk on macros. its a bit dated (2016) but the thinking behind macros and when to use them still applies: https://vimeo.com/190927958
<mps> z64: I would add to you good explanation: generate code at compile time, not at execution time
<FromGitter> <konung> Thank you
<FromGitter> <konung> Yep that takes a bit of an ajustment in thinking
<z64> mps, yep good note :). yw konung
<mps> macros are confusing for programmers coming from interpreters 'world'
<FromGitter> <j8r> @konung you can simulate "eval" with macros: https://github.com/j8r/crystal-object-send
<FromGitter> <j8r> they are powerful enough to cover virtually all use cases, minus really edge cases
<FromGitter> <konung> @j8r I thought somebody just mentioned that it should be avoided ( just a few dozen messages above)?
<FromGitter> <konung> Huh. It was you. I'm going to take a close look right now
<FromGitter> <konung> Thank. you
<FromGitter> <j8r> that's me
<FromGitter> <j8r> and maybe other too like z64
<FromGitter> <j8r> If you need a full blown interpreter, that's fine. But we usually don't
<FromGitter> <j8r> better to writing our own case/when to have control, and good perf
Raimondi has joined #crystal-lang
<FromGitter> <Sija> @anamba yo, what's up with this raven ssl error you had?
<z64> anyone around that is familiar with StaticArray internals? i can't find where `@buffer` is typed. i'm building a similar type for a special use case, so i was referencing its implementation
<FromGitter> <r00ster91> It looks like that's happening in the compiler: https://github.com/crystal-lang/crystal/blob/master/src/compiler/crystal/program.cr#L177
<z64> ah okay. thanks.
DTZUZO has quit [Quit: WeeChat 2.0]
fanta7531 has joined #crystal-lang
<FromGitter> <straight-shoota> Yeah, `StaticArray` is a primitive. It can't be fully implemented in user code.
<z64> yeah. wasn't trying to (otherwise i would just use SA lol) but just implementing similar memory ops
DTZUZO has joined #crystal-lang
<FromGitter> <girng> hi
<FromGitter> <Blacksmoke16> o/
<FromGitter> <girng> i'm kinda stuck here, and was wondering if anyone can help https://play.crystal-lang.org/#/r/69cm/edit
<FromGitter> <girng> err. forgot what i actually want to statically type them as, added the `TypedRows` named tuple: https://play.crystal-lang.org/#/r/69cp/edit
<FromGitter> <Blacksmoke16> so tl;dr you want to read from a csv and have the values be casted to the given types?
<FromGitter> <Fryguy> You have this line, which is your expectation: ⏎ ⏎ > puts Items[1]["required_level"] should return a String type, with a value of 1, not a union (Int32 | Float64 | String) ⏎ ⏎ but it will always be a union because that's how you declared your Hash [https://gitter.im/crystal-lang/crystal?at=5c67296929bd7b606eb227db]
<FromGitter> <girng> yeah!
<FromGitter> <Fryguy> The compiler can't know runtime values, so it can only know but all of the possible types
<FromGitter> <girng> @Fryguy i could use to_type on them tho right?
<FromGitter> <girng> to make a new/fresh hash statically typed?
<FromGitter> <Fryguy> you will always have a union type at the getter, because that's how you defined the values: Items = `Hash(Int32, Int32 | Float64 | String).new`
<FromGitter> <Fryguy> you would have to create separate hashes *or* cast them after you get them
<FromGitter> <girng> yeah, i guess that's what i mean, "cast them after"
<FromGitter> <Fryguy> yes, you can cast them after
<FromGitter> <Fryguy> but you will have to deal with exceptions if the values are not castable
<FromGitter> <Fryguy> like if someone put a "string" in the item_id section or whatever
<FromGitter> <girng> yah hmm
<FromGitter> <Fryguy> it would be cool if the YAML mapper and JSON mapper had a similar mapper for CSV but I don't think it has it
<FromGitter> <Blacksmoke16> it doesnt
<FromGitter> <Blacksmoke16> would be tricky as there isnt a defined schema
<FromGitter> <Blacksmoke16> would like have to know which index to fetch each value
<FromGitter> <Blacksmoke16> vs key
<FromGitter> <Fryguy> yeah, it would have to assume headers
<FromGitter> <Fryguy> then map header names to index positions or somsething
<FromGitter> <Blacksmoke16> mhm
<FromGitter> <Blacksmoke16> probably doable
<FromGitter> <Fryguy> actually, without headers, I could see just index positions as the key
<FromGitter> <Blacksmoke16> but you would need a way to map index value to property name if you wanted it to work like json/yaml
<FromGitter> <Blacksmoke16> could be annotation
<FromGitter> <Fryguy> yeah true
<FromGitter> <Fryguy> or if indexes, it just creates fake accessors like "index_0"
<FromGitter> <Blacksmoke16> @girng any chance you could store this as json/yaml then just do `from_*`?
<FromGitter> <girng> i do that for levels, quests, and other data, but for items.. all the redudant keys with json result in a huge .txt file. , 40kb compared to just 7kb, and that's only with 82 items in the db, it'll be much larger once i start adding more items. i plan to have hundreds if not thousands. so i really want to stick with csv
<FromGitter> <girng> for items*. for other data, like levels and quests it's fine
<FromGitter> <Blacksmoke16> 😐
<FromGitter> <Blacksmoke16> fair enough
<FromGitter> <Fryguy> another option is to just zlib compress the data (json duplicated keys should compress really nicely), then feed that Zlib wrapper io into JSON
<FromGitter> <girng> @Blacksmoke16 let me show you what i wrote so far, one second
<FromGitter> <Blacksmoke16> 👍
<FromGitter> <girng> @Blacksmoke16 for example, look here: https://play.crystal-lang.org/#/r/69dk i casted those properties in the csv, and they are still a union!
<FromGitter> <Blacksmoke16> well yea it doesnt know at runtime what type it is
<FromGitter> <Blacksmoke16> sec
<FromGitter> <girng> that's what @Fryguy is talking about lol
<FromGitter> <Fryguy> yeah, that's what I was saying about the getter
<FromGitter> <Fryguy> you have to do a to_i or the like *after* the getter to get the type you want
<FromGitter> <girng> yeah exactly, i hate that lol
<FromGitter> <girng> tbut i mean, i'll do it i have to...
<FromGitter> <girng> i do it all over already hahahahah
<FromGitter> <girng> i do all this work to get my types casted and then i hve to write .to_xxx.. feels like i'm stabbing myself each time xD
<FromGitter> <Fryguy> yeah, unfortunately that's the nature of serializing to things that don't support native types
<FromGitter> <Fryguy> hence why @Blacksmoke16 asked about json
<FromGitter> <Blacksmoke16> give me a min
markong has joined #crystal-lang
markoong has quit [Ping timeout: 245 seconds]
<FromGitter> <Fryguy> OMG, LOL, I'm playing around trying to get an example for @girng and nothing's working and I can't figure out why
<FromGitter> <Fryguy> turns out I typed `irb` instead of `icr` 😂
<FromGitter> <girng> only reason i'm complaining cause when a player equips an item ineed to check required_level against client.level.. and i wrote `["required_level"].to_i > client.level` and was like EWWW this feels wrong. since i already have my csv_to_dict method and casting them
<FromGitter> <Fryguy> In that case instead ofusing a Hash -> Union of stuff I woulduse a Hash -> Struct
<FromGitter> <Fryguy> that way you can define those fields individually
<FromGitter> <girng> yeah
<FromGitter> <Fryguy> so it would be `Items[0].required_level` and there you can control the type
<FromGitter> <girng> basically, i'm wanting a csv.mapping lol
<FromGitter> <Fryguy> yeah 😄
<FromGitter> <girng> errr. should i say CSV.mapping 😆
<FromGitter> <girng> i'm weird though. i don't do thinks conventional or normal in programming. which really, can be a good thing because it allows me to subconsciously write code and makes me feel good. but on the other hand, 95% of the time i end up not being able to solve certain issues and then ultimately confuse myself
<FromGitter> <girng> but then, if i see fancy code like from lead devs, blacksmoke, or whoever.. my mind is like O_O
<FromGitter> <girng> @Fryguy nice website 🆒 i thought it was an image at first LOL
<FromGitter> <Fryguy> oh haha
<FromGitter> <girng> then i highlighted it all and was like ayyeee
<FromGitter> <Fryguy> I did that with some gif => ascii tool ages ago, and totally forgot about it 😆
<FromGitter> <girng> much better than 90% of the websites out there! nowadays, sites are riddled with too much stuff, i hate it
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/69f6
<FromGitter> <Blacksmoke16> is what i had in mind
<FromGitter> <Blacksmoke16> prob would have to edit it a bit but general idea is there
<FromGitter> <Blacksmoke16> like prob make it a class method that will iterate over each row and return `Array(Item)`
<FromGitter> <Blacksmoke16> that could be empty or just 1 item
<FromGitter> <girng> @Blacksmoke16 wow, very cool
<FromGitter> <Blacksmoke16> now compiler can enforce the types since its struct
<FromGitter> <Fryguy> nice @Blacksmoke16
<FromGitter> <Blacksmoke16> working wish hashes never ends well
<FromGitter> <Blacksmoke16> structs is always a better idea
<FromGitter> <Blacksmoke16> almost*
<FromGitter> <girng> so neat to see this
<FromGitter> <Sija> `Regex::Options` no has `UNGREEDY`, arrgghh!
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/69fm better version, handles missing header keys
<FromGitter> <drum445> Anyone mind checking out my (very early) attempt at a kanban app - zaybul.com/kanban ?
<FromGitter> <Blacksmoke16> content never loads :trollface:
<FromGitter> <drum445> oh nah ignore that landing page ;)
<FromGitter> <Fryguy> @girng Here's an example where I used the Zlib class to acts as a compression layer on the json data, should you choose to store it in json instead of CSV - https://play.crystal-lang.org/#/r/69fq
<FromGitter> <drum445> create a random account (top right) then you can create a board and have a play about :)
<FromGitter> <Fryguy> I tried to use similar values to show the type of compression you get when there's a lot of duplicated data (in this example roughly 90%)
<FromGitter> <Fryguy> so, if you were store it in JSON, you could leverage the JSON.mapping, but still not have to worry as much about the size-on-disk
<FromGitter> <Blacksmoke16> any reason to not use a db for this?
<FromGitter> <Blacksmoke16> even sqlite wouldn't be too bad
<FromGitter> <drum445> not sure how much data there is, but sqlite would probably be more performant
<FromGitter> <Blacksmoke16> > i plan to have hundreds if not thousands. ⏎ ⏎ so not much data
<FromGitter> <Blacksmoke16> in the grand scheme of things
<FromGitter> <girng> @Fryguy interesting, thx for the example
<FromGitter> <drum445> yeah that's very small - if you ever need to update a row though
<FromGitter> <Fryguy> I agree with the rest on sqlite, though
<FromGitter> <Fryguy> depends on how static/dynamic the data is
<FromGitter> <girng> i use also use csv because in godot, parsing a 100kb+ json with redundant keys is much slower than a csv one. i did tests on this. i want the game client to open fast and with csv, it's much faster
<FromGitter> <girng> so.. i use csv on server file Items data as well, keep it consistent
<FromGitter> <Blacksmoke16> you do you
<FromGitter> <Sija> I was pretty sure there was sth like a class initializer `self.init`, anyone had experience with this?
<FromGitter> <Blacksmoke16> `self.new`?
<FromGitter> <Fryguy> @Sija or do you mean .allocate?
<FromGitter> <Sija> no no, I mean a method which gets called just once for a Class
<FromGitter> <Blacksmoke16> @girng so like does the sever send the client the csv file?
<FromGitter> <Sija> not *instances* of that class, just the class itself
<FromGitter> <Sija> seems I was wrong since I can't find any reference to such concept… (many `self.init` definitions but they're all executed manually l8r in the code)
<FromGitter> <Fryguy> I know there are macros you can hook for things like when a Class is inherited, for example...maybe you can hook Object.inherited ? https://crystal-lang.org/reference/syntax_and_semantics/macros/hooks.html
<FromGitter> <Fryguy> but it's all at compile-time, so not sure that's useful for you
<FromGitter> <girng> @Blacksmoke16 nah, it's shipped with the client. if new update, the launcher will update new files though
<FromGitter> <j8r> i've a question about fds
<FromGitter> <Blacksmoke16> has to be some better way to handle that
<FromGitter> <j8r> if i create a class that creates a FD in initialize
<FromGitter> <j8r> do i need to close the FD in finalize?
<FromGitter> <Sija> @j8r most likely
<FromGitter> <Sija> other it'll leak till you kill your app
<FromGitter> <j8r> thx @Sija , i w suspecting this kind of messy things
<FromGitter> <Sija> after some time you'd run into things like these - https://access.redhat.com/solutions/19225
<FromGitter> <j8r> that's bad :/
<FromGitter> <j8r> what's the default limit usually, is it `ulimit -n`?
<FromGitter> <girng> i had to add `LimitNOFILE=655360` under `[System]` in my .service file to get around that limit
<FromGitter> <anamba> @Sija Thanks for following up. I still haven't had a chance to dig deeper, was just hoping you had some troubleshooting tips, since I was trying to fix a particular issue in my app that was only being reported sometimes by raven. But I ended up fixing that issue in my app yesterday.
<FromGitter> <Sija> ah, I see.
<FromGitter> <Sija> my only hunch it was related to crystal ssl handling itself.
<FromGitter> <Sija> recently there were several ssl-related issues opened on the crystal issue tracker
<FromGitter> <Sija> sorry I can't help more :/
<FromGitter> <anamba> @Sija i think you may be correct. i have been having some general ssl issues that i can't quite pin down. i'll check the crystal issues later when i encounter them again