ChanServ changed the topic of #crystal-lang to: The Crystal programming language | | Crystal 0.23.1 | Fund Crystal's development: | GH: | Docs: | API: | Gitter:
balduin has joined #crystal-lang
vikaton has joined #crystal-lang
<watzon> So i
<watzon> Whoops lol
<watzon> Ok, so if I wanted to test scry I'd just pipe some crystal into it right?
<watzon> Like `cat | scry`
renovo_ has quit []
<crystal-gh> [crystal] javanut13 opened pull request #5294: Add reduce macromethod to TupleLiteral and ArrayLiteral (master...arrayliteral-reduce-macro-method)
azah has quit [Quit: ""]
andrewzah has joined #crystal-lang
andrewzah has quit [Client Quit]
andrewzah has joined #crystal-lang
andrewzah has quit [Client Quit]
<FromGitter> <megatux> Hi everyone! I've some problems trying to compile the sample apps in *crystal-gobject* shard. Crystal v 0.23. I know Ruby but no Crystal. There is an "undefined macro variable 'main' " error. I think it is defined in an already required file as a *fun*
andrewzah has joined #crystal-lang
andrewzah has quit [Client Quit]
andrewzah has joined #crystal-lang
andrewzah has quit [Client Quit]
andrewzah has joined #crystal-lang
<faustinoaq> @‎watzon‎ no, scry doesn't work in that way. Scry is a Language Server Protocol implementation, you must use it with a client like VIM, Eclipse, Sublime, Atom, VSCode, etc
<faustinoaq> check
<faustinoaq> @watzon also please try scry master branch instead of latest version, we have fixed some issues :)
vikaton has quit [Quit: Connection closed for inactivity]
<watzon> faustinoaq: yeah I figured that out. I'm actually on the master branch now, I was just confused as to why the VS Code plugin didn't seem to be working
<watzon> but now it's working alright
<faustinoaq> watzon, vscode-crystal-lang has support for Scry but is still highly experimental, please see:
<faustinoaq> You need to set the filepath for scry executable on `"crystal-lang.server": "/absolute/path/bin/scry/executable"`
<faustinoaq> inside `settings.json`
<faustinoaq> and also enable some other features like `"crystal-lang.implementations": true`
<faustinoaq> I just tried scry master and seems is working well :)
<faustinoaq> BTW, sublime text has very good support for LSP, so scry should work almost out-the-box, except for some bug on diagnostics :)
<watzon> Yeah I've got it working now, thanks :) I didn't know about the implementations feature though
rohitpaulk has joined #crystal-lang
sz0 has joined #crystal-lang
rohitpaulk has quit [Quit: Ping timeout (120 seconds)]
<watzon> faustinoaq: have you managed to get Native Debug working with Crystal?
<watzon> I don't know how I'd go about setting up the VS Code config file to work with crystal
<faustinoaq> commonly I disable these features by default because are unstable or buggy or bad implemented
<FromGitter> <watzon> Oh I was talking about the GDB config haha
<FromGitter> <watzon> But I think I figured it out
<faustinoaq> So, We want to finish Scry to be able to get good language support :)
<faustinoaq> [here]( is a gist about debugging an amber project, so it may be useful :)
<faustinoaq> native-debug is very useful GDB front-end to debug D, Rust, Nim, C, Crystal and other languages that compile to binary
<FromGitter> <cyclecraze_twitter> The crystal api has an example of json mapping: ``` ⏎ class Location ⏎ JSON.mapping( ⏎ ⏎ `````` []
<FromGitter> <cyclecraze_twitter> the following is the (page)[]
<FromGitter> <vonKingsley> @cyclecraze_twitter its because location has the possibility to be nil (nilable: true). The compiler checks to see if there is a method called lat for nil. Since it doesn't fine one, the compiler throws that error. if you know for a fact that its not going to be nil you can do `house.location.not_nil!.lat` or if the json could actually not include a location node you could do this
<FromGitter> <vonKingsley> ```if loc = house.location ⏎ puts``` []
illy_ has joined #crystal-lang
illyohs has quit [Ping timeout: 240 seconds]
mbarbar has quit [Ping timeout: 255 seconds]
sz0 has quit [Quit: Connection closed for inactivity]
shelvacu has quit [Ping timeout: 268 seconds]
Excureo has quit [Remote host closed the connection]
Excureo has joined #crystal-lang
shelvacu has joined #crystal-lang
flaviodesousa has joined #crystal-lang
claudiuinberlin has joined #crystal-lang
mark_66 has joined #crystal-lang
Papierkorb_ has joined #crystal-lang
Groogy has joined #crystal-lang
Groogy has quit [Client Quit]
Groogy has joined #crystal-lang
<FromGitter> <codenoid> is crystal have image processing library ? (resize, etc)
<FromGitter> <codenoid> *change file meta info
<Groogy> Eh I kind of sort of started one
<Groogy> but not really
<Groogy> I bound everything I needed from FreeImage to load images
<Groogy> if you want to create a proper binding/library for it I would love you
<FromGitter> <codenoid> great @groogy 👍
<Groogy> my library is probably too big for whatever you want to do so you should create your own specifically for this :) Though you can use mine as guide on how freeimage works
<Papierkorb_> Roses are red, violets are blue, Groogy wrote lib bindings, and so can you
<Groogy> That's a quite nice poem ^^
<Papierkorb_> haven't seen you around in recent weeks Groogy, were you on vacation?
<Groogy> Nah just been working on release candidate and day 1 patch
<Papierkorb_> ah crunchy time
<Groogy> some bad planning happened TM and the tech lead is on vacation
<Groogy> Didn't like being tech lead, so stopped and now pulled back in D:
danielpclark has joined #crystal-lang
<FromGitter> <zyriuse75> do you know an equivalant of CSSH ?
<FromGitter> <bew> @zyriuse75 what is it?
<crystal-gh> [crystal] icyleaf opened pull request #5296: Remove mistake example in query property comment (master...correct-query-property-doc)
<FromGitter> <Rinkana> Is there some article on functions to avoid for better performance. Like the `+=` operator. It took me some time to debug some performance issues with that operator: ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <Rinkana> You would expect that they would perform somewhat the same
<Groogy> eh what, what's slow with +=?
<Groogy> doesn't += just expand into foo = foo + 5?
<FromGitter> <Rinkana> Adding to the array, as seen in the `Slow` example
<FromGitter> <bew> well, `ary += ["bla"]` will be transformed to `ary = ary + ["bla"]` I think, so it'll create a temporary array and re-assign to ary
<Groogy> ooooh yeah
<FromGitter> <bew> and `<<` will directly add the item to `ary` to there's no temporary object
<Groogy> so if you think about that += is always a shortcut for literally foo = f00 + something
<Groogy> it becomes more obvious
<FromGitter> <Rinkana> Yeah that's correct.
<FromGitter> <bew> and @Rinkana, `["foo", "bar", "baz"].each` is slower than `{"foo", "bar", "baz"}` and probably even slower than assigning the tuple to a variable, and iterate it in the `.times`'s block
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<FromGitter> <Rinkana> @bew the example is a simplified version of what i have.
<FromGitter> <bew> I imagine that ;)
<FromGitter> <Rinkana> But would there be a reason to keep using `ary = ary + [...]` for arrays instead of looping trough it and adding it to itself?
<FromGitter> <Rinkana> ```code paste, see link``` []
<FromGitter> <Rinkana> It's slower by quite some margin. And afaik it yield the same result
<Groogy> not really
<Groogy> there isn't really any reason to do temp arrays
<Groogy> or well there are
<FromGitter> <bew> I don't know, it's still useful to make a copy to another variable, but yeah, for the same array it's useless and slow
<Groogy> but that is most probably biggest culprit you get in performance
<FromGitter> <bew> but we can't remove `+=` for arrays, as it is a syntax sugar on `ary = ary + {something}`, Array only has to define `+`
<Groogy> some shameless self promotion, I recommend
<Groogy> should help you find tmp arrays in your code
<Groogy> and other poltergeist objects
<FromGitter> <bew> looks good!
<Groogy> it gives you callstack where allocated and also how long time an object from that callstack lived on average
<Groogy> before bieng collected
<FromGitter> <bew> you could use `class_property? guard = false` ;)
<FromGitter> <Rinkana> > but we can't remove `+=` for arrays, as it is a syntax sugar on `ary = ary + {something}`, Array only has to define `+` ⏎ ⏎ No but what about changing the `+=` operator for arrays to my other implementation?
<Papierkorb_> += isn't a real operator, it's rewritten.
<Groogy> how do you mean bew?
<Papierkorb_> And as += is `x = x + y`, it's *not* equivalent to using #<<
<FromGitter> <bew> Groogy instead of writing the methods yourself, you can use `class_property?`!
<Yxhuvud> because being able to concatenate two arrays without modifying them is necessary to have. In this case you will just have to learn the performance cost of creating new arrays.
<Groogy> oh
<Groogy> didn't know it existed
<FromGitter> <bew> that's why I tell you ;)
<Groogy> does property? do the same?
<FromGitter> <Rinkana> Papierkorb_ what's the difference then?
<Groogy> it creates a ? method instead of a getter?
<Groogy> what if I only want a getter do I then do getter?
<Papierkorb_> Rinkana, please think about "passing by reference."
<Papierkorb_> (/or read up on it)
<Papierkorb_> And what it implies in the general case.
<Groogy> Rinkana #<< acts on left hand object, while #+ will create a new array
<Papierkorb_> Groogy: ..Yes
<FromGitter> <bew> Groogy API doc says it all*names)-macro
<Groogy> how did I miss this
<Papierkorb_> yes?
<Papierkorb_> man a pun with a question mark
<Papierkorb_> what a time to be alive
<Papierkorb_> > Because CouchDB databases are meant to be exposed directly to the internet, this enabled privilege escalation, and ultimately remote code execution, on a large number of installations.
<Papierkorb_> Let me reiterate:
<Papierkorb_> > Because CouchDB databases are meant to be exposed directly to the internet,
<Papierkorb_> ... Just why man
<Groogy> why the hell would you...
<Papierkorb_> That is so obviously stupid that not even the OWASP is warning against it
hightower2 has joined #crystal-lang
<Papierkorb_> Reminds me of the perl sucks talk which exploited a really similar behaviour in popular powered-by-Perl web applications
Papierkorb_ has quit [Remote host closed the connection]
Papierkorb_ has joined #crystal-lang
qard has joined #crystal-lang
<FromGitter> <bararchy> We should ofc encourage this kind of thinking ;)
danielpclark has quit [Ping timeout: 240 seconds]
<Papierkorb_> ?
danielpclark has joined #crystal-lang
<FromGitter> <bararchy> The more RCE the better ?
<FromGitter> <bararchy> Hahahah
<FromGitter> <bararchy> I was working with an organization, not a small one, who didn't want to use VPN as its "not secured" , they ended opening up multiple RDP servers to the internet
<FromGitter> <bararchy> A much better solution hahahha
<Papierkorb_> Yeah RDP never had vulns or anything
<FromGitter> <bararchy> Never ever , also , super secured support of SSL3
unshadow has joined #crystal-lang
danielpclark has quit [Remote host closed the connection]
<Groogy> Hey kinda curious... the code for like parsing crystal code and get AST nodes from that...
<Groogy> I can do like require "something" to access that right?
<FromGitter> <bew> Yes
<FromGitter> <bew> Require compiler/crystal/parser
<FromGitter> <bew> And you can Crystal::Parser.parse(source_code)
<faustinoaq> watzon, Thank you! I'm thinking in the future to replace current completion by something like
<Groogy> oh nice, so I could make a nice little Crystal like script language
<Groogy> for like gui definitions n stuff
<watzon> faustinoaq: That would be awesome
<crystal-gh> [crystal] j8r opened pull request #5298: Add (master...ini-build)
<watzon> Is the compiled binary small enough to ship with the extension?
<Yxhuvud> groogy: Before doing that, don't forget that you can come a long way with macros.
<Groogy> oh yeah but I mean i want to have a thing read in runtime and parsed
<faustinoaq> vivus, Yes, but I would recommend to not include with, because I tried embed scry before and it was a headache
<Groogy> or whatevs :P
<faustinoaq> vivus, I think including it on Scry is a better option, see
<Yxhuvud> that seems somewhat hacky until the day someone implements a proper parser generator :)
<watzon> faustinoaq: Fair point. So I guess it would be kinda like Scry then? Something you can install and then configure in the options
<Yxhuvud> .. and silly afterwards.
<Groogy> ¯\(°_o)/¯
<Groogy> I mean all I want is to read data and setup my UI based on it
<faustinoaq> vivus, Yes, that exactly
<Groogy> and of course be able to update the UI runtime since it is a lot nicer than having to restat over and over
<Papierkorb_> Groogy: write your UI in a .. YAML or XML based description?
<Groogy> yeah but that starts to look messy real fast
<Groogy> (that's what I have on the c++ version of it all)
<Groogy> I even have logic in there for gameplay stuff
<Papierkorb_> For UI imho a declarative approach is amazing
<Papierkorb_> but YAML surely isn't nice once you want to put some kind of script into it :P
<Groogy> yeah but also YAML kind of... grows
<Groogy> let's say I try to define a window in it and its components under it
<Papierkorb_> But maybe, like `onclick: some.random(js_code);` would still be the most sane way, if all functionality is kinda specialized - and you're working on your own anyway
<Papierkorb_> The UI designer can't mess up the logic if there's no UI designer to begin with :^)
<Groogy> I can see how this is going to get ugly fast
<Groogy> though YAML supports anchors n stuff so might actually be quite viable
<Yxhuvud> groogy: you can have comments, and I think, whitespace in the file though
<Groogy> in the YAML file? yeah?
<Groogy> oh wow lol, I didn*t know you could have collections as keys in a collection
<Groogy> for YAML
<FromGitter> <bew> Oo how?
<crystal-gh> [crystal] j8r closed pull request #5298: Add (master...ini-build)
<Groogy> ? [Foo, Bar]: Hey
<Groogy> I guess should work?
<crystal-gh> [crystal] j8r reopened pull request #5298: Add (master...ini-build)
sz0 has joined #crystal-lang
<FromGitter> <bew> or maybe with the colon after a new line?
<crystal-gh> [crystal] j8r closed pull request #5298: Add (master...ini-build)
<crystal-gh> [crystal] j8r reopened pull request #5298: Add (master...ini-build)
hightower2 has quit [Ping timeout: 248 seconds]
Papierkorb_ has quit [Quit: Konversation terminated!]
ShalokShalom has joined #crystal-lang
mark_66 has quit [Remote host closed the connection]
faustinoaq has quit [Read error: Connection reset by peer]
faustinoaq has joined #crystal-lang
claudiuinberlin has quit [Quit: Textual IRC Client:]
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium]
DTZUZU has quit [Quit: WeeChat 1.9]
unshadow_ has joined #crystal-lang
unshadow has quit [Ping timeout: 250 seconds]
unshadow_ is now known as unshadow
hightower4 has joined #crystal-lang
hightower3 has quit [Ping timeout: 248 seconds]
Excureo has quit [Remote host closed the connection]
<hightower4> I'm looking to load files/plugins in runtime. Plugins would be in Crystal. Is there a convenient way/recipe to do so, or I should by all means load stuff during compile time and that's it?
claudiuinberlin has joined #crystal-lang
<faustinoaq> @‎hightower4‎ I tried an experiment some months ago :)
<hightower4> faustinoaq, pretty cool!
<faustinoaq> ‎hightower4‎, Yeah, would be awesome if someone create a full experiment like
unshadow has quit [Quit: unshadow]
<sevensidedmarble> I figured out the issue Papierkorb with fancyline. I was running crystal deps but it wasnt updating my dependencies.
<sevensidedmarble> it still doesnt update when I run crystal deps
<Papierkorb> yea that's why insisted that you check that first
<Papierkorb> remove your .shards too
<Papierkorb> and the shards lock
<sevensidedmarble> remove the shards.yml and shards.lock?
DTZUZU has joined #crystal-lang
<Papierkorb> no not the shards.yml
<Papierkorb> the .shards/
<sevensidedmarble> well hell I didnt even notice that was there lol
<sevensidedmarble> and then if I run crystal deps it should fetch the latest?
<Papierkorb> if you didn't specify the version in the shards.yml, hopefully yes
<sevensidedmarble> that didn't seem to work
<sevensidedmarble> it just says 'updating' the packages when I run crystal deps or shards install after removing those files
<sevensidedmarble> and when I look at the versions in lib theyre still the old ones
<Papierkorb> and lib/ should be removed too
<sevensidedmarble> ok
<Papierkorb> all of the files and dirs
<Papierkorb> if it insists on using v0.1, then tell it you want to use master
lacour has joined #crystal-lang
<sevensidedmarble> yeah it just keeps giving me 0.1
<sevensidedmarble> ok specifying master worked
<sevensidedmarble> I wonder why that happens?
<sevensidedmarble> color working now
<sevensidedmarble> the cursor is still like one character too far to the right for some reason
<sevensidedmarble> it happens in your color prompt sample too
<sevensidedmarble> is it related to the you mentioned?
<literal> what's the assignment in the optionparser block doing here?
<literal> seems to confuse the compiler
<Papierkorb> no it's working correctly.
<literal> what am I doing wrong then?
<literal> how could ever be called when filename is Nil? I
<Papierkorb> you're using filename in a caught block (L13). as the block is stored, the compiler can't guarantee that it's actually called
<Papierkorb> hence it must assume that the type is String or Nil
<literal> but how can I ever make sure of it myself if even an "if filename" won't do?
<Papierkorb> but as the block still exists on line 17 onwards, the compiler can't know if from line 17 to 20 `filename` isn't written to, it could be changed from a String to a nil
<Papierkorb> either `if var=`, or use a different option parser lib
<literal> I thought that only applied to instance variables
<literal> that is, I thought this would apply:
<Papierkorb> please read again what I wrote
<literal> so what is stated in if_var_nil.html does not apply to any variable held by a block?
<Papierkorb> no.
<literal> no I'm wrong, or no it doesn't apply? :P
<Papierkorb> doesnt apply, because of what I already wrote.
<literal> alright then
<literal> should the block not have been out of scope/garbage-collected after the call to parse!() is finished?
Renich has quit [Ping timeout: 276 seconds]
<literal> also, if I change line 9 to be <filename = "bla">, then the compiler doesn't complain
<literal> don't quite understand how the initial value matters if the uncertainty of the block is what the problem was
Renich has joined #crystal-lang
<FromGitter> <victor95pc> hey
<FromGitter> <victor95pc> someone could help me?
<FromGitter> <victor95pc> ```code paste, see link``` []
<FromGitter> <victor95pc> It's not running because the compiler thinks I want a string like this: ```def initialize({{ { |f| "@#{f[:name]} : #{f[:type]}" }.join(", ") }})```
<FromGitter> <victor95pc> but I want this: ```def initialize(@:name : String, @:age : Int32)```
<FromGitter> <victor95pc> so you guys know a way to do it?
<FromGitter> <bew> you should look at how `record` is defined
<FromGitter> <victor95pc> record?
claudiuinberlin has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<faustinoaq> @victor95pc I think you should add `.id` at end of `join(", ").id`
<FromGitter> <bew> yes `record`, documented here:*properties)-macro
<FromGitter> <victor95pc> the id suggestion kind of works
<FromGitter> <bew> you can maybe find some inspiration
<oprypin> victor95pc, you can add .id everywhere but it's best to avoid `map`. use `{% for`
<FromGitter> <marksiemers> @RX14 and @sdogruyol - We may have figured out the TFB issue with crystal-raw vs the frameworks for plaintext and json:
<FromGitter> <victor95pc> uhu, but it'll run at compile time anyway, so is it best to create a property for each field?
<FromGitter> <marksiemers> Thanks to @faustinoaq
claudiuinberlin has joined #crystal-lang
<FromGitter> <bew> @victor95pc using for could end up like this:
<oprypin> thx for showing that :)
<oprypin> needs more .id tho
<FromGitter> <bew> what do you mean "need more .id" ?
<FromGitter> <bew> it works no?
<FromGitter> <bew> ah yes ok I see
<FromGitter> <victor95pc> mine kind of the same
<FromGitter> <victor95pc>
<FromGitter> <victor95pc> thx
<FromGitter> <bew> moore .id
<FromGitter> <bew> you still use .map for the initialize, but yes, you get the idea!
<FromGitter> <victor95pc> yup, thx
<oprypin> victor95pc, check out the nice `{{*` feature that `record` uses though
<FromGitter> <victor95pc> now I'm anxious about 1.0
<oprypin> well it is basically equivalent to `.join(", ").id` but hey
<oprypin> victor95pc, don't worry about it any time soon :p
<hightower4> mm, help me a little bit here. I do x= @@X; next unless x; x.something() and I get undefined method something for Nil (compile-time type is (Logger | Nil))
<hightower4> How do I restrict type to Logger?
<oprypin> hightower4, i dunno, maybe `next` just doesnt get the type inference
<oprypin> hightower4, miminized
<oprypin> wait im stupid
<oprypin> hightower4, it works
ShalokShalom has quit [Remote host closed the connection]
<oprypin> hightower4, it's the suffix-if - it does not affect type inference, for whatever reason.
<oprypin> no nevermind, my example still uses that. i havve no idea what's going wrong in your case lol
<hightower4> Yeah, here's the paste:
<hightower4> (It won't work of course since I pasted it out of context, but that's the code which gives the above error)
<oprypin> that doesnt count then
<oprypin> in case it wasn't clear, i'm waiting for a reproducible example
<hightower4> I got this: , but that works
<hightower4> Not sure really...
qard has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
qard has joined #crystal-lang
<hightower4> Oh damn got it...
<hightower4> I had log= something; Signal::USR2.trap { next unless log= something_else; ... }
<hightower4> But 'log' inside the block was the same as the outer one. When I changed log to logx inside the block, it all worked
danielpclark has joined #crystal-lang
<hightower4> Should I be using logger.warn {block} always, or only when the data to log is non-trivial (i.e. something other than a plain string)
<FromGitter> <unreadable> There's the c2 language loool
<FromGitter> <unreadable>
vivus has joined #crystal-lang
<hightower4> What's my best bet to daemonize a process? Equivalent of Ruby's Process.daemon doesn't seem to be there
<Papierkorb> Just don't. Daemonizing isn't your job, it's the job of the service manager
<Papierkorb> If you really have to, just fork away. Just keep in mind that self-daemonizing is Bad Style™
<hightower4> Yeah I agree, just wanted to provide that option. Ok great, I'm in favor of removing it altogether.
<Papierkorb> if a user insists, they can always just & it themselves.
<Papierkorb> Though you can distribute a (sample) configuration file for e.g. systemd
<Papierkorb> Which .. is the de-facto standard now anyways lul
<FromGitter> <bew> Is there a better way to do wait for all channels to send a specific thing? ⏎ ⏎ ```code paste, see link``` []
<FromGitter> <sdogruyol> thanks @marksiemers 🎉
<FromGitter> <marksiemers> Still working on our solution for amber right now @sdogruyol - hopefully by the end of day we'll have something and perhaps you can adapt it for kemal, if you like.
<hightower4> I have text = [ "txt", "cfg"]. Then I want to run 'case extension' and have a 'when text'. How exactly do I do that? (i.e. have case/when match a value from array)
<hightower4> Actually, that can be a tuple, in which case *text would work. So I just need an equivalent of %w() which creates a tuple rather than an array
<hightower4> Hm looks like *text doesn't work even with a tuple
<hightower4> Why doesn't this work?
<hightower4> and/or how to make it work
<FromGitter> <bew> do you really need a hash? or can you use a struct/class ?
<FromGitter> <bew> (and it'd be better to simplify to `location[:line] = list.size` for your example)
claudiuinberlin has quit [Quit: Textual IRC Client:]
<hightower4> I'm using this to print the line number of error for example, not to count number of lines
<hightower4> Could use a struct/class, yes. Ok, thanks.
<FromGitter> <bew> To easily build small structs you can use the `record` macro
<hightower4> fabulous hint, thanks
<FromGitter> <MrSorcus> Hi, how to write this function in crystal binding? I can't find info or example...
DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU2 has joined #crystal-lang