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> <Sija> that's how `extend`-ing works, IIRC it's the same as in Ruby
<FromGitter> <dscottboggs_gitlab> Yeah I kinda get it now. Modules can be `include`d in classes but `extend` each other.
<FromGitter> <dscottboggs_gitlab> also I've been learning ruby from crystal haha. I came to Crystal from python through go
<FromGitter> <Blacksmoke16> ye, include makes the methods in the module available as instance methods while extend makes them class methods
jemc has joined #crystal-lang
Groogy has quit [Read error: Connection reset by peer]
<FromGitter> <sam0x17> anyone know when https://pkgs.alpinelinux.org/package/edge/community/x86_64/crystal is going to get the 0.27.1 update? been quite a while :/
<FromGitter> <Blacksmoke16> 1) 27.2 is the newest as well
<FromGitter> <sam0x17> yes :/
<FromGitter> <sam0x17> alpine is how everyone does static compilation, so I'm surprised it takes so long to get newer versions
<FromGitter> <Blacksmoke16> indeed
fanta7531 has joined #crystal-lang
<FromGitter> <Sija> @sam0x17 shouldn't be surprising that much, given the limited amount of resources Manas has, packages (aside of most popular ones, i.e. debian and homebrew) are solely maintained by their respective maintainers
<FromGitter> <Sija> I'd love for one having nightlies working in Travis CI, but it still didn't happen and who knows when (or if) it will...
fanta7531 has quit [Quit: fanta7531]
sagax has joined #crystal-lang
<FromGitter> <Blacksmoke16> ayy
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6a1e16adf6cb0b2cd83af9]
<FromGitter> <Blacksmoke16> found a fellow crystaler :p
_whitelogger has joined #crystal-lang
jemc has quit [Ping timeout: 240 seconds]
jemc has joined #crystal-lang
jemc has quit [Ping timeout: 240 seconds]
jemc has joined #crystal-lang
jemc has quit [Ping timeout: 246 seconds]
jemc has joined #crystal-lang
jemc has quit [Ping timeout: 272 seconds]
DTZUZO_ has joined #crystal-lang
DTZUZO has quit [Ping timeout: 250 seconds]
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
hightower2 has joined #crystal-lang
<FromGitter> <sdogruyol> 👋
<FromGitter> <sdogruyol> @Blacksmoke16 great, what's eve?
<mps> sam0x17: test fails for 0.27.1 and 0.27.2 on Alpine, need fix in crystal
<mps> it couldn't pass abuild check, so couldn't be upgraded in Alpine
<FromGitter> <awws_twitter> Does anyone have any good pointers to a post on reading a yaml file (essentually an array of hashes) and transforming/pouring that into a struct of the same format? I am definitely doing something wrong here that woud work in ruby or elixir but assuming the type safety is casuing issues (ie. the types are the same but because I've defined the Array as a an array of struct X where struct X is a string: i32
<FromGitter> ... and then tried to load in the yaml into thar structure it's really really not liking it. Think I just need to see some canonical examples.
wakatara has joined #crystal-lang
wakatara has quit []
<FromGitter> <girng> @sdogruyol eve online maybe?
<FromGitter> <sdogruyol> :shrug: how's your game going on @girng ?
<FromGitter> <girng> @sdogruyol good, doing item loot RNG. something like this: https://play.crystal-lang.org/#/r/6a6o/edit still working on it
<FromGitter> <sdogruyol> we have some built-in good RNGs in stdlib
<FromGitter> <j8r> mps is it the issue about encoding?
<mps> j8r: failed tests? something with XML, iirc
<mps> could be encoding with XML
<mps> probably RX14 and straight-shoota could give better answers than I
<FromGitter> <delef> Hi! Tell me how to remove Slice(UInt8) from memory? I work with a large binary database and I want to clear the memory of it after I do the parsing.
<FromGitter> <maiha> `GC.collect` ?
<FromGitter> <delef> @maiha I need to remove from memory only Slice(UInt8), will it help?
<FromGitter> <delef> something like this? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6aad4ad1e3093ab53f378e]
<FromGitter> <maiha> Yep, I imaged it. It worked?
marmotini_ has joined #crystal-lang
<FromGitter> <maiha> I tried it myself, but it didn't free the memory. Wait for an expert to appear. :-)
<FromGitter> <j8r> Interesting
<FromGitter> <j8r> We can do `Bytes[]`, but not `Array[]` - we have to use `Array{}`
rohitpaulk has joined #crystal-lang
<FromGitter> <delef> @maiha it didn't free the memory for me too
<FromGitter> <delef> Why Array haven't #to_slice method? ⏎ `[1u8, 0u8, 0u8, 0u8].to_slice # => Bytes[1u8, 0u8, 0u8, 0u8]`
<FromGitter> <asterite> memory gets free eventually by the GC, don't worry about that
<FromGitter> <asterite> Array has no `to_slice` because the buffer can be reallocated, so it would be unsafe
<FromGitter> <delef> @asterite but how do I brutally clear my memory? ⏎ ⏎ I need something like that: ⏎ ⏎ ```db = DB.open("/path/to/large_file.bin")``` [https://gitter.im/crystal-lang/crystal?at=5c6abb6c604f233ab62e29e1]
<FromGitter> <delef> after calling #close method, I no longer need `/path/to/large_file.bin` in memory
<FromGitter> <j8r> @Sija I was lurking of `Slice[0, 1, 2]`, with https://github.com/crystal-lang/crystal/blob/master/src/slice.cr#L31 we can have the same perf of `of` with a syntax like `Array(Int32 | String)[0, 1, 2]` :D
<FromGitter> <j8r> https://carc.in/#/r/6a8w cool, nah?
<FromGitter> <silmanduin66> Hello i just started with a crystal websocket chat , my idea was to keep the messages in a database using granite and postgresql. Is this the right way to do this ? and what is the limit of messages that can fit into such database ?
<FromGitter> <j8r> https://carc.in/#/r/6a91 ;(
<FromGitter> <dscottboggs_gitlab> @delef if you're super insistent on controlling when you free a section of memory, you could use unsafe code for that section, but if you're going to do that I would recommend using a class to allow the GC to make sure your unsafe code is handled right. For example (I'm not super experienced at unsafe code so maybe it's not perfect) something like this: ⏎ ⏎ ```code paste, see link```
<FromGitter> <dscottboggs_gitlab> @j8r why isn't it working?
<FromGitter> <dscottboggs_gitlab> also wouldn't that incur a performance penalty?
<FromGitter> <dscottboggs_gitlab> oh, no, because it uses .build instead of `<<`
<FromGitter> <dscottboggs_gitlab> @silmanduin66 yeah, Granite+Postgres is fine
<FromGitter> <j8r> 💀 https://carc.in/#/r/6a9f
hightower2 has quit [Ping timeout: 255 seconds]
<FromGitter> <Blacksmoke16> @sdogruyol yea Eve online
<FromGitter> <Blacksmoke16> Is q game that has really nice third party developer support. Is a good developer community within it
<FromGitter> <Blacksmoke16> https://esi.evetech.net/ui/
<FromGitter> <Blacksmoke16> Is their API
jemc has joined #crystal-lang
<FromGitter> <j8r> @asterite I still don't get why you create a merge commit for single commit PRs... :|
marmotini_ has quit [Ping timeout: 245 seconds]
jemc has quit [Quit: WeeChat 2.2]
<FromGitter> <yxhuvud> Because it is nice to see the meta info of that merge commit, like the PR number.
<FromGitter> <yxhuvud> I wish github would have an option to rebase merges, but with `no-ff` flag set
rohitpaulk has quit [Ping timeout: 246 seconds]
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
marmotini_ has joined #crystal-lang
dannyAAM has quit [Quit: znc.saru.moe : ZNC 1.6.2 - http://znc.in]
dannyAAM has joined #crystal-lang
<FromGitter> <asterite> @j8r I'm not in charge :-)
<FromGitter> <j8r> I guess it's because someone haven't change the default merge option in GitHub
<FromGitter> <j8r> I usually set it to rebase and merge, often that's what I want :)
<FromGitter> <j8r> else it's a pain to search in the history with all this merge commits :(
<FromGitter> <asterite> My understanding is that they explicitly removed the "rebase" option... for some reason
<FromGitter> <j8r> or squash and merge?
<FromGitter> <asterite> I like rebase
<FromGitter> <j8r> for one commit PRs, rebase and squash is the same
<FromGitter> <j8r> me too
<Yxhuvud> rebase is nice, bit for multi commit PRs, it is not as nice as they can't be reverted in one go. hence, the need for rebase but no-ff
marmotini_ has quit [Ping timeout: 272 seconds]
marmotini_ has joined #crystal-lang
marmotini_ has quit [Remote host closed the connection]
marmotini_ has joined #crystal-lang
marmotini_ has quit [Ping timeout: 246 seconds]
marmotini_ has joined #crystal-lang
oz has quit [Quit: EOF]
marmotini has joined #crystal-lang
marmotini_ has quit [Ping timeout: 246 seconds]
oz has joined #crystal-lang
marmotini has quit [Ping timeout: 250 seconds]
<FromGitter> <Blacksmoke16> well the type of `subject` is different
<FromGitter> <Blacksmoke16> in each module
<FromGitter> <Blacksmoke16> hence the error you get
<FromGitter> <Blacksmoke16> its a compile error saying, hey, you need to make sure this variable is the type you are expecting, as you cant call `hi` on type `String`
<FromGitter> <hanneskaeufler> I get that, but `subject` is only a string in `A::B`, not `A::C`
<FromGitter> <hanneskaeufler> Does that var get implicitly defined on `A` somehow?
<FromGitter> <dscottboggs_gitlab> yeah...that's weird IMO
<FromGitter> <hanneskaeufler> Or is it simply a local variable not at all attached to a module? In which case I would understand the error and the fact that it runs when inside two separate files ...?
<z64> temporary vars aren't scoped to modules https://carc.in/#/r/6afj
<FromGitter> <dscottboggs_gitlab> what are they scoped to then?
<FromGitter> <hanneskaeufler> *files* I guess? :D
<z64> the issue in your code is that the union is introduced by closuring `subject` https://carc.in/#/r/6afm
<FromGitter> <hanneskaeufler> Huh, now you lost me :D
<z64> basically, when you write `it "foo" do..` you're registering a piece of code to be run *some time* at runtime. the compiler doesn't know when it will be executed. since "subject" is essentially global, it sees at one point you assign it as String, and at one point you assign it as Foo
<FromGitter> <hanneskaeufler> Okay yeah, thanks.
<z64> this might be more clear: https://carc.in/#/r/6afy
<FromGitter> <hanneskaeufler> So coming back around: I see that pattern used sometimes `subject = ...` in specs, and when I copy & paste multiple specs into a single file, that blows up
<FromGitter> <hanneskaeufler> yeah okay thats more minimal
<z64> well, i'd have to see a specific case. but in general, you have a few options. one is to not closure subject; i.e., subject is defined completely in scope of the spec block https://carc.in/#/r/6ag0
<z64> another is to have `subject` be a method, which is actually scoped to the module https://carc.in/#/r/6ag3
<z64> lastly, you can just give subjects special names. `b_subject = ..`, `a_subject = ..`
<FromGitter> <hanneskaeufler> yep thanks for the suggestions!
<z64> or i guess, if you keep specs organized by one type -> one file, `subject` will generally always be a single type, in which case it won't be an issue to share `subject` between tests
<z64> yw
<FromGitter> <hanneskaeufler> My problem is I'm running a third party tool over code that isn't under my control haha
<FromGitter> <hanneskaeufler> Can I ... rescope files?
<FromGitter> <hanneskaeufler> like in javascript I'd wrap files in a self-invoking function `(..)()` or something
<z64> i don't really know what that means, but i'm inclined to say "no". `require` is a compiler mechanism, and is done once per file at compile time
<FromGitter> <hanneskaeufler> That'd not be a problem, I am hooking into `require` through the ast :D
<z64> what exactly is this...? i'm assuming some kind of code coverage tool?
<FromGitter> <hanneskaeufler> yes, mutation testing https://github.com/hanneskaeufler/crytic
<z64> neat
<FromGitter> <hanneskaeufler> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c6b0c6c28c89123cbee79c4]
<FromGitter> <hanneskaeufler> would that rescope it as I hope it would?
<z64> well, you cannot do `module`, `class`, etc. inside of a block
<FromGitter> <hanneskaeufler> Ah no, cant define module dynamically
<FromGitter> <dscottboggs_gitlab> can't define ANY constant dynamically
sevensidedmarble has joined #crystal-lang
<FromGitter> <Blacksmoke16> coughmacroscough
<FromGitter> <Blacksmoke16> best you could do
<z64> totally uninformed suggestion, but would patching the `Spec` API possibly allow you to do what you want?
<z64> i.e. rewrite Spec `it` to your own `it`
<FromGitter> <hanneskaeufler> @Blacksmoke16 how could a macro help me?
<FromGitter> <Blacksmoke16> not sure, what are you trying to do?
<FromGitter> <hanneskaeufler> Making https://carc.in/#/r/6aga run without any changes to code in between `module ... end` :)
aither has left #crystal-lang ["WeeChat 2.2"]
<FromGitter> <Blacksmoke16> https://carc.in/#/r/6agf
<FromGitter> <Blacksmoke16> tada?
<FromGitter> <Blacksmoke16> https://carc.in/#/r/6agg *
<z64> i imagine this is user code, and you don't want to expose any custom spec API so that everything works out of the box without any changes?
<z64> @Blacksmoke16 not quite, you made changes inside of `module` :p
<FromGitter> <Blacksmoke16> well something is going to have to change, running it a bunch of times isnt going to fix the problem :p
<FromGitter> <hanneskaeufler> > *<z64>* i imagine this is user code, and you don't want to expose any custom spec API so that everything works out of the box without any changes? ⏎ Exactly that
<z64> right, ok. yeah i'm not sure then. that's pretty brutal.
<FromGitter> <hanneskaeufler> I'm just holding off running everything in a copied directory and writing the files back out for as long as possible
<FromGitter> <hanneskaeufler> although thats probably the most compatible way ... :(
<FromGitter> <hanneskaeufler> I started piping all the code into `crystal eval` at first, but that had it's own limitations
<FromGitter> <asterite> variables anywhere in the top-level (inside modules, classes, etc.) all have the same scope. That's not very good, but that's how it is right now
<FromGitter> <dscottboggs_gitlab> heres a fun one https://carc.in/#/r/6agh
<FromGitter> <dscottboggs_gitlab> oh that's because I'm using `when` I see now
<FromGitter> <dscottboggs_gitlab> > anywhere in the top-level (inside modules, classes, etc.) all have the same scope ⏎ ⏎ Oh I seee, that makes some sense, I was worried about cross-function variables being polluted, but if it's just top-levels then that's understandable
<z64> i think the only reasonable thing you can do right now is just ask users to use meaningful names other than just "subject" everywhere. even if you have many specs, this is just a simple search/replace per-file. maybe there is a deeper hack you could do, but that's the best "workaround"..
<FromGitter> <Blacksmoke16> or wrap everything in begin/end and use the fresh variable macro thing https://carc.in/#/r/6agp
<FromGitter> <dscottboggs_gitlab> ooh yeah that poses some serious issues when it comes to specs... could you use https://crystal-lang.org/reference/syntax_and_semantics/macros/fresh_variables.html
<FromGitter> <dscottboggs_gitlab> yeah that
<FromGitter> <dscottboggs_gitlab> beat me to it by a second lol
<z64> no, they can't change the users variables to fresh variables
<z64> they are taking specs that someone has *already written* - they could be in any form, using any kind of convention or practice for writing specs
<FromGitter> <Blacksmoke16> ah
<FromGitter> <Blacksmoke16> hrm
<FromGitter> <hanneskaeufler> yeah I'm trying to keep the specs *as is*, because it is after all valid crystal
<FromGitter> <Blacksmoke16> yea, top level vars would be an issue if they conflict
<FromGitter> <Blacksmoke16> if everything is within a like `describe` block that scopes the var
<FromGitter> <dscottboggs_gitlab> I think you'd have to reimplement `describe` or `it` with your feature added?
<FromGitter> <Blacksmoke16> or like how does this user code get into your modules?
<FromGitter> <hanneskaeufler> Those modules aren't mine either
<FromGitter> <hanneskaeufler> many crystal users write specs in modules though
<FromGitter> <hanneskaeufler> makes them read less verbose
<FromGitter> <hanneskaeufler> because the class names get much shorter if you use modules as namespaces
<FromGitter> <silmanduin66> can someone tell me how to pass an array of value from crystal to javascript ( in the amber framework ) . For the moment i can only pass them by rendering them using slang and then access them with javascript . Is there a direct/ faster way to do it ?
sevensidedmarble has quit [Quit: Leaving]
<FromGitter> <dscottboggs_gitlab> you can render the JSON, or connect to Amber using the amber.js library which allows you to communicate over websockets
<FromGitter> <dscottboggs_gitlab> Or you could have the JS make an XHR to the server and get the data as a JSON response
<FromGitter> <dscottboggs_gitlab> The last one is how I do it in flix.cr -- the web page is downloaded to the browser, displays a basic loading screen, then reaches out to the server for JSON-formatted application state
<FromGitter> <silmanduin66> i'm using websockets for a chat , i want to the user access to maybe 20 messages that are in the database
<FromGitter> <silmanduin66> yes using amber.js for now
<FromGitter> <dscottboggs_gitlab> yeah if you already have a websocket connection, just send a message to the server (protocol is up to you) and pull the array across that as json
<FromGitter> <silmanduin66> oh i see
<FromGitter> <silmanduin66> thank you ill try that
<FromGitter> <dscottboggs_gitlab> I should probably switch flix.cr to websockets for performance's sake... hm...
<FromGitter> <kingsleyh> hey - how can I supply my own to_json for an Enum - I put a def to_json method on the Enum but it seems to ignore it
<z64> how exactly are you defining it? it needs to be like `def to_json(builder : JSON::Builder)`, and then you write your values to that builder
<FromGitter> <Sija> @silmanduin66 there's also https://github.com/crystal-community/msgpack-crystal which you might want to take a look at if you need efficiency
<FromGitter> <kingsleyh> oh I did't supply any paramter
<z64> yeah. `#to_json` (with no parameter) is already defined on every type. that method is usually called - by you - on the outermost type, which internally makes a new `JSON::Builder` and passes it around via `#to_json(builder)` to that types components (or itself)
<FromGitter> <kingsleyh> how do I access the value as a string within the to_json?
<FromGitter> <dscottboggs_gitlab> @Sija thanks, I didn't know about that
<z64> just as you would with an enum instance - to_s
<FromGitter> <Sija> @dscottboggs_gitlab 👍
<FromGitter> <kingsleyh> ``` def to_json(builder : JSON::Builder) ⏎ to_s.to_json(builder) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5c6b242c85b7eb4569f35924]
<z64> sure, or simply `builder.string(to_s)` / `builder.string(self.to_s)` etc.
<FromGitter> <kingsleyh> ok thanks :)
<FromGitter> <girng> hey
<FromGitter> <girng> ``` x = msg["message"]["x"].as_i ⏎ x = x.clamp(0, 20)``` ⏎ ⏎ i did not know we could chain the clamp. `x = msg["message"]["x"].as_i.clamp(0, 20)` is valid. 😀 :D :D [https://gitter.im/crystal-lang/crystal?at=5c6b3c19c776985d8f1657ad]
<FromGitter> <girng> i just saved a few lines of redundant code!
<FromGitter> <girng> wow, i did about 85% of my marketplace code in php (listing, searching mod affixes, your item listings, sort by price and item affix values, cancel listing, etc). now, i'm doing the purchasing and retrieving an item (insert to inventory) on the gameserver. the simplicity of crystal DB's API is AMAZING compared to what i just coded in php 😆