<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>
<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/
<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
<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
<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>
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...
<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
<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>
<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> 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