ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.33.0 | 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
<postmodern> Blacksmoke16, i need to do char.ord all within the macro, because i'm generating values that go into an enum
<FromGitter> <Blacksmoke16> you cant
<FromGitter> <Blacksmoke16> `Char` !=` CharLiteral`
<postmodern> exactly, thus my "why the heck" :)
<FromGitter> <Blacksmoke16> macro types use a subset of the runtime type that are hardcoded in the compiler
<postmodern> ah
<FromGitter> <Blacksmoke16> it would be trivial to add, but would have to make a PR, and wait for next release
<FromGitter> <Blacksmoke16> https://github.com/crystal-lang/crystal/pull/8836 would help
<postmodern> could i add my own ASCII lookup table that the macro uses to map CharLiteral to Int?
<FromGitter> <Blacksmoke16> you could do something like that
<FromGitter> <Blacksmoke16> define a hash with the key as the char and the value the int value
<FromGitter> <Blacksmoke16> essentially replicate what `.ord` does
<FromGitter> <Blacksmoke16> would be the hacky workaround
<oprypin> postmodern, i dont get it. `p {{ 'a'.stringify }}`
<oprypin> oh but it's a string then
<FromGitter> <Blacksmoke16> right
<postmodern> also stringify returns a StringLiteral, i believe
<FromGitter> <Blacksmoke16> right
<postmodern> oprypin, here's a simplified example of what i'm trying to do: https://carc.in/#/r/8mnh
<oprypin> postmodern, one pragmatic option would be to just write out the integer
<oprypin> actually in hexadecimal would be nice
<oprypin> and then do an assert that the value equals to your computation but at runtime
<oprypin> (could be in specs)
<oprypin> i think doing computations inside `lib` is bound to get you into more trouble than just the macro itself
<oprypin> the available syntax in them is limited, right? but what you want should still be supported, yeah
* FromGitter * Blacksmoke16 wants the PR
<postmodern> oprypin, but then you lose the four character code (fourcc) information. You'd have to move that into a comment or something, because that's how pixel formats are historically represented
<postmodern> Blacksmoke16, where would i put the CharLiteral#ord method?
<FromGitter> <Blacksmoke16> sec i have that branch checked out, i can try it
<oprypin> postmodern, in the context of #8836 or without it?
<DeBot> https://github.com/crystal-lang/crystal/pull/8836 ([Experimental] Allow user-defined macro methods)
<FromGitter> <Blacksmoke16> with it
<postmodern> depends if 8836 will be accepted before the next release?
<postmodern> might be more pragmatic to just add CharLiteral#ord directly
<FromGitter> <Blacksmoke16> could add it either way
<oprypin> postmodern, yea lol do the lookup table. write out a HashLiteral 😬
<FromGitter> <andrewc910> In a config class for my shard I have an option for setting the mailer class. How can I do something like `property mailer_class : Mochi::Mailer = Mochi::Mailer`. I need to set a default but I get an error like 'mailer_class cannot be Mochi::Mailer.class'. May I ask for proper syntax?
<FromGitter> <Blacksmoke16> actually cant seem to get it to work
<FromGitter> <Blacksmoke16> add a `.new`
<FromGitter> <Blacksmoke16> otherwise you're trying to assign the class `MochI::Mailer` to something typed as an instance of it
<FromGitter> <Blacksmoke16> postmodern: sorry that method is inherently missing so it would have to be added even with that PR :/
<FromGitter> <watzon> Man I'm excited https://github.com/metacall/core/issues/38
<postmodern> ok i created an ascii table, and it appears to be generating number literals, but now i get this error when it's called from within the enum
<postmodern> Error: unexpected token: 826427218
sz0 has quit [Quit: Connection closed for inactivity]
<FromGitter> <Blacksmoke16> Called how?
<postmodern> it appears that macros cannot be used within enums at all?
<FromGitter> <Blacksmoke16> Can you share the error and trace
<postmodern> i think this is a simpler example https://carc.in/#/r/8mnk
<FromGitter> <Blacksmoke16> Try wrapping the macro def in begin end macro block
<postmodern> here's a more complete example https://carc.in/#/r/8mnl
<FromGitter> <christopherzimmerman> @ArtLinkov @bararchy I just merged in a PR to add opencl integration to num.cr (https://github.com/crystal-data/num.cr), it would be awesome to have GPU support in shainet! If you have specific ways you'd like to integrate it that I would be able to take care of, just let me know.
<FromGitter> <andrewc910> @Blacksmoke16 Thank you very much. I have that feeling when you're four characters away from fixing a problem that's been bugging you for a week. :facepalm:
<postmodern> Blacksmoke16, begin/end around the macro or around it's body?
<FromGitter> <watzon> @postmodern it appears as though you've found a bug
<FromGitter> <watzon> I don't think that's intended
<FromGitter> <watzon> Just something that doesn't happen much
<postmodern> a bug? in software? surely you jest
<FromGitter> <watzon> Lmao
<postmodern> watzon, which example should i submit in my bug report, and am i correct that it appears macros cannot be called from within enum bodies?
<FromGitter> <watzon> It defintely looks that way. I'd submit both, one as a simple example and the other as a more complete example.
<FromGitter> <watzon> I tried everything I could think of to make it work
<FromGitter> <Blacksmoke16> Around where you set the enum value
<postmodern> tried putting begin/end around the enum element assignment, and the whole enum it self
<postmodern> Error: expecting token 'EOF', not 'end'
<FromGitter> <Blacksmoke16> should it exist in a `lib`?
<FromGitter> <Blacksmoke16> works when its not
<FromGitter> <Blacksmoke16> `enum Linux::V4L2PixFmt` would do the same job
<postmodern> Blacksmoke16, it probably should because it comes from C and is used in other C structs
<postmodern> that also seems like a bug, is it some scope difference issue?
<FromGitter> <Blacksmoke16> idk much about the c binding stuff, but essentially `lib` is a macro too i think?
<FromGitter> <watzon> I tried taking the enum out of `lib` and it still didn't work
<FromGitter> <Blacksmoke16> ofc have to remove the `Linux::` namespace from the type too
<postmodern> enum LibName::EnumName did work for me with the simplified example
<FromGitter> <Blacksmoke16> https://carc.in/#/r/8mo3
<postmodern> can macros not call other macros from within {{ }} ?
<FromGitter> <Blacksmoke16> *thats* what that PR is for
<FromGitter> <Blacksmoke16> but yes, you'll have to duplicate the logic
<postmodern> ah, i thought it was about adding methods to the Macros Classes
<FromGitter> <Blacksmoke16> that too, but is slightly diff
<FromGitter> <Blacksmoke16> you can add custom macros to the macro classes, but not actual methods
<FromGitter> <Blacksmoke16> i.e. could do
<FromGitter> <Blacksmoke16> ```class Crystal::Macros::StringLiteral ⏎ macro add_foo ⏎ "foo " + seld ⏎ end ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e55c9fa3e6ef6416175d1cf]
<FromGitter> <Blacksmoke16> which would allow you to do `"bar".add_foo`
<FromGitter> <Blacksmoke16> `+ self`*
<postmodern> hmm getting Nils from my ascii_table. Do CharLiterals not compare with Chars? Do I have to coerce the values?
<FromGitter> <Blacksmoke16> check the value that is causing nil
<postmodern> RGB444 = v4l2_fourcc('R', '4', '4', '4') # 16 xxxxrrrr ggggbbbb
<postmodern> particularly the ^ is pointing to the last '4'
<FromGitter> <Blacksmoke16> sure thats it? https://carc.in/#/r/8mo6
<postmodern> weird it compiles on carc.in, but not locally with 0.33.0
<postmodern> 72 | {{ (ascii_table[a] | (ascii_table[b] << 8) | (ascii_table[c] << 16) | (ascii_table[d] << 24)) }}
<postmodern> Error: undefined macro method 'NilLiteral#<<'
<FromGitter> <Blacksmoke16> :thinking:
<postmodern> odd that the previous line parsed just fine: RGB332 = v4l2_fourcc('R', 'G', 'B', '1') # 8 RGB-3-3-2
<postmodern> both contain uppercase and numeric char literals
<FromGitter> <Blacksmoke16> Dunno
<postmodern> dang ran out of workarounds
<FromGitter> <Blacksmoke16> Not missing a char or something?
<FromGitter> <Blacksmoke16> That carc fails when you run it as is locally?
<postmodern> er i had to edit the source code a bit so the line numbers don't match with the error
<postmodern> ah ha, compiling the file separately works. It's something else in my source code...
<FromGitter> <Blacksmoke16> 👍
<postmodern> hmm or maybe it's being optimized out in my single file example
<postmodern> the backtrace is wrong
<postmodern> print debugging found it, a ' ' char that i was missing
<postmodern> but coming from line 137, not 89
<FromGitter> <Blacksmoke16> 😬
<postmodern> hmm can't repro outside of my code
<postmodern> far too many hacks and bugs here. hope that macros and enums get some work
<FromGitter> <andrewc910> Is it possible to determine a parent class from a variable? `MyController < Mochi.config.parent_controller`
<FromGitter> <andrewc910> Can't find anything in docs.
<FromGitter> <andrewc910> I thought about a macro but then that requires me to require files and invoke methods in a very particular order that I am not fond of.
<FromGitter> <watzon> Not like that, but I'm pretty sure you can with a macro
<FromGitter> <watzon> You also can't extend a non-constant
<postmodern> do variadic function declarations require an argument?
<postmodern> can i call foo(a,b,...) as foo(a,b)?
<FromGitter> <andrewc910> May I ask what you mean by 'you can't extend a non-constant'? I don't truly understand extend.
<FromGitter> <andrewc910> I'll try with macros. Just need to think about implementation. 😭
<FromGitter> <tenebrousedge> postmodern, if you have `foo(a, *b)` then yes
<postmodern> ah forgot to splat the args
<FromGitter> <Blacksmoke16> @andrewc910 thats not possible
<FromGitter> <Blacksmoke16> unless you define some method within the parent that would expose it as a class method
<postmodern> is it possible to define macros local to a class or namespace? or are all macros global?
<FromGitter> <Blacksmoke16> they would work just like class methods
<FromGitter> <andrewc910> @Blacksmoke16 best to use a macro?
<FromGitter> <Blacksmoke16> What are trying to do exactly?
<FromGitter> <Blacksmoke16> got auto service resolution implemented
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e55e3c33e6ef64161760a03]
<FromGitter> <Blacksmoke16> if no arguments are provided to `Register`, it'll fallback to the initializer arguments, attempting to resolve arguments automatically based on type restriction
<FromGitter> <Blacksmoke16> if multiple services are registered with that type, will fall back on the arg's name
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e55e515ef8d646099d11a6a]
<FromGitter> <andrewc910> @Blacksmoke16 In my shard, i have controllers already made for people. I made an `ApplicationController` which inherits from `Amber::Controller::Base`. All my controllers parent class is this `Mochi::ApplicationController`. I would like for people to be able to change it.
<FromGitter> <Blacksmoke16> change the base class?
<FromGitter> <andrewc910> Id like Mochi::Controllers::ApplicationController to be something like `Mochi.config.parent_controller`.
<FromGitter> <Blacksmoke16> ```code paste, see link``` ⏎ ⏎ to close the loop, can use the initializer's named prefixed with `_` to manually specify a specific arg/service to use [https://gitter.im/crystal-lang/crystal?at=5e55e69ffa9f20553b4fd60b]
<FromGitter> <Blacksmoke16> @andrewc910 yea thats not possible
<FromGitter> <andrewc910> If i use a macro, then you have to require the app controller, invoke the macro then require the rest of the files. I don't like that things need to be in such a specific order :/
<FromGitter> <andrewc910> Macro it is!
<FromGitter> <Blacksmoke16> can you not make it a module or something?
<FromGitter> <Blacksmoke16> then they can just include it whereever they want?
<FromGitter> <andrewc910> I can with a different implementation. Currently, a user would inherit from my controller then their controllers look like: ⏎ ⏎ ```def confrm ⏎ super ⏎ end``` ⏎ ⏎ It seems like modules would be best. My controllers are full modules instead of classes, the controller i generate for you already have the mixin and the same final effect is done. [https://gi
<FromGitter> ... tter.im/crystal-lang/crystal?at=5e55e883101adb4160c8a2b6]
<FromGitter> <Blacksmoke16> pretty sure that would still work
<FromGitter> <andrewc910> If i converted it to a module the controller class would look like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e55e8d4fa9f20553b4fd9cc]
<FromGitter> <andrewc910> obvious the params method wouldn't be empty but you get the point
<FromGitter> <andrewc910> I think that would work too. Just sucks you can't see the methods directly in your controller. You can still do some before/after code which is nice.
<FromGitter> <Blacksmoke16> prob would show up in generated api docs
darkstardevx has quit [Remote host closed the connection]
ur5us has quit [Ping timeout: 240 seconds]
<FromGitter> <andrewc910> That's true. I have to sit and think of some other implementations. I think pure modules is the way to go but I'm not really liking it.
darkstardevx has joined #crystal-lang
<FromGitter> <Blacksmoke16> sounds like a plan
<FromGitter> <WintonMc_twitter> Hi
<FromGitter> <WintonMc_twitter> I'm new, someone tells me why I can't post anything on forum
<FromGitter> <tenebrousedge> do you get some sort of error message?
<FromGitter> <WintonMc_twitter> I registered yesterday, they gave me a badge and well I still don't know
<FromGitter> <WintonMc_twitter> https://prnt.sc/r7qgk3
<FromGitter> <tenebrousedge> and do you get an error if you try to create a new topic?
<FromGitter> <WintonMc_twitter> I do not go out to create a new
<FromGitter> <WintonMc_twitter> It does not give me the option
<FromGitter> <WintonMc_twitter> I still have 2 weeks learning this language, works well backed
<FromGitter> <WintonMc_twitter> ?
<FromGitter> <tenebrousedge> yes, it's a very nice backend language. It's very surprising to me that you're having trouble with the forums. I've never had any problems, but perhaps it's because I used github to sign up
<FromGitter> <grkek> @sorcus Yeah I saw that made me really happy
<FromGitter> <grkek> @watzon Sup, I had to work on a backend project for one of my buddies and was so busy that crystal progressed with 2 versions, haha. very nice very nice
ur5us has joined #crystal-lang
_ht has joined #crystal-lang
<sorcus> grkek: :-)
ur5us has quit [Ping timeout: 240 seconds]
_whitelogger has joined #crystal-lang
sz0 has joined #crystal-lang
<FromGitter> <wout> Given the following json string: `%({"value":"3.14","currency":"EUR"})`. What would be to convert the `value` to `BigDecimal` when the struct includes `JSON::Serializable`? Should I use a `JSON::Field` annotation with a converter, or is there a more convenient way?
<FromGitter> <Blacksmoke16> converter
<FromGitter> <wout> @Blacksmoke16 Thanks!
<FromGitter> <asterite> Doesn't BigDecimal already know how to de serialize from JSON?
<FromGitter> <wout> @asterite It does not so it seems. I have tried a few things but I keep getting `Error: can't cast (String | Nil) to BigDecimal`.
<FromGitter> <wout> Probably because it is `String | Nil` instead of `String`?
<FromGitter> <wout> Using `@[JSON::Field(nilable: false)]` results in:
<FromGitter> <wout> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e566e61fa9f20553b513dab]
<FromGitter> <j8r> `405 Method Not Allowed`... this means the router has to store the route, then the methods available for each one.
<FromGitter> <j8r> I have done the other way around :/
<FromGitter> <Blacksmoke16> 😐
<FromGitter> <j8r> I was taking example in Kemal, that stores the HTTP method first - need to store it last. ⏎ What does Athena?
<FromGitter> <Blacksmoke16> athena does like `"/" + method + prefix + path`
<FromGitter> <Blacksmoke16> so like `"/" + "GET" + "" + "/foo/bar"`
<FromGitter> <j8r> so 405 can't be supported easily
<FromGitter> <Blacksmoke16> i use 405 for CORs, but otherwise it would be 404
<FromGitter> <j8r> On my side I will first resolve the path, then return available actions
<FromGitter> <j8r> It would also simplify doc generation :D
<FromGitter> <j8r> I was planning to release today, but I need to fix this first
<FromGitter> <Blacksmoke16> > On my side I will first resolve the path, then return available actions ⏎ ⏎ how does this work? wouldnt the path map 1:1 to an action?
<FromGitter> <j8r> now it is the case
<FromGitter> <j8r> in the future the path can map to one Object, which holds 0 to several actions
<FromGitter> <j8r> this will allow to send a 405 is there are actions available
FromGitter has quit [Ping timeout: 245 seconds]
postmodern has quit [Quit: Leaving]
dwdv has joined #crystal-lang
_whitelogger has joined #crystal-lang
MasterdonX has quit [Ping timeout: 272 seconds]
masterdonx2 has joined #crystal-lang
Nekka has quit [Read error: Connection reset by peer]
Nekka has joined #crystal-lang
travis-ci has joined #crystal-lang
travis-ci has left #crystal-lang [#crystal-lang]
<travis-ci> crystal-lang/crystal#c4d70bc (master - Deque#from_json/to_json (#8850)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/655485846
<DeBot> https://github.com/crystal-lang/crystal/pull/8850 (Deque#from_json/to_json)
Human_G33k has quit [Ping timeout: 240 seconds]
Human_G33k has joined #crystal-lang
ur5us has joined #crystal-lang
waleee-cl has joined #crystal-lang
waleee-cl has left #crystal-lang [#crystal-lang]
_ht has quit [Remote host closed the connection]
teardown has quit [Ping timeout: 258 seconds]
teardown has joined #crystal-lang
teardown has quit [Ping timeout: 258 seconds]
darkstardevx has quit [Remote host closed the connection]
darkstardevx has joined #crystal-lang
lunarkitty has quit [Ping timeout: 246 seconds]
darkstardevx has quit [Remote host closed the connection]
lunarkitty has joined #crystal-lang
darkstardevx has joined #crystal-lang
teardown has joined #crystal-lang
masterdonx2 has quit [Read error: Connection reset by peer]
MasterdonX has joined #crystal-lang
darkstardevx has quit [Remote host closed the connection]
darkstardevx has joined #crystal-lang
ur5us has quit [Ping timeout: 240 seconds]
ur5us has joined #crystal-lang
_whitelogger has joined #crystal-lang