RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.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
<FromGitter> <Blacksmoke16> `arr = [] of String`
<FromGitter> <Blacksmoke16> oh
<FromGitter> <Blacksmoke16> `arr = [] of Array(String)`
<FromGitter> <renich> Ah, OK
<FromGitter> <renich> Thanks @Blacksmoke16
<FromGitter> <Blacksmoke16> np
<coderobe> I use a macro for adding type information to an array, among other things, so `[foo]` turns into `[foo] of Foo | Bar`, however calling the macro with an empty array still results in an `for empty arrays use '[] of ElementType'` compiler error - despite the macro attaching type information. is this intentional?
<FromGitter> <Blacksmoke16> yes, have to have a type on the arra
<FromGitter> <Blacksmoke16> its even more needed on empty arrays because the type cannot be inferred from the contents of the array
<coderobe> the macro attaches the type information
<coderobe> shouldn't the macro run *before* type checking? as they're compile-time..
<FromGitter> <Blacksmoke16> type checking happens at compile time too
<FromGitter> <Blacksmoke16> so type checking *could* be happening *before* the macro runs?
<coderobe> well yes
<FromGitter> <Blacksmoke16> got some example code?
<coderobe> one sec
<coderobe> as it stands, this definitely turns into Array(UInt16 | UInt8 | Nil) at compile time
<coderobe> however, swapping the commented lines, it turns into a compile-time error ;)
<coderobe> to me it seems like this should work with empty arrays as well, as the type is correctly attached, and *then* be type-checked
<coderobe> especially considering that the document describes macros as `Macros are methods that receive AST nodes at compile-time and produce code that is pasted into a program`
<coderobe> eh, remove the typeof() around the macro call in the commented line of my example, that was unintentional
<coderobe> not that it changes anything, though
<coderobe> so the argument is not a valid expression on its own, but the generated code must be valid according to the docs, which it is
<coderobe> as `[] of UInt8 | UInt16` is valid, so is `[1_u8] of UInt8 | UInt16`, both of which would be generated by an `attach_type([])` and `attach_type([1_u8])` respectively, given my example macro
<FromGitter> <Blacksmoke16> hmm
<FromGitter> <Blacksmoke16> the issue is the actual array you are passing it
<FromGitter> <Blacksmoke16> since its empty
return0e has quit [Remote host closed the connection]
return0e has joined #crystal-lang
<coderobe> ...
<FromGitter> <Blacksmoke16> would have to https://play.crystal-lang.org/#/r/5jep
<FromGitter> <Blacksmoke16> so that it wont try to evaluate the empty array before executing the macro
<coderobe> yes, my argument is that it shouldn't evaluate it before running the macro either way
<FromGitter> <Blacksmoke16> :shrug: but it does
<coderobe> i'm here to find out why.
<coderobe> especially considering that other invalid expressions like undefined constant garbage is fine
<coderobe> ie 'my_macro(FOOOO)' does not throw an error when FOOOO is, in fact, not defined, and properly fills in the macro, turning it into valid code
<coderobe> when FOOOO is, e.g., a partial class name
<coderobe> so this just seems like an oversight
<coderobe> because as far as i can tell, any arbitrary input should be fine as macro argument as long as the produced code is not garbage
<FromGitter> <Blacksmoke16> Probably due to order of compile
<FromGitter> <Blacksmoke16> Which I don't know enough about
non-aristotelian has quit [Quit: non-aristotelian]
<FromGitter> <pitosalas> a = [1,2,3]
<FromGitter> <pitosalas> Is there a similar method to drop the first element of an array?
<FromGitter> <Blacksmoke16> @pitosalas ^
DTZUZO has quit [Ping timeout: 246 seconds]
moei has joined #crystal-lang
<FromGitter> <Blacksmoke16> @ljuti ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bef9bb65f5c9250406dbe50]
<FromGitter> <Blacksmoke16> ;)
<FromGitter> <Blacksmoke16> by default error message would be like `'enddate' should be greater than {{date}}` where `{{date}}` is whatever `startdate `was
<FromGitter> <Blacksmoke16> ill leave this question here before i go to bed, what syntax would you rather
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5befb441061f2e6bbb7e486f]
<FromGitter> <Blacksmoke16> or
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5befb4814720c11e0e7c9bae]
akaiiro has quit [Remote host closed the connection]
<FromGitter> <dscottboggs_gitlab> so... how to convert from a Bytes which contains utf-8 codepoints to a String?
<FromGitter> <dscottboggs_gitlab> never mind of course I figure it out as soon as I ask
<shmibs> ラバーダック
<FromGitter> <ljuti> @Blacksmoke16 I’d rather put the annotations on separate lines
rohitpaulk has joined #crystal-lang
ashirase has quit [Ping timeout: 264 seconds]
ashirase has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <vladfaust> @Blacksmoke16 I prefer one line instead
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 264 seconds]
DTZUZO has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <j8r> @renich but we cant `[] of [] of String`, so I prefer `Array(String)` and `Array(Array(String))`
<FromGitter> <j8r> can someone remind me what the point of having this `of` syntax?
<FromGitter> <r00ster91> it's just an alias to e.g. Array(String).new
<FromGitter> <Manu-sh> hi, the last time i had made a question but no one answer me now i want repropose why this expression raise an error (I suspect the reason is that this expression can not be evaluated at compilation time) ? And how can i do this with crystal ? ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5bf004e880e46b4266c64ba0]
<FromGitter> <j8r> I don't think its only an alias @r00ster91 , someone told me it has another feature. If it's really just an alias, we should remove it
<FromGitter> <j8r> this syntax hides the real type behind the variable, when we `typeof` it
<FromGitter> <j8r> @Manu-sh what?! This isn't valid, obviously. You might succeed with macros
<FromGitter> <Manu-sh> isn't obvius
<FromGitter> <j8r> @Manu-sh Types are know at compile time, you can't have this type of runtime operations
<FromGitter> <Manu-sh> thankyou
<FromGitter> <Manu-sh> i will take a look
<FromGitter> <j8r> @Manu-sh you can't use sizeof in a macro
<FromGitter> <j8r> https://carc.in/#/r/5jju
<FromGitter> <Manu-sh> ok
<FromGitter> <Manu-sh> It seems problematic
DTZUZO has quit [Ping timeout: 264 seconds]
<coderobe> what's the canonical way to reinterpret an UInt8 as an Int8?
<coderobe> is unsafe_as the only method?
<coderobe> i specifically don't want it to upcast but rather reinterpret the signed bit
<jokke> to_i8?
<jokke> 255_u8.to_i8 => -1_i8
<jokke> coderobe:
<coderobe> oh, i totally missed that - thanks
<jokke> no problem :)
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <diegogub_gitlab> @Blacksmoke16 one line looks better
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 252 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <swinSpo> Is there a test api i can use
<FromGitter> <swinSpo> like instead of value.should be_truthy
<FromGitter> <swinSpo> something like test.Fail("message"(
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/0.27.0/Spec/Methods.html#fail%28msg%2Cfile%3D__FILE__%2Cline%3D__LINE__%29-instance-method
<FromGitter> <swinSpo> no way
<FromGitter> <swinSpo> LOL
<FromGitter> <swinSpo> damn.. i was checking the api on https://crystal-lang.org/api/0.27.0/Spec.html but didnt see the sub items
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5jm1 is there a way to get the type of a generic in a macro?
akaiiro has joined #crystal-lang
<FromGitter> <Blacksmoke16> ideally id like to do something diff depending on what the type is
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <renich> Good $tod! o/
<FromGitter> <renich> How can I look for duplicates in 2 or more arrays?
<FromGitter> <renich> I have several arrays and need to find the duplicates, and report them.
<FromGitter> <renich> I have this but doesn't quite work: https://play.crystal-lang.org/#/r/5jmy
<FromGitter> <renich> With a `pp` at the end https://play.crystal-lang.org/#/r/5jn0
<FromGitter> <j8r> You could iterate in an array to build another one. If the element is present on the in-build array, report the element
<FromGitter> <renich> @j8r But I need to know in which one of the arrays the duplicates are.
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5jn5
<FromGitter> <Blacksmoke16> ah
<FromGitter> <Blacksmoke16> could you call `.uniq` on each array and compare sizes
<FromGitter> <Blacksmoke16> nvm
<FromGitter> <renich> The thing is that if an element is on array0, it won't appear again on array0.
<FromGitter> <renich> It can be, either, in array1 or array2
<FromGitter> <j8r> you'll need a custom solution
<FromGitter> <renich> @j8r yep
<FromGitter> <j8r> iterate on the first one, found duplicates, iterate on the second, found duplicates etc
<FromGitter> <j8r> the fact that there won't have the same duplicate isn't really a problem
<FromGitter> <renich> @j8r yeah, I thought that I was doing that but I am confused...
rohitpaulk has joined #crystal-lang
<FromGitter> <renich> This one is almost right: https://play.crystal-lang.org/#/r/5jnd but I don't understand why host2 isn't in that picture...
<FromGitter> <renich> OK, I will turn that Hash around and try to get `{ guest => [hostn, hostn] }`
<FromGitter> <renich> Damn... almost there but this is incorrect: https://play.crystal-lang.org/#/r/5jni
<FromGitter> <renich> guest3 should be in host1 and host2. Why isn't it in host2?
<FromGitter> <swinSpo> Hi i would like some feedback and help if possible
<FromGitter> <swinSpo> This code works so far, but I would like to add other types than just String (like Integers or booleans / time ) without making the code too complicated
<FromGitter> <swinSpo> One Issue I am having is that the Provider, the Config and ConfigNamespace seem to have a lot of repetition if I implement other data types (like Integers or booleans)
<FromGitter> <swinSpo> because the config namespace would need to expose the config methods, and that would need to expose the provider methods
<FromGitter> <vlazar> @j8r I've build simple Crystal hello world HTTP server for alpine using command like you've mentioned here, only with local alpine crystal image https://github.com/j8r/dockerfiles/tree/master/crystal-alpine#usage and server does seem to work without added `require "llvm/lib_llvm"` and `require "llvm/enums"` - is this really needed to run any app or is it for some programs only?
<FromGitter> <j8r> @vlazar yeah this is a current limitation https://github.com/crystal-lang/crystal/pull/6945
<FromGitter> <j8r> The PR I've sent with the libunwind linking doesn't seem to work better, unfortunatly
<FromGitter> <ljuti> @renich Did you figure it out?
<FromGitter> <Blacksmoke16> o/ Lauri
<FromGitter> <ljuti> Hello :)
<FromGitter> <vlazar> Thanks Julien, I guess I'll always add these requires for now for safety. I've seen https://github.com/crystal-lang/crystal/pull/4872 and thought that maybe it's only needed if compiling Crystal itself
<FromGitter> <Blacksmoke16> working on v0.5.0 now, will be some more nice changes coming your way
<FromGitter> <Blacksmoke16> `include CrSerializer`, dropping the `::Json`
<FromGitter> <Blacksmoke16> also dropping it in serialization options, `@[CrSerializer::Options(xx)]`
<FromGitter> <ljuti> Nice 👍
<FromGitter> <Blacksmoke16> class annotation is renamed to `ClassOptions`
<FromGitter> <ljuti> I like the shortened syntax, much cleaner
<FromGitter> <Blacksmoke16> indeed, should work out better. not going to worry about yaml so no need for the `::Json`
<FromGitter> <Blacksmoke16> currently working on supporting more serialization options
<FromGitter> <Blacksmoke16> https://jmsyst.com/libs/serializer/master/reference/annotations mostly `since` `until` and `groups`
<FromGitter> <Blacksmoke16> and the callbacks like `preSerialize`/`postSerialize`
<FromGitter> <ljuti> Ooh, that’s nice
<FromGitter> <ljuti> I’ve now done them manually, looking forward to seeing your solution
<FromGitter> <Blacksmoke16> the callbacks?
<FromGitter> <ljuti> Yeah, any modifications that I have wanted to do on the attributes post deserialization
<FromGitter> <Blacksmoke16> will be pretty trivial i think
<FromGitter> <Blacksmoke16> before returning `self` run the given method if it exists
<FromGitter> <ljuti> Uhhuh
<FromGitter> <Blacksmoke16> let me put a quick example together
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bf05fe780e46b4266c8789c]
<FromGitter> <Blacksmoke16> something like that?
<FromGitter> <ljuti> Yeah, that’s nice
<FromGitter> <Blacksmoke16> 👌 nice
<FromGitter> <ljuti> What I’ve done until now is something like this
<FromGitter> <ljuti> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bf0608a1665691e0fbc5cf0]
<FromGitter> <Blacksmoke16> if you're just using default `JSON::Serializable` you could do
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5jo3
<FromGitter> <ljuti> Oh, I didn’t know that
<FromGitter> <Blacksmoke16> thats what i tap into for the validation/deserialization options
<FromGitter> <Blacksmoke16> mhm
<FromGitter> <Blacksmoke16> ``` def after_initialize ⏎ super ⏎ @name = @name.upcase ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5bf0613a4720c11e0e80b7fc]
<FromGitter> <Blacksmoke16> would also work with crserializer
rohitpaulk has quit [Ping timeout: 244 seconds]
<FromGitter> <Blacksmoke16> so hmm, what would be the better solution
<FromGitter> <Blacksmoke16> think im leaning towards the `def after_initialize` would just have to call `super` else validations wouldnt run
akaiiro has quit [Remote host closed the connection]
<FromGitter> <ljuti> Played around a bit in the Playground but couldn’t figure out an elegant solution or syntax
<FromGitter> <Blacksmoke16> for what?
<FromGitter> <Blacksmoke16> groups are done
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5bf06515f9993b4267257f93]
<FromGitter> <Blacksmoke16> :D
<FromGitter> <ljuti> Callbacks
<FromGitter> <ljuti> Tried to use procs for them but they didn’t work out
<FromGitter> <Blacksmoke16> got a link?
<FromGitter> <Blacksmoke16> by default serializable only does like `postDeserialize` and `postSerialize`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/5jpa
<FromGitter> <Blacksmoke16> that work?
rohitpaulk has joined #crystal-lang
lvmbdv has quit [Quit: WeeChat 1.5]
lvmbdv has joined #crystal-lang
lvmbdv has quit [Client Quit]
lvmbdv has joined #crystal-lang
teardown has joined #crystal-lang
<FromGitter> <ljuti> Nice! 👍
<FromGitter> <Blacksmoke16> still not sure how i want to handle the callbacks
<FromGitter> <Blacksmoke16> leaning towards my first idea as its more explicit of what will happen
<FromGitter> <ljuti> OK. Thanks for making my playground bit work. Helped to understand how to use procs like that.
<FromGitter> <Blacksmoke16> np
rohitpaulk has quit [Ping timeout: 252 seconds]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
ua_ has joined #crystal-lang
ua has quit [Ping timeout: 246 seconds]
<FromGitter> <Blacksmoke16> @ljuti do you have any examples of what you would be using the callbacks for?
<FromGitter> <Blacksmoke16> i imagine the common thing is to set calculated fields from the json data?