RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.25.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
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 264 seconds]
Raimondii is now known as Raimondi
<FromGitter> <drosehn> [back to overflows on constants] Ah, overriding `**`. That's one of those features that I always forget about. Come to think of it, one trick I could use is that *I* could overload `**` for `Int23`, and do some magic in there! I'll have to try that sometime.
<FromGitter> <drosehn> Uh, make that `Int32`. I'm not in a position to be announcing any dramatically new hardware right now!
jeet has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
akaiiro has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 264 seconds]
Raimondii is now known as Raimondi
<FromGitter> <DanilaFe> Int23 sounds like just the right number of bits
<FromGitter> <cpunion> https://play.crystal-lang.org/#/r/4nxz This code snipet is from `graphql-crystal`, can’t compiles, how to make it works?
<FromGitter> <icyleaf> why not use `JSON.parse(params.to_json)`
<FromGitter> <cpunion> Great idea! Thanks!
<FromGitter> <aa-tan> Quick question, is this the proper way to call the SHA1 hash function? It seems to work in the crystal playground but I get an undefined constant error when calling it from my application. ⏎ ⏎ ```require "openssl" ⏎ OpenSSL::SHA1.hash("test_string")``` [https://gitter.im/crystal-lang/crystal?at=5b63f1aa85278d705e7a07c8]
<FromGitter> <codenoid> hi crystaller
<FromGitter> <aisrael> @aa-tan Do you need OpenSSL specifically? I mean, if you just need SHA1 have you tried Digest::SHA1?
flaviodesousa has joined #crystal-lang
ashirase has quit [Ping timeout: 264 seconds]
ashirase has joined #crystal-lang
flaviodesousa has quit [Remote host closed the connection]
Ragnor1 has joined #crystal-lang
Ragnor1 has quit [Killed (Sigyn (Spam is off topic on freenode.))]
<Ragnor1> With our IRC ad service you can reach a global audience of entrepreneurs and fentanyl addicts with extraordinary engagement rates! https://williampitcock.com/
<RX14> *sigh*
<RX14> its not over
return0e_ has joined #crystal-lang
<FromGitter> <j8r> @talbergs If it can help you, I've made a text editor in Crystal. You might find some relevant code in https://github.com/j8r/cride/tree/master/src/cride/terminal
return0e has quit [Ping timeout: 264 seconds]
<FromGitter> <MrSorcus> Hi all. https://play.crystal-lang.org/#/r/4nzk - it's normal?
flaviodesousa has joined #crystal-lang
Totoro has quit [Ping timeout: 245 seconds]
sagax has joined #crystal-lang
<sagax> hi all!
<sagax> what we have like as "gems"?
<sagax> where i can found this?
<FromGitter> <sdogruyol> @sagax http://crystalshards.xyz/
<sagax> thanks
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
<FromGitter> <j8r> why there is crystal on the site? The language itself isn't a shard
<FromGitter> <sdogruyol> it just scans github with language:crystal search
<FromGitter> <j8r> so the site's name isn't really correct 😄
<FromGitter> <sdogruyol> why not?
<FromGitter> <fridgerator> what happens if you add crystal as a shard dependency?
<FromGitter> <fridgerator> inception?
<RX14> it fails because theres no shard.yml
<FromGitter> <fridgerator> darn
<FromGitter> <sdogruyol> lol
<FromGitter> <gustavramestad> How do i compare variables in an if statement
<FromGitter> <Blacksmoke16> what kind of comparison?
<FromGitter> <Blacksmoke16> ```if var1 == var2 ⏎ # Do stuff? ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5b6458afc917d40dc2391645]
<FromGitter> <Blacksmoke16> or
<FromGitter> <gustavramestad> I forgot the double ==, it was a while since I programmed anything
<FromGitter> <Blacksmoke16> Do stuff if var1 == var2
<FromGitter> <j8r> what the purpose of `should be_true` vs `should eq true` in specs?
<z64> it's the same thing
<z64> the implementation is `def be_true; eq true`
<FromGitter> <j8r> just an alias?! sad
<z64> not completely an "alias", it calls `eq` with a specific value (doesn't just delegate to `eq`). don't think its a big deal, spec DSLs are usually tuned to be expressive & read like that
<z64> rspec etc
<FromGitter> <j8r> I will keep the space vs the underscore, and the q vs the b :)
Raimondii has joined #crystal-lang
<FromGitter> <j8r> I feels more Crystalish, and nicer in text editor with syntax highlightning
Raimondi has quit [Ping timeout: 244 seconds]
Raimondii is now known as Raimondi
<z64> highlightning? oh my:)
<z64> sounds like a "power mode" type plugin lol
<FromGitter> <j8r> haha
<sagax> strange
<sagax> i try compile example from this link http://ru.crystal-lang.org/2013/07/10/hello-world.html
<sagax> where "class Greeter"
<sagax> and this example don't compile
<sagax> >> in helloworld.cr:3: Can't infer the type of instance variable '@name' of Greeter
<z64> sagax: that is a pretty old example (2013). follow the compiler errors instructions; you have to specify a type restriction to `@name`
<sagax> name : String ?
<sagax> i added this, but any don't work
<z64> if you're talking about `name` in `def initialize(name : String)`, no - you need to apply it to the instance variable. somewhere in the class, you write `@name : String`
<z64> if you're just getting familiar with crystal, you should read https://crystal-lang.org/docs/ - it has the most up to date examples and tutorials on the language's syntax/semantics
<sagax> strange
<z64> the old example (2013) you linked works if you don't have `.capitalize` https://carc.in/#/r/4o0j
<z64> when you add `.capitalize`, the compiler doesn't know yet what type `@name` will end up being
<sagax> thanks
jeet has quit [Ping timeout: 240 seconds]
<FromGitter> <talbergs> @j8r very much apprecited thanks for `cride`
<FromGitter> <talbergs> @robacarp thanks @straight-shoota thanks for insight!
vegai has joined #crystal-lang
wontruefree has joined #crystal-lang
akaiiro has quit [Remote host closed the connection]
akaiiro has joined #crystal-lang
wontruefree has quit [Quit: bye]
Groogy has joined #crystal-lang
<FromGitter> <Michionlion> Hey does anyone know how you get the `Defined in` section populated if you're generating docs?
wontruefree has joined #crystal-lang
<FromGitter> <asterite> It's done automatically
<FromGitter> <ninjablog> hi all, I've got a rather newb question regarding database ResultSets
<FromGitter> <ninjablog> basically all I was trying to do (and failed baldy) is return a generic Hash Map, without having to manually specify each column type
<FromGitter> <ninjablog> I have been able to do this in every other language e.g Python, PHP, Kotlin etc, but Crystal is has alluded me
<robacarp> @ninjablog want to post your code?
bmcginty has quit [Ping timeout: 264 seconds]
<FromGitter> <ninjablog> its some sandbox code
<FromGitter> <ninjablog> its using Will's PG lib
<FromGitter> <ninjablog> its kind of a shame, I had lots of projects I could have used Crystal for, but this has become a show stopped :(
<FromGitter> <ninjablog> I'll try and post some code later, turns out I need to go :)
Jenz has joined #crystal-lang
<FromGitter> <yorci> i have a string which is contain `\r\n` characters, but when i print it in kemal template file, it prints inline text, how can i print that string multi line ?
<Jenz> Can anyone take a quick look at this?: https://play.crystal-lang.org/#/r/4o1a
wontruefree has quit [Quit: this is not the client you are looking for]
<Jenz> Has to do with automatic casting (I think)
<FromGitter> <Michionlion> @asterite That doesn't seem to be working then... is it only with Github projects?
<oprypin> yorci, maybe it's just HTML, it doesn't care about newlines
<FromGitter> <Blacksmoke16> im not sure i see the issue with that jenz, you are passing a new Bar element to a method that is typed to only take Foo?
<FromGitter> <Michionlion> @oprypin Thanks!
<oprypin> yorci, you can try `white-space: pre-wrap;` in CSS or maybe replacing \n with <br>
<oprypin> Jenz, step one, stop using `record` so you can see what's really happening
<FromGitter> <yorci> @oprypin yea i did replace thing but im asking there is built-in something for it in html class
<Jenz> oprypin: I like `record`...
<FromGitter> <yorci> its kinda looks ugly you know
<oprypin> Jenz, i'm not telling you what you should use in the long term. this is debugging
<Jenz> I think it's beautiful
* Jenz ¯\_(ツ)_/¯
<Jenz> Then, here is updated version: https://play.crystal-lang.org/#/r/4o1u/edit
<Jenz> uh, just pretend it says "getter" not "property"
* Jenz XD
<oprypin> Jenz, ok so how can you define a method with one type but then pass a completely different type?
<oprypin> regardless of the method #foo
<Jenz> I was just wondering if it is a way
<Jenz> given the method #foo
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4o1x
<FromGitter> <Blacksmoke16> would have to use an overload of the method that takes bar then prints bar's foo's qux?
<Jenz> Well, I guess
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4o1y
<oprypin> here's a classic
<oprypin> and this is maybe more along the lines of what you were thinking
<oprypin> though i think this would kinda be fooling yourself
<Jenz> Oh, yeah thats just what I wanted
<Jenz> Fooling myself sounds great
<FromGitter> <Michionlion> Not really good code that last one
<Jenz> There a method_missing macro hook or something as well right? I can probably figure a way to make it not so much fool-yourself
bmcginty has joined #crystal-lang
<oprypin> well yeah lol
<oprypin> https://crystal-lang.org/api/0.25.1/Object.html#delegate%28%2Amethods%2Ctoobject%29-macro
<Jenz> haha
<Jenz> what does \{{x}} do?
<Jenz> Oh double macro, nvm
<Jenz> or, wait what?
<Jenz> nvm the nvm
* Jenz DX
<Jenz> Oh wait, nvm the nvm the nvm
<Jenz> I got it
<FromGitter> <bew> X)
<Jenz> Yeah thanks, I got it
jeet has joined #crystal-lang
<Jenz> Oh damn, segfault, that's pretty rare for crystal
<Jenz> I get I am doing something very stupid though
<Jenz> Is there a way to kinda— "cancel", the method_missing macro hook?
<Jenz> i tried previous_def to no avail
<oprypin> Jenz, what? no
<Jenz> Uh, sorry badly phrased, I'll try again
<robacarp> Jenz: just define the method regularly?
<Jenz> no, sorry, badly phrased
<Jenz> I want to use method_missing to forward methods if certain conditions are met, otherwise, throw an error like normally. E.g.: https://play.crystal-lang.org/#/r/4o2q, here I want the call to qux, to be forwarded to Foo, while I want the call to the nonexistant method bar to throw an error like normal
<Jenz> Sorry for being so craving and bothersome...
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4o2s ?
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/4o2u formatted a bit better
<Jenz> @Blacksmoke16, indeed that works, but its not as well formatted and put as how crystal does it natively
<Jenz> s/put as/put as nicely
<Jenz> eh, s/put as nicely/put as nicely as
<Jenz> I guess
<Jenz> So it gets: ... and put as nicely as how crystal does it natively
<Jenz> (I mean the error message, if that was not clear)
<FromGitter> <Blacksmoke16> you can make the exception message whatever you want, im not sure i see what you mean?
<robacarp> Jenz: the difference is that the error message you're getting in Crystal is from the _compiler_
<robacarp> the code sample provided by Blacksmoke16 is going to have a runtime exception
<Jenz> robacarp: Yeah, and I am wondering if it is possible to get the compiler to throw the error
<robacarp> you can mock out the compiler error message all you want, but by hooking method_missing like this, you're defeating the purpose of the compiler
<robacarp> you could put the check in macro-space instead
<robacarp> but then you lose the ability to prevent dispatching the method based off of runtime variables
jeet has quit [Ping timeout: 260 seconds]
<Jenz> lucklily I don't need that
<Jenz> Thanks
<robacarp> (similarly, if you want the compiler error message, you're going to have to mock it out yourself)
<Jenz> Yeah, thanks
Groogy has quit [Quit: WeeChat 2.2]
DTZUZO has quit [Ping timeout: 240 seconds]
olbat__ has quit [Changing host]
olbat__ has joined #crystal-lang
<FromGitter> <Michionlion> https://play.crystal-lang.org/#/r/4o43 -- why is the result `Array(NoReturn)` instead of `Array(Float)`? Seems counter-intuitive, the block only returns `Float64` or nil...
Jenz has left #crystal-lang [#crystal-lang]
<FromGitter> <bmulvihill> Looks like compact_map can't determine the type because the first yield will return Nil
<FromGitter> <bmulvihill> https://play.crystal-lang.org/#/r/4o4d
<FromGitter> <Michionlion> How does compact even work for arrays that start with nil then?
<FromGitter> <Michionlion> Is there some kind of dynamic generic addition happening on `<<` of a new type?
<FromGitter> <Michionlion> because that doesn't seem like something crystal can do
<FromGitter> <Michionlion> https://play.crystal-lang.org/#/r/4o4k
<FromGitter> <Michionlion> That yields 5 which result in `nil.not_nil!` but somehow the type that comes out is `Int32`, what fits the second element...
<FromGitter> <Michionlion> https://play.crystal-lang.org/#/r/4o4m < this makes sure it's getting the nil
vikaton has joined #crystal-lang
<FromGitter> <bmulvihill> this works https://play.crystal-lang.org/#/r/4o4x
<FromGitter> <Michionlion> Feels like a bug or problem with the implementation...
<FromGitter> <Michionlion> because that results in a `typeof(nil.not_nil!)` as the resulting array type
<FromGitter> <Michionlion> so how does it get `Float64`?
<FromGitter> <bmulvihill> looks like its related to the is_a?(Float64) since the array is Int32 it will never hit that branch and basically be something like this https://play.crystal-lang.org/#/r/4o4y
<FromGitter> <Michionlion> huh
<FromGitter> <bmulvihill> does seem a bit strange though
<FromGitter> <Michionlion> I think it might be related to the fact that the result from `typeof` is `CONST`
ua_ has joined #crystal-lang
<FromGitter> <Michionlion> It must be detecting that there is no return path at all when the array does not have `Float64` in it's type, so the `CONST` returned is `NoReturn` since it will raise. But if `Float64` is possibly in the array, it can possibly return, so `typeof` returns `Float64`. A combination of however `typeof` is implemented, and the fact that it's specialized at compile-time
<FromGitter> <Michionlion> It can't detect the case where it will fail because there are no elements of that type inside the array -- thats after compile-time stuff is evaluated
ua has quit [Ping timeout: 240 seconds]
<FromGitter> <Michionlion> It looks like the yield is never actually done, just the possible result types are considered (https://play.crystal-lang.org/#/r/4o5b)
<FromGitter> <Michionlion> I don't understand why it doesn't just get the `Float64` in the case where it isn't in the array's type
<FromGitter> <Michionlion> maybe because multiple versions of a block are actually codegenned with different parameter types? I don't know how that works...
<FromGitter> <Michionlion> it's definitely weird though
<FromGitter> <asterite> It's because it's impossible for an element to be Float64, so the only branch hit is nil. And compact map discards nil, so you end up without types, which is what NoReturn is
<FromGitter> <asterite> It's not a bug. It's a natural consequence of of the type system
<hightower4> Hey where can I see example of using an ORM with Kemal?
DTZUZO has joined #crystal-lang
<FromGitter> <Blacksmoke16> is there a good way to get the name of the class you are in using like `self.class.name` but without the namespace stuff
<FromGitter> <Blacksmoke16> i.e. `Foo` vs `Api::Models::Foo`
<FromGitter> <Blacksmoke16> for granite you would just have to do like `Granite::Adapters << Granite::Adapter::Pg.new({name: "pg", url: ENV["DATABASE_URL"])` before your require the granite adapter
<FromGitter> <Blacksmoke16> then `require "granite/adapter/pg"`
<FromGitter> <Blacksmoke16> then just follow the standard granite setup, in routes could do like `User.first.to_json` etc
hightower4 has quit [Ping timeout: 248 seconds]
return0e_ has quit [Ping timeout: 265 seconds]
return0e has joined #crystal-lang
<FromGitter> <reiswindy> @hightower ⏎ There's an example with Crecto ORM here: https://github.com/reiswindy/kemal-realworld ⏎ An example with Core ORM here: https://github.com/vladfaust/crystalworld
return0e has quit [Quit: Leaving...]
return0e has joined #crystal-lang