snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
maattdd has joined #crystal-lang
snsei has quit [Ping timeout: 256 seconds]
maattdd has quit [Ping timeout: 256 seconds]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
snsei has quit [Remote host closed the connection]
<watzon>
Crap. The case statement doesn't do fallthrough does it?
<FromGitter>
<bew> What do you mean by "fallthrough"?
<watzon>
In some languages, it seems java-type languages in particular, the switch/case statement will allow conditions to "fall through" if there isn't a break. So one thing will match and, if there isn't an explicit break, the next thing that matches will also be called
<watzon>
Ruby doesn't do it and I guess Crystal doesn't either
<watzon>
It's not a bad thing. Just means I need to rewrite about 60 lines of case statement as if statements instead
snsei has joined #crystal-lang
snsei has quit [Ping timeout: 276 seconds]
qard has joined #crystal-lang
qard has quit [Client Quit]
snsei has joined #crystal-lang
duane has quit [Ping timeout: 276 seconds]
snsei has quit [Ping timeout: 265 seconds]
alex`` has quit [Ping timeout: 260 seconds]
radagast_04 has joined #crystal-lang
radagast_04 has quit [Ping timeout: 268 seconds]
radagast_04 has joined #crystal-lang
<FromGitter>
<bew> Oh ok I see what you mean, could you give an example to see if there's no other ways to do this?
<FromGitter>
<CodeTrooperMC> So I downloaded a ZIP of source code but everything is in .cr files... no C source code anywhere...
<FromGitter>
<bew> hmm yes, the crystal compiler is written in Crystal :)
<FromGitter>
<CodeTrooperMC> That's very confusing........ how is that even possible?
<FromGitter>
<bew> ahahah, well at the beginning the compiler was written in Ruby, but at some point, the Ruby compiler compiled a Crystal compiler, and that compiled compiler was able to re-compile itself
faustinoaq has quit [Quit: IRC client terminated!]
faustinoaq has joined #crystal-lang
faustinoaq has quit [Ping timeout: 248 seconds]
sz0 has joined #crystal-lang
faustinoaq has joined #crystal-lang
faustinoaq has quit [Changing host]
faustinoaq has joined #crystal-lang
dannyAAM has joined #crystal-lang
DTZUZO has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
faustinoaq has quit [Quit: IRC client terminated!]
alex`` has joined #crystal-lang
faustinoaq has joined #crystal-lang
faustinoaq has quit [Client Quit]
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter>
<bararchy> what's the best way to recursivly go over each key in a json ?
<FromGitter>
<bararchy> or, Hash for that matter
jradd has quit [Ping timeout: 248 seconds]
return0e has quit [Read error: No route to host]
return0e has joined #crystal-lang
<FromGitter>
<sam0x17> @watzon yeah that switch behavior is also a C/C++ thing I believe. A more readable implementation of that might be to simply allow multiple items, comma delimited, as a case argument (maybe this is already a thing though? haven't played with crystal switch statements yet)
<FromGitter>
<sam0x17> @watzon btw thanks for trying to fix that bug with mongo.cr -- still getting errors on my end -- left you a comment
DTZUZO has joined #crystal-lang
<FromGitter>
<laginha87> @sam0x17 in crystal you can do have multiple items comma delimited in the when clause
<FromGitter>
<bew> well, you can do: `case var = 3; when 1, 2, 3 then ...; end` this will enter the `when` if `var` is either 1, 2 or 3
<FromGitter>
<aisrael> I wish Crystal had pattern matching (versus just `case` with multiple items, or fall through, etc.)
rohitpaulk has joined #crystal-lang
<FromGitter>
<sam0x17> ^ this, but at the same time retain O(1) where it is possible
<FromGitter>
<sam0x17> e.g., do all the const matches first, then try the patterns if none matched
DeBot has joined #crystal-lang
<FromGitter>
<aisrael> +1
<FromGitter>
<sam0x17> I've been wanting that in *some* programming language for like 10 years lol
<FromGitter>
<sdogruyol> @sam0x17 it sounds a bit complicated :P
<FromGitter>
<sam0x17> I don't really know how the grammar works but I would imagine as long as it is easy to differentiate const expressions from dynamic expressions it should be easy as pie
<FromGitter>
<sam0x17> phase 1: do O(1) lookup for all the const expressions, if no matches enter phase 2: for each dynamic expression, try it out, if it matches, return
<FromGitter>
<sdogruyol> I still prefer having a simpler way that just works instead of having multiple phases
<FromGitter>
<sam0x17> syntactically it would just work
<FromGitter>
<sdogruyol> can't visualize it for now :P
<FromGitter>
<sam0x17> the user would just mix in const things and non const things willy nilly -- compiler would parse through that and divide execution into the two phases
<FromGitter>
<sam0x17> statically it's easy to tell whether something is phase 1 or phase 2
<FromGitter>
<sam0x17> the compiler probably already does that in fact in that it should throw an error when something isn't a const expression with the current implementation
<FromGitter>
<sam0x17> the one caveat would be that the const expressions always have precedence, so if one of the non const expressions returns something that is already one of the const options, the non-const block will not execute
<FromGitter>
<sam0x17> but that's perfectly reasonable
<FromGitter>
<sam0x17> another way of looking at it is do all the const stuff with the O(1) optimization, and then fall back to else if execution style for the rest
<FromGitter>
<sam0x17> notice how I mix const and non expressions in terms of ordering -- there are no ordering constraints on the user because the compiler already has enough information
<FromGitter>
<sam0x17> if people like this maybe I'll put in a feature request
dragonkh has quit [Ping timeout: 256 seconds]
<FromGitter>
<sdogruyol> @sam0x17 please do so, it'll be healthier to have a broader discussion with more
LastWhisper____ has joined #crystal-lang
jradd has joined #crystal-lang
alex`` has quit [Ping timeout: 252 seconds]
duane has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 256 seconds]
<FromGitter>
<alexanderadam> I try to forward a captured block as described in the documentation (https://crystal-lang.org/docs/syntax_and_semantics/block_forwarding.html). ⏎ But I have obviously an error in my implementation. ⏎ The block looks has this type `PlaybackBlockType = (::Request, ::Response) -> Nil`, is stored in a configuration and when try it to pass it to a method that *should* accept this block as an argument I get
<jhass>
Basically the type you try to pass is PlaybackBlockType|Nil while the method expects PlaybackBlockType. If you're sure it can't be nil try calling .not_nil!, but it would be better to try to get rid of the nilable in whatever configuration is or at least hide the not_nil! there with a getter! macro
<FromGitter>
<alexanderadam> Ah, I see! Now I understand. ⏎ I missed the ` | Nil` of the error message somehow :S ⏎ Awesome. Thank you @jhass!
<jhass>
yw, glad it helped
rohitpaulk has joined #crystal-lang
<FromGitter>
<alexanderadam> Ah, and is there anything like `remove_instance_variable` in crystal?
<jhass>
I would be surprised
<jhass>
why?
<FromGitter>
<alexanderadam> it's not too bad. I mean I can nil it but I thought maybe it's there and I just can't find it.
<jhass>
well crystal generates a memory layout at compile time for your type
<jhass>
so you for sure can't change that layout at runtime
rohitpaulk has quit [Remote host closed the connection]
<watzon>
@sam0x17 I replied to your comment. I do have the latest version of crystal, but my mongo version is a bit newer. All of the specs are passing for me.
<watzon>
aisrael: ++ for pattern matching. Something on the level of Rust or Elixir would be amazing.
<FromGitter>
<aisrael> @watzon Exactly what I was thinking of
<watzon>
It would be possible to make it happen with a macro if Crystal's macro implementation was more robust, but as it is you can't do too much with them besides some basic code generation
<watzon>
I would love to have macros like Nim has
<FromGitter>
<aisrael> Why do I get the feeling that Crystal early adopters are either a) Ruby-ists looking for compiled, performant, and type-safe, or b) programming language junkies?
<FromGitter>
<xfbs> Because when you are in the Ruby-sphere, you will hear about crystal from your fellow rubyists, when you are a programming language junkie you will hear it from your gang (or from your fellow lobste.rs (https://lobste.rs/) in my case).
<oprypin>
aisrael, because that's like the only 2 types of people, except for the 3rd type that goes for whatever is popular
<FromGitter>
<xfbs> I think it's just that. A, say, VisualBasic programmer who doesn't happen to have an interest in programming languages just wouldn't ever hear about Crystal
<FromGitter>
<CodeTrooperMC> So someone told me awhile ago that Crystal compiles itself now. Does that mean porting to Windows is gonna be extra hard or require a rewrite?
rohitpaulk has joined #crystal-lang
jokke1 has quit [Ping timeout: 256 seconds]
jokke1 has joined #crystal-lang
jokke1 has quit [Client Quit]
<FromGitter>
<xfbs> I don't know anything about crystal internals but I think that the fact that it is self-hosting (compiles itself) just means that if you want to get it running on Windows, you need to cross-compile (meaning you will compile the Windows executable on linux/macos)
<FromGitter>
<CodeTrooperMC> Oh, okay.
faustinoaq has joined #crystal-lang
<jhass>
and once you have obtained a compiler via cross compilation you can use it to compile it again on windows
<FromGitter>
<aisrael> From what I’ve heard, it’s not the language/compiler itself that’s the problem—it’s the stdlib, specifically around some file/IO
<FromGitter>
<robacarp> I think the big problems for getting crystal to run on windows are interfacing with the system. Files, sockets, etc.
<FromGitter>
<j8r> exactly, windows isn't another UN*X OS
<FromGitter>
<CodeTrooperMC> Lol, I know.
<FromGitter>
<xfbs> That doesn't mean that you can't run crystal under windows right now tho
<FromGitter>
<j8r> but maybe with wsl, a bit
<FromGitter>
<CodeTrooperMC> I'm just really horrible at using linux-ish stuff as a programming OS.
<FromGitter>
<CodeTrooperMC> To do programming stuff.
<FromGitter>
<xfbs> Why is that?
<FromGitter>
<j8r> that's exactly the opposite of why I'm on on unixes O.o
<wmoxam>
ruby/lang junkies at this point makes a lot of sense
<wmoxam>
Crystal doesn't have a killer feature/app/use case yet
<FromGitter>
<CodeTrooperMC> Maybe I have to learn it or something. But I'm used to stuff like Visual Studio that isn't possible on linux. And all the other windows stuff that doesn't run on linux.
<robacarp>
CodeTrooperMC are you saying you're used to an IDE?
<FromGitter>
<CodeTrooperMC> No I'm used to VS. And other programs (not IDEs) that don't run on linux.
<FromGitter>
<xfbs> What do you use apart from VS?
<watzon>
Is is possible to pass a class method as an argument to another method? Basically turning it into a proc.
<FromGitter>
<CodeTrooperMC> I did some eclipse, and some codeblocks. ⏎ But I think the real reason is cause I don''t know how to do anything in the terminal. Like install a program.
<robacarp>
Getting used to a different software stack isn't quick, but I've found that most of the tools are pretty similar. I think @faustinoaq uses VSCode on linux
<robacarp>
oh, yeah, thats a big difference between windows life and linux life
<FromGitter>
<xfbs> @CodeTrooperMC do you need some help on how to get set up?
<FromGitter>
<straight-shoota> @CodeTrooperMC You might want to start using linux/command line in a VM or using Windows Subsystem for Linux instead of dual boot. From my experience, dual boot doesn't make much sense, you'll end up using one main operating system. Having two is not productive.
<FromGitter>
<robacarp> There’s truth to that
<FromGitter>
<j8r> yeah agree, WSL is a good start!
<FromGitter>
<j8r> @watzon you are working on something with matrig.org?
<FromGitter>
<robacarp> WSL is a bit of a brain warp looking at the filesystem though
<FromGitter>
<CodeTrooperMC> Okay, thanks for the advice guys!
<watzon>
@jr8 no I'm not, what is that? The link failed to resolve.
<watzon>
Basically what I'm trying to do is create a middleware handler that allows you to do `.use` with a class. The classes would need to inherit from the abstract `Middleware` class which has an abstract method `handle` defined on it. That handle method then needs to be pushed to an array of middleware.
<watzon>
I probably just need to rethink the solution
alex`` has joined #crystal-lang
<watzon>
I just want this to not happen when I try to pass a class as an argument `no overload matches 'Tourmaline::Bot::Client#use' with type MyMiddleware:Class`
<FromGitter>
<sdogruyol> make it a generic?
<FromGitter>
<sdogruyol> or make it accept a generic type
<watzon>
We need an interpreted version of Crystal for scripting. CrystalScript or something.
<FromGitter>
<sdogruyol> that'd be interesting
<FromGitter>
<imonmyown> it'd be a pain to implement
<watzon>
It would be nice to have. I am planning on writing something like Ruby's God or Eye in Crystal, but I'd love to be able to make the configuration in Crystal itself
<watzon>
Can you call the Crystal compiler from Crystal?
DTZUZO has quit [Ping timeout: 255 seconds]
<watzon>
I could just have scripts written in Crystal and have the process manager compile and then execute the script
<FromGitter>
<sdogruyol> yes you can
<watzon>
How would I go about doing that?
<FromGitter>
<bararchy> wouldn't using JSON\YAMAL be easier ?
<watzon>
Error in .icr_eFRRYxP7bip8uLuwO6hdig.cr:2: Please use `make crystal` to build the compiler, or set the i_know_what_im_doing flag if you know what you're doing
<watzon>
This doesn't work, probably because I want the methods to be static and forward_missing_to is going to make them instance methods
Ven`` has quit [Read error: Connection reset by peer]
Poeticode has quit [Client Quit]
Ven`` has joined #crystal-lang
Poeticode has joined #crystal-lang
Poeticode has quit [Changing host]
Poeticode has joined #crystal-lang
<FromGitter>
<straight-shoota> oprypin, yeah it makes sense
TakeYourFreedom has quit [Remote host closed the connection]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 248 seconds]
Ven`` has quit [Ping timeout: 265 seconds]
Ven`` has joined #crystal-lang
Ven`` has quit [Ping timeout: 240 seconds]
Ven`` has joined #crystal-lang
Ven`` has quit [Ping timeout: 264 seconds]
Ven`` has joined #crystal-lang
Ven`` has quit [Client Quit]
alex`` has quit [Ping timeout: 240 seconds]
<FromGitter>
<bew> watzon: just put your `LOGGER` instance in the `Deus` namespace, not in `Deus::Logger`, this xay you can do `Deus::LOGGER.debug ...`
<watzon>
Now that you say that it sounds so obvious haha
<FromGitter>
<bew> No need for macro stuff generating missing methods, just use the LOGGER instance directly
return0e has joined #crystal-lang
<FromGitter>
<bew> :)
faustinoaq has quit [Ping timeout: 248 seconds]
<FromGitter>
<bew> watzon: about the `\b` you said you thought it would have been escaped => Why? And if so, how do you put a `\b` (called backspace in 'man ascii') ?
<watzon>
Because it was in a string
<FromGitter>
<bew> when you use `"\n"` it's not escaped as `"\\n"`
<FromGitter>
<bew> if you want that, you can use `%q(\n)`
<FromGitter>
<bew> this is the raw string literal, everything in there will be as is, without any understanding on the content like `\` then `n` is a converted to a newline in normal string literal.
rohitpaulk has joined #crystal-lang
LastWhisper____ has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
rohitpaulk has quit [Ping timeout: 264 seconds]
devil_tux has quit [Ping timeout: 265 seconds]
<watzon>
So you're saying a double backslash doesn't escape? So `\\n` wouldn't escape the newline?
<FromGitter>
<bew> huh no, I'm not saying that
devil_tux has joined #crystal-lang
<FromGitter>
<bew> `\n` gives you the char newline, `\\n` gives you 2 chars `\` and `n`
<watzon>
What's the difference between `p` and `puts`? Because if you do `puts "foo\nbar"` the newline is inserted as a newline literal and `puts "foo\\nbar"` escapes the literal.
<FromGitter>
<bew> `puts` will just print the string with a call to `to_s` on the object(s), `p` will do the same but bye calling `inspect` on the object(s)
<watzon>
Ahh I see. `p` and `pp` are the same?
<FromGitter>
<bew> almost
<FromGitter>
<bew> `pp` will also print before what you gave it, e.g: `pp 1 + 2` will give `1 + 2 # => 3`
<FromGitter>
<bew> `pp` is a macro, this is wy it is able to get and print `1 + 2`
<watzon>
Ahh I see
<watzon>
Ok cool
<FromGitter>
<bew> All this is explained in the docs!
<FromGitter>
<bew> or API
<watzon>
But my point I think is still valid, unless I'm missing something. When a string, not a raw one, is printed `\n` becomes a newline literal and `\\n` becomes an escaped `\n` right?
<watzon>
That's why I figured the `\b` might be getting escaped before it got passed to grep.
<FromGitter>
<bew> yes but no, to escape `\b` you would have to write `\\b`
<FromGitter>
<bew> to have an escaped `\b` as you just said for `\n`
tobyfree has joined #crystal-lang
<tobyfree>
is anyone here familiar with file uploads in kemal?
<watzon>
Exactly haha. So when his `\b` was passed to grep it got passed as an unescaped literal, but grep expected to receive an escaped one
<watzon>
At least that's what my thought process was. It seemed to work.
<tobyfree>
i'm getting a missing hash key error when trying to access env.params.files[
greengriminal has joined #crystal-lang
<FromGitter>
<bew> ah yes watzon, grep want `\b` as 2 chars, so when writing the string in Crystal, you have to escape it, so that it is sent as 2 chars and not one
<watzon>
Are you sure the key you're expecting to be there is actually there?
<FromGitter>
<bew> \o/ x)
<watzon>
@bew yup, that's the point I was trying to make haha
<watzon>
tobyfree: you can check if the key is there first by using `Hash#has_key?`
<FromGitter>
<bew> perfect then, long discussion to realize we were saying the same thing ^^
<watzon>
Or list all the keys for debugging purposes with `Hash#keys`
<FromGitter>
<aisrael> @watzon “ We need an interpreted version of Crystal for scripting. CrystalScript or something.” ⏎ ⏎ Uhm, isn’t that called Ruby? /snark
<watzon>
I figured we were haha. It's just hard to communicate these sometimes
<watzon>
@aisrael I was waiting for someone to say that
<watzon>
Lol
<tobyfree>
watzon, no, it doesn't seem like its being parsed by kemal. the file input is named correctly and I have enctype="multipart/form-data", tested in both curl and chrome
<FromGitter>
<bew> yeah and I'm not a native english speaker, so I prefer to over-explain to make sure the message pass
<watzon>
@bew that seems like the safe option
<FromGitter>
<bew> but sometimes I don't understand what other are saying (or missing the context) so we have this kind of discussion
<tobyfree>
ah, it might be in env.params.body and not env.params.files
greengriminal has quit [Quit: Leaving]
duane has quit [Ping timeout: 255 seconds]
<tobyfree>
ah nevermind, I had a type in my enctype attribute, not sure why it was failing with curl though