ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.19.4 | Fund Crystals development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
<FromGitter> <drosehn> Hmm. There's no way to make the value for `strict=` to be a run-time option, is there?
<BlaXpirit> drosehn, yes and no..
<BlaXpirit> you can copy the entire macro and change it to be a runtime if, not a macro if https://github.com/crystal-lang/crystal/blob/0.19.4/src/json/mapping.cr#L113
<BlaXpirit> though it might also be a harmless change to stdlib to have it like that
<FromGitter> <drosehn> Ah, yeah, that gives me some interesting ideas. thanks.
soveran has quit [Remote host closed the connection]
shawn42 has quit [Quit: Connection closed for inactivity]
bjz has joined #crystal-lang
Philpax has quit [Ping timeout: 260 seconds]
perks has quit [Quit: perks]
emancu has joined #crystal-lang
bjz has quit [Read error: Connection reset by peer]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 256 seconds]
pduncan has joined #crystal-lang
<FromGitter> <drosehn> Hmm. I wonder if there is some max-depth or something with JSON's `mapping()` macro. It turns out that the JSON in my source files is pretty complicated. It's impressive how flexible `mapping()` is, and how it's able to handle *almost* everything I need.
<FromGitter> <drosehn> I'm down to one last variable, which needs to be `v: String | Nil`. If I define it as just `v: String`, everything works except that there are three records in my source file which do not have this `v:` value defined.
<FromGitter> <drosehn> But if I *do* define it as `v: String | Nil`, then those same three lines run into an error of `Error: couldn't parse (String | Nil) from 1359608400 at 0:0`.
<FromGitter> <drosehn> I have plenty of other entries defined as `something: String | Nil`, and all of those work fine. I've even copied-and-pasted one of those lines into this call to `mapping()` (from a call in a different class), and then changed 'something' to 'v', and it still fails.
<FromGitter> <drosehn> But my program is already doing much better than I expected it to do, and I don't really care about the JSON fields which end up in this class. So I just commented out the `v: String | Nil` line, and turned `strict:` off for the`mapping()` of this class.
<FromGitter> <drosehn> Unfortunately my data files include a lot of sensitive info, so it'd be way too much work for me to come up with an example.
<FromGitter> <cjgajard> Did you tried using `v: {type: String, nilable: true}` instead of `v: String | Nil`??
<FromGitter> <cjgajard> nope, sorry, "Passing T | Nil as a type has the same effect"
<FromGitter> <drosehn> I did try that just in case it was some obscure bug, but I did end up with the same errors.
<FromGitter> <drosehn> (I certainly don't know enough about crystal macros to try and debug this!)
<FromGitter> <drosehn> Hmm. I should probably enter this as an "issue" on github, but I've been too much of a pest in the last few days. Maybe in a few days, if I can't come up with any insights on it.
<FromGitter> <drosehn> g'night...
snsei has joined #crystal-lang
emancu has quit [Ping timeout: 244 seconds]
pawnbox has joined #crystal-lang
soveran has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
soveran has quit [Ping timeout: 256 seconds]
pawnbox has joined #crystal-lang
pawnbox_ has joined #crystal-lang
pawnbox has quit [Ping timeout: 265 seconds]
emancu has joined #crystal-lang
pawnbox_ has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pduncan has quit [Ping timeout: 240 seconds]
soveran has joined #crystal-lang
bjz has joined #crystal-lang
bjz has quit [Read error: Connection reset by peer]
soveran has quit [Ping timeout: 256 seconds]
bjz has joined #crystal-lang
bjz has quit [Read error: Connection reset by peer]
bjz has joined #crystal-lang
emancu has quit [Ping timeout: 245 seconds]
soveran has joined #crystal-lang
emancu has joined #crystal-lang
<FromGitter> <choallin> Hey folks! Since I am talking a look into FP languages as well right now I was wondering how well Crystal is handling FP style. ⏎ I know it has many of the features that Ruby has and therefore it works with that style as well, but I'm wondering how efficient Crystal is if I'm using e.g. a lot of recursion and stuff like this. Are there any information about that? :smile:
snsei has quit [Remote host closed the connection]
pawnbox has quit [Remote host closed the connection]
akwiatkowski has joined #crystal-lang
pawnbox has joined #crystal-lang
mark_66 has joined #crystal-lang
bjz_ has joined #crystal-lang
snsei has joined #crystal-lang
bjz has quit [Ping timeout: 244 seconds]
snsei has quit [Ping timeout: 258 seconds]
pawnbox has quit [Read error: Connection reset by peer]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
hako has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 240 seconds]
pawnbox has joined #crystal-lang
<FromGitter> <mverzilli> hi @choallin, if you go that way you'll be wrestling a lot with the language features and the std lib design. not that I don't like FP (on the contrary, I love it!), but Crystal is designed as an imperative OOP language from the ground up
<FromGitter> <mverzilli> there are some features from FP that you could mimic in Crystal (like currying) but that's about it. if you're looking for a language somehow resembling Ruby that embraces FP maybe you can give Elixir a try
hako has quit [Ping timeout: 260 seconds]
hako_ has joined #crystal-lang
soveran has quit [Remote host closed the connection]
<FromGitter> <choallin> Thanks for the answer @mverzilli ⏎ I don't want do use Crystal as a full blown FP language but these days I often find myself writing (business logic) code that is stateless and has as few side effects as possible. To do this, I use the FP methods that are build in Ruby (map, reduce,...) and are also there in Crystal. But also I like to write some loops as recursions since this appears more natural too me. So, I was wondering
<FromGitter> ... if there are any tail recursion optimizations made in Crystal. :smile:
<FromGitter> <greentornado> Is there any eventbus for crystal
<BlaXpirit> and what would that be
<txdv> its a bus for events
soveran has joined #crystal-lang
soveran has quit [Remote host closed the connection]
soveran has joined #crystal-lang
soveran has joined #crystal-lang
soveran has quit [Changing host]
Philpax has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 256 seconds]
bjz_ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
shawn42 has joined #crystal-lang
Philpax has quit [Ping timeout: 260 seconds]
soveran has quit [Remote host closed the connection]
perks has joined #crystal-lang
snsei has joined #crystal-lang
emancu has quit []
Raimondii has joined #crystal-lang
Raimondi has quit [Remote host closed the connection]
Raimondii is now known as Raimondi
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 256 seconds]
<FromGitter> <samueleaton> @greentornado Like something similar to the Node.js event emitter? https://nodejs.org/api/events.html#events_class_eventemitter
<FromGitter> <samueleaton> Is there a major difference here that I might overlook? I am in need of an asynchronous method. ⏎ ⏎ ```def do_something ⏎ ... ⏎ end ⏎ ⏎ spawn { do_something }``` [https://gitter.im/crystal-lang/crystal?at=5824a224c2f2cf7275f47694]
<FromGitter> <samueleaton> @choallin it looks like LLVM will automatically do tail rec optimizations in `--release` mode. https://github.com/crystal-lang/crystal/issues/2021
<FromGitter> <samueleaton> @choallin actually, in the comments here it looks like it isn't guaranteed https://crystal-lang.org/2016/07/15/fibonacci-benchmark.html
mark_66 has quit [Remote host closed the connection]
Yxhuvud has quit [Remote host closed the connection]
Yxhuvud has joined #crystal-lang
<BlaXpirit> samueleaton, there is no difference between two options regarding `spawn`
_whitelogger has joined #crystal-lang
<FromGitter> <paulcsmith> Any ideas on how to get this working? https://gist.github.com/paulcsmith/63a729638b52899db57dc8c886cdee0c
<FromGitter> <paulcsmith> The model_class appears to be a `Path`, but I'd like to treat it as the constant so I can access the `FIELDS` constant. Any ideas how to do that?
<FromGitter> <paulcsmith> I've tried a few things, but haven't been able to figure it out :S
<FromGitter> <paulcsmith> I can do `model_class.resolve` which returns the constant (at least that's what appears to happen), but then I still get the "unexpected token" error. Maybe there is a method for getting a constant instead of using `::`?
<BlaXpirit> paulcsmith, you can't put :: after a lowercase identifier
<BlaXpirit> so what you're trying to do is probably impossible
<BlaXpirit> paulcsmith, then again, there is https://crystal-lang.org/api/0.19.4/Crystal/Macros/TypeNode.html#constants%3ACrystal%3A%3AMacros%3A%3AArrayLiteral%28MacroId%29-instance-method
<BlaXpirit> but it seems to be just names of constants..?
<FromGitter> <paulcsmith> Yeah I think you're right. It seems you can't use `::` after lower case as you said. I was hoping there was a method that would allow me to do something similar, but maybe not :(
<RX14> BlaXpirit, but you get a constant node which has the full path which can then be pasted
<BlaXpirit> true, good idea
<BlaXpirit> can't iterate over those FIELDS though
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 256 seconds]
<FromGitter> <paulcsmith> Yeah I'm trying to iterate over the fields :S Haven't been able to find away to do that
<FromGitter> <redcodefinal> Good morning Crystal community. May your code be type safe, readable, and polymorphic in these trying times.
<FromGitter> <philnash> 🙌
<FromGitter> <paulcsmith> Good morning to you too @redcodefinal!
Renich has joined #crystal-lang
<FromGitter> <redcodefinal> Hey, readability question, how much do we frown upon monkey patching? I want to add a "make_nd_array" method that makes a Nd Array.
<FromGitter> <sdogruyol> @redcodefinal it is OK
<FromGitter> <redcodefinal> Actually, I'm having a little trouble wrapping my head around the generic types in this. I'm trying to make a method that makes a 2d array, and takes a block to define each default value. ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ It fails because it can't figure out what T is supposed to be. [https://gitter.im/crystal-lang/crystal?at=5824c1dadf5ae966453e8c13]
<FromGitter> <redcodefinal> https://play.crystal-lang.org/#/r/1do7
<FromGitter> <cjgajard> @samueleaton , IMHO spawn outside methods is better because it make them testable synchronously and I only have to care about synchronization in one place. (and the `spawn method` macro makes it pretty)
<FromGitter> <samueleaton> @cjgajard agreed! Thats is what I ended up doing.
<FromGitter> <samueleaton> I was thinking it would be cool to have a way to do this: ⏎ ⏎ ```async def do_something ⏎ ... ⏎ end``` ⏎ ⏎ but this ain't javascript! [https://gitter.im/crystal-lang/crystal?at=5824c3ac65485ebc677c44a1]
<BlaXpirit> these are entirely different concurrency concepts...
<FromGitter> <samueleaton> Yup. just going on a tangent.
<FromGitter> <cjgajard> `async def` is quite useless, but it is easy to make :-P ( https://carc.in/#/r/1doi )
<BlaXpirit> :P
rafadc has joined #crystal-lang
<FromGitter> <redcodefinal> So I've been looking through the docs and I noticed there is a ```map``` but not a ```map!``` which should modify the object it's referencing. Is there a reason behind this?
<FromGitter> <johnjansen> it gets tricky when the collection becomes mutable apparently
<FromGitter> <johnjansen> e.g. consider `[1,2,3].map!(&.to_s)`
<FromGitter> <redcodefinal> damn didnt think of that
<FromGitter> <redcodefinal> there are so many habits and ways of thinking I got from Ruby I need to change for Crystal
<FromGitter> <redcodefinal> I found out what you just said the hard way -> https://play.crystal-lang.org/#/r/1dot
<FromGitter> <johnjansen> just remember, its not ideal to change the type of a variable … it becomes less predictable
<FromGitter> <redcodefinal> Do you think there is good way to make the ```set_all``` method as described in that link?
<FromGitter> <johnjansen> there is alot of bad ruby around, i tripped over a very well used method in a ruby gem the other day which returned `(Array(String) | String | Int32 | Nil)`how this ever worked was pure luck
<FromGitter> <cjgajard> there is `map!` but it is specific for Array https://crystal-lang.org/api/0.19.4/Array.html#map%21%28%26block%29-instance-method ... (because not all enumerable are mutable)
<FromGitter> <redcodefinal> Yeah and I am using ```Slice(T)``` as a backing for my ```Matrix3``` class
bjz has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<FromGitter> <johnjansen> @redcodefinal you need to map the return from your proc to a Slice(T) its an Array(Nil) ATM i think
<FromGitter> <redcodefinal> Yeah I tried this and it worked. Anything I'm missing that might screw me later?
<FromGitter> <redcodefinal> ``` def set_all(&block) ⏎ max.times do |x| ⏎ buffer[x] = yield ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5824d0026cb72076305f2301]
<FromGitter> <redcodefinal> https://play.crystal-lang.org/#/r/1dp3
<FromGitter> <johnjansen> make sure your procs cant return the wrong type https://play.crystal-lang.org/#/r/1dpa
<FromGitter> <redcodefinal> btw I love we can share the play.crystal.com sketches. This makes the whole thing so much easier
snsei has joined #crystal-lang
<FromGitter> <redcodefinal> @johnjansen So I tried this, and I noticed that Union types don't match one of the types, it tries to match all of them.
<FromGitter> <redcodefinal> How do I do proper matching for union types?
snsei has quit [Ping timeout: 258 seconds]
<FromGitter> <johnjansen> https://play.crystal-lang.org/#/r/1dpf
<FromGitter> <redcodefinal> ah, I tried this as well but I see where I went wrong now -> https://play.crystal-lang.org/#/r/1dpg
bjz has quit [Ping timeout: 260 seconds]
rafadc has quit [Ping timeout: 256 seconds]
<BlaXpirit> can do alias Type = ... and use it
<FromGitter> <redcodefinal> oh ok thats how thanks @BlaXpirit
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 256 seconds]
FromGitter has quit [Ping timeout: 268 seconds]
FromGitter has joined #crystal-lang
BlaXpirit has quit [Ping timeout: 265 seconds]
<FromGitter> <redcodefinal> idk. I'm pretty much building it whole, then testing all the individual pieces to make sure they work. A lot of things have to change because Ruby had it's way of doing things that Crystal doesn't. I also built a viewer last time but I might skip that until the last step. I'll probably just make it output PNGs
BlaXpirit has joined #crystal-lang
<FromGitter> <sdogruyol> Well if you can actually build and run it then that's a win. Isn't it?
<FromGitter> <redcodefinal> yeah thats the hope but I feel it's very optimistic.
<FromGitter> <redcodefinal> There is a lot I'm not sure if I am doing right, or stuff that I think is right that is wrong. All I can say, hope the debugging will be easy.
<FromGitter> <sdogruyol> Well we can help you and learn / improve together
<FromGitter> <redcodefinal> hell yeah. I love the gitter we have and the conversation and helpfulness of this community
<FromGitter> <sdogruyol> That makes me happy :)
<FromGitter> <wmoxam> anyone know of any work on a gui toolkit shard?
<FromGitter> <redcodefinal> Can I make a method definition for an abstract definition? Essentially ensuring it can't be used until it has been inherited?
<FromGitter> <redcodefinal> for example ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5824da6131c5cbef43de7264]
<FromGitter> <sdogruyol> @wmoxam https://github.com/Fusion/libui.cr
<FromGitter> <sdogruyol> @redcodefinal `abstract def` ?
<FromGitter> <redcodefinal> hold on
<FromGitter> <redcodefinal> https://play.crystal-lang.org/#/r/1dpz
<FromGitter> <redcodefinal> I guess you can't :<
<FromGitter> <redcodefinal> I wanted to force someone to define it when inheriting the class, but not allow it to be directly called from the super class
<Papierkorb> redcodefinal, an abstract class can never bee instantiated directly?
<FromGitter> <wmoxam> @sdogruyol ohh, interesting
* FromGitter * wmoxam checks for openbsd support
<FromGitter> <redcodefinal> I wasnt even thinking about abstracting the class itself. Just a method in a class that shouldn't be called directly, but needs an additional definition
<FromGitter> <sdogruyol> @redcodefinal https://play.crystal-lang.org/#/r/1dqc
<FromGitter> <johnjansen> anyone know if this is a) possible and b) how … https://play.crystal-lang.org/#/r/1dqb
<FromGitter> <wmoxam> ah it's a wrapper over gtk 3
<FromGitter> <redcodefinal> @johnjansen if I am not mistaken,. which I very well might be, one letter class names are not allowed
<FromGitter> <redcodefinal> @BlaXpirit do you remember that github issue you sent me where they discussed making a forall?
<FromGitter> <johnjansen> @redcodefinal they are allowed
<FromGitter> <redcodefinal> ah I remember reading in the github issue where they added forall they were talking about disabling the one letter class names and let them be used for generics only
<FromGitter> <cjgajard> @johnjansen https://play.crystal-lang.org/#/r/1dqk some alternatives :/
<FromGitter> <sdogruyol> @cjgajard that's neat
<FromGitter> <johnjansen> thanks @cjgajard i appreciate the options but neither are feasible in my particular case :-)
<FromGitter> <johnjansen> thanks alot tho
pduncan has joined #crystal-lang
<FromGitter> <johnjansen> anyone know if you can get the byte size of an arbitrary object easily
<BlaXpirit> johnjansen, sizeof(typeof(
<BlaXpirit> but it depends on what u need
<FromGitter> <johnjansen> trying to decide when to flush a runtime buffer
<FromGitter> <johnjansen> i might wind up tracking it myself, or use a memory io if it turns out to work ok for my use case
<FromGitter> <johnjansen> dont want to reinvent the wheel tho
rafadc has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
mgarciaisaia has joined #crystal-lang
<mgarciaisaia> Has anyone had this issue while compiling bdwgc on Linux? https://github.com/ivmai/bdwgc/issues/69#issuecomment-259798774
<mgarciaisaia> It seems to be an issue with autotools or something like that. The maintainer tried to clearly explain the issue, but I still don't get what should I do. I'm stalled trying to install Crystal from sources there :/
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 258 seconds]
<FromGitter> <redcodefinal> When defining a method that takes a block if I ```typeof``` the block variable I get ```Proc(Nil)```. What does the Nil mean here?
<FromGitter> <redcodefinal> ```def test &block ⏎ typeof(block) ⏎ end ⏎ ⏎ puts test {} => Proc(Nil)``` [https://gitter.im/crystal-lang/crystal?at=5824ea98e097df757596e6c1]
<FromGitter> <barisbalic> To those who may be interested, I finally had time to sort out Crystal Docs, it now pulls repos from GH on first request, then attempts to update them every 30 minutes or so. It takes the latest 6-7 crystal releases and tries to build against those. It looks for new releases every hour. I think @RX14 this is something you specifically preferred?
<RX14> ehh
<FromGitter> <barisbalic> RX14 like a month ago or whenever I pushed the original crystal docs you said you'd prefer for it to pull from GH and build, rather than be a glorified rsync server. Just letting you know that's now the case.
<RX14> well i rather liked the option for both
<FromGitter> <barisbalic> @RX14 would you care to elaborate over DM?
<RX14> and how do you solve the building issue?
<RX14> containers?
<FromGitter> <barisbalic> As I said above, I just keep a bunch of crystal releases, then attempt to build in order of version descending, until the list is exhausted
<RX14> yes but how do you make sure people can't run RCE against the build server?
<RX14> generating the docs still runs macros which runs remote code on your machine with full shell access
mgarciaisaia has left #crystal-lang [#crystal-lang]
<RX14> what do you do?
<FromGitter> <barisbalic> @RX14 I don't, I had assumed (without checking) that building the docs was safe, however now that I think about it I can't see how it could be.
bjz has joined #crystal-lang
<FromGitter> <barisbalic> I don't really want to get tangled up in docker, at the same time the rsync option meant it was hard to restrict what was uploaded, and supporting both users/CI publishing was non-trivial.
soveran has joined #crystal-lang
bjz has quit [Read error: Connection reset by peer]
<Papierkorb> barisbalic, you really should use containers, or maybe systemd-nspawn, to limit the power of the ran crystal commands. Everything else is a ticking bomb waiting for someone to turn your server into a private proxy or a botnet zombie or something
<FromGitter> <barisbalic> @Papierkorb, yeah that's obvious now
<FromGitter> <barisbalic> I guess docker it is
<Papierkorb> Please make sure to read the docker manuals in its entirety
<Papierkorb> Docker is a container service to easily deploy things, it's not really a security service in itself
rafadc has quit [Ping timeout: 244 seconds]
<FromGitter> <barisbalic> It is very unlikely I'll do that, I'll likely do nothing for another month, I have little time as it is.
Renich has quit [Quit: leaving]
<Papierkorb> It's a bit like using chroot() for security reasons. Yes, it has been done, and it has always been wrong too for the general case
soveran has quit [Remote host closed the connection]
lacour has joined #crystal-lang
<RX14> using docker AND making the command run as an unprivileged user inside docker gives good protection
matp_ has joined #crystal-lang
matp has quit [Ping timeout: 246 seconds]
akwiatkowski has quit [Ping timeout: 264 seconds]
transfire has joined #crystal-lang
Philpax has joined #crystal-lang
Philpax has quit [Ping timeout: 260 seconds]
soveran has joined #crystal-lang
soveran has quit [Ping timeout: 256 seconds]