jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<oprypin> dang, the trail of bugs from parsing / as a regex seems to just never end
renich has quit [Ping timeout: 240 seconds]
renich has joined #crystal-lang
renich has quit [Ping timeout: 265 seconds]
renich has joined #crystal-lang
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
renich has quit [Ping timeout: 258 seconds]
renich has joined #crystal-lang
chachasmooth has quit [Ping timeout: 240 seconds]
f1refly has joined #crystal-lang
chachasmooth has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 260 seconds]
renich has quit [Quit: Leaving.]
r0bby has quit [Ping timeout: 272 seconds]
r0bby has joined #crystal-lang
<FromGitter> <naqvis> @RespiteSage https://carc.in/#/r/9meo
<FromGitter> <naqvis> better to be explicit
<FromGitter> <naqvis> or ⏎ https://carc.in/#/r/9met
r0bby has quit [Ping timeout: 256 seconds]
r0bby has joined #crystal-lang
_whitelogger has joined #crystal-lang
<oprypin> @naqvis: nice!!
<FromGitter> <naqvis> Thanks oprypin
tsujp has joined #crystal-lang
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <davidepaolotua_gitlab> Hi everyone, just to be sure I didn’t miss it anywhere… In Crystal, it’s currently not possible to have intersection types, am I right?
<FromGitter> <naqvis> Hi, got an example?
<jhass> you're thinking like java interfaces or rust traits?
<FromGitter> <davidepaolotua_gitlab> Yup, basically calling some method like ⏎ ⏎ ```def do_something(objects : Array(Displayable & Moveable) )``` [https://gitter.im/crystal-lang/crystal?at=5f4f74429566774dfe4bf25c]
<jhass> Crystal solves this through automatic union types and duck typing
<jhass> just don't type restrict your method argument and assume the methods are there on what you're passed
<FromGitter> <davidepaolotua_gitlab> yup, but that would ensure that objects are either Displayable OR Moveable
<FromGitter> <davidepaolotua_gitlab> if I want them to be Displayable AND Moveable, union types are not what I should look for, or am I missing anything?
<jhass> Give it a try, turns out most of the time you don't care, just that you can trat them like that :)
<jhass> *treat
<FromGitter> <davidepaolotua_gitlab> Ok then :) I’ll give it a try
HumanG33k has quit [Quit: Leaving]
HumanG33k has joined #crystal-lang
Jenz has joined #crystal-lang
Jenz has quit [Quit: leaving]
woodruffw has quit [Ping timeout: 256 seconds]
<FromGitter> <RespiteSage> @naqvis Interesting solution. The working code I have uses a ternary operator to map to the element or Nil, but I like the version that rejects `Nop` better.
<FromGitter> <naqvis> `Nop` one looks like a magical one, as one need to know why its Nop but not Nil. I prefer to be explicit in my code as it makes easy to read and reason about.
<FromGitter> <naqvis> also don't know the reason behind this inconsistency of `map` in normal code and macroland. normal code it should have returned `nil` instead of an empty node `Nop`
<FromGitter> <Blacksmoke16> oo i think i might actually know how to fix this one
<FromGitter> <Blacksmoke16> whats the issue? `.each_with_index` returns `Nop` instead of `Nil` type?
<FromGitter> <RespiteSage> Yeah, that's fair. Right now the code is a PoC for myself, but if I ever use it for anything, I'll need to make it explicit. I'll leave my ternary for now.
<FromGitter> <RespiteSage> @Blacksmoke16 Yeah, I think that's it. Lemme write a quick carc example.
<FromGitter> <Blacksmoke16> ❤️
<FromGitter> <naqvis> ```code paste, see link``` ⏎ ⏎ but in macroland, output is `Nop` instead of `nil` [https://gitter.im/crystal-lang/crystal?at=5f4fae14ddc2d041c0e3aa22]
woodruffw has joined #crystal-lang
<FromGitter> <RespiteSage> https://carc.in/#/r/9mjf
<FromGitter> <RespiteSage> Not as succinct, but pretty explicit.
<FromGitter> <naqvis> 💯
<FromGitter> <RespiteSage> `#map` does the same thing: https://carc.in/#/r/9mjg
<FromGitter> <Blacksmoke16> oh i see
<FromGitter> <RespiteSage> The `#map` example outside of a macro: https://carc.in/#/r/9mjj (just for convenience).
<FromGitter> <Blacksmoke16> thanks
<FromGitter> <mtsmmp_gitlab> hey guys
<FromGitter> <mtsmmp_gitlab> how to convert time to iso8601
<FromGitter> <Blacksmoke16> prob just use https://crystal-lang.org/api/master/Time.html#to_rfc3339(*,fraction_digits:Int=0)-instance-method
<FromGitter> <mtsmmp_gitlab> thanks bro
zorp has joined #crystal-lang
alexherbo2 has joined #crystal-lang
deavmi has quit [Quit: Eish! Load shedding.]
ua has quit [Ping timeout: 256 seconds]
ua has joined #crystal-lang
renich has joined #crystal-lang
deavmi has joined #crystal-lang
renich has quit [Ping timeout: 240 seconds]
renich has joined #crystal-lang
riffraff169 has joined #crystal-lang
<riffraff169> hello, im trying to write a class....i need to initialize the class with an array of arrays (specifically: [ ["a","b"] , ["c","d"], ... ]
<riffraff169> i keep getting either: Error: wrong number of type vars for Array(T) (given 2, expected 1)
<riffraff169> or: Error: can't infer the type of instance variable '@tokens' of Parser
<FromGitter> <Blacksmoke16> can you share the code?
<riffraff169> def initialize(tokens : Array)
<riffraff169> @tokens = tokens
<riffraff169> @tp = 0
<riffraff169> end
<FromGitter> <Blacksmoke16> prob would be like `def initialize(@tokens : Array(Array(String))); end`
<riffraff169> ah let me try that
<FromGitter> <Blacksmoke16> need to be more specific than just `Array`
<riffraff169> still wrong number of type vars for Array(T):
<riffraff169> 3 | def initialize(tokens : Array(Array(String,String)))
<riffraff169> Error: wrong number of type vars for Array(T) (given 2, expected 1)
<FromGitter> <Blacksmoke16> why are you doing `String, String`?
<FromGitter> <Blacksmoke16> only need the one
<riffraff169> sorry, still learning crystal (from ruby), so trying to figure it out
<FromGitter> <Blacksmoke16> np
<riffraff169> i dont think it matches, here is error now:
<riffraff169> Error: no overload matches 'Parser.new' with type (Array(Array(Int32 | String) | Array(String)) | Array(Array(Int32 | String)))
<riffraff169> Overloads are:
<riffraff169> - Parser.new(tokens : Array(Array(String)))
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/cr can you make an example here?
<riffraff169> lets see
<riffraff169> ive been looking through the docs, but all examples are single dimension (Int32, String, etc)....not arrays of mixed, so not quite getting my syntax right
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9mmc
<FromGitter> <Blacksmoke16> so two things going on
<FromGitter> <Blacksmoke16> first the type of tokens is actually `Array(Array(String | Int32))`, since the inner arrays can contain either strings or int32s
<riffraff169> ok, i see that
<FromGitter> <Blacksmoke16> next you have to help the compiler a bit by adding a `of Array(String | Int32)`
<FromGitter> <Blacksmoke16> otherwise the inner arrays that do not contain int32s would not be allowed to contain them
<FromGitter> <Blacksmoke16> so that basically says, each inner array can contain either strings or int32s, even if they don't currently
<riffraff169> so it isnt inferring that @tokens should be same type as tokens? even though i say tokens = ... and @tokens = tokens?
<FromGitter> <Blacksmoke16> thats the thing, they aren't the same w/o the `of Array(String | Int32)`
<riffraff169> hmm
<FromGitter> <Blacksmoke16> like, look at the error message: It says the type is `Array(Array(Int32 | String) | Array(String)) | Array(Array(Int32 | String))`
<riffraff169> hmm, let me test something, thanks
<FromGitter> <Blacksmoke16> main problem being the inner arrays that contain only strings, the type of the array would be like `Array(Array(String |Int32) | Array(String))`
<FromGitter> <Blacksmoke16> meaning not all inner arrays are allowed to contain int32s
<riffraff169> yeah, right now all inner arrays are [String,String] or [String,Int32] ([String,String|Int32]), and given my current requirements im not sure that will ever change
<riffraff169> so where would the `of Array(String|Int32)` be....should i declare @tokens with that type before trying to assign tokens to it?
<riffraff169> im assuming tokens would be copied to @tokens (value instead of reference), which is fine
<FromGitter> <Blacksmoke16> its at the very end of line 1, if you scroll all the way to the right
<FromGitter> <Blacksmoke16> arrays are passed by reference
<riffraff169> ah, hmmm....
<riffraff169> well, thats fine, at this point it is immutable anyway, so
<riffraff169> well, in this small example i statically assigned tokens, but tokens is actually generated by another class, and that is the result....so i cant but `of...` at the end of tokens because it is already set somewhere else
<riffraff169> my first class has this: tokens = [] of Array(String|Int32)
<riffraff169> then that var has values added to it `tokens += [token]`
<riffraff169> then tokens is passed to parser
<FromGitter> <Blacksmoke16> prob should just use `<<`
<FromGitter> <Blacksmoke16> but is that not working?
<riffraff169> well gee, something somewhere, got it to working with this:
<riffraff169> def initialize(tokens : Array(Array(String|Int32)))
<FromGitter> <Blacksmoke16> 👍 makes sense i think
<FromGitter> <Blacksmoke16> also you can add the `@` to the initializer arg, like `@tokens : `
<FromGitter> <Blacksmoke16> so you dont have to do `@tokens = tokens`
deavmi has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<riffraff169> probably because i had String,String....i think i was thinking (for some reason) like a tuple, where i had to declare type of every index...but that wasnt making sense to me because an array is inherently variable...
<riffraff169> thats working, thanks for the help
<riffraff169> im from a c background, then ruby, so the cross between static and kind of dynamic is kind of weird
<FromGitter> <Blacksmoke16> Tuples are also a thing in crystal land
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/Tuple.html
<riffraff169> im sure people have done it, but when i tried to load and access yaml it gave me errors because of not knowing the types (YAML::Any)...so basically yaml cant really be freeform, must have a schema
<FromGitter> <Blacksmoke16> it can but you have to be a bit more explicit
<FromGitter> <Blacksmoke16> i.e. instead of like `yaml_data["name"]` you have to do like `yaml_data["name"].as_s` to tell it it should be a string
<riffraff169> yeah, i was mixing the two...can a tuple have a mixed type? (String,String|Int32), or must they all be the same
<FromGitter> <Blacksmoke16> otherwise, yea using a schema + https://crystal-lang.org/api/YAML/Serializable.html is usually the better option
<FromGitter> <Blacksmoke16> probably?
<riffraff169> yeah, but that means you have to know ahead of time what type it is, which moves the data into the code, sort of
<riffraff169> but im not working with yaml right now so im not investigating that further
<FromGitter> <Blacksmoke16> if you're working with data it most likely has some predefined structure
<FromGitter> <Blacksmoke16> so yes that means your code would know about the properties of that data, but it allows you to work with it in an easier/more type safe way
<riffraff169> thanks for the help, i like crystal so far, i like the static binaries and no gc...well, not static binaries as such (dynamic doesnt bother me), but actually binaries rather than interpreted
<FromGitter> <Blacksmoke16> however if the data is totally dynamic you ofc cant use that approach
<FromGitter> <Blacksmoke16> crystal has a GC btw...
<FromGitter> <Blacksmoke16> and you can get static binaries
<FromGitter> <Blacksmoke16> make*
<riffraff169> i wonder what crystals gc is, perf wise, compared to ruby, python, go, or java...mainly go or java....ive seen too many issues with java stop the world gcs
<FromGitter> <Blacksmoke16> it uses https://github.com/ivmai/bdwgc
<FromGitter> <Blacksmoke16> related: https://github.com/crystal-lang/crystal/issues/5271
<riffraff169> i was trying to do something with yaml some months ago, and the yaml i had was kind of freeform....basically a list of multiple types, so had to determine the type of that section before you could do anything with it...
<riffraff169> ah that one
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/YAML/Serializable.html#use_yaml_discriminator(field,mapping)-macro might be helpful as well
<riffraff169> yeah, thats kind of what i would have done...had code that checked if a field was present, and if so, then access relevant data through one method, if not, or had different fields, then do other things
<riffraff169> basically unstructured data i guess, but thats not always great
<riffraff169> thanks for the help, im going to continue with my program...
<FromGitter> <Blacksmoke16> 👍
<riffraff169> trying to write a compiler for 6502 assembly that can be run on c64....probably not necessary (there are others), but im learning crystal, and it is very nostalgic doing c64 programming again
<FromGitter> <Blacksmoke16> :S sounds like a plan
maxpowa has quit [*.net *.split]
daemonwrangler has quit [*.net *.split]
maxpowa has joined #crystal-lang
daemonwrangler has joined #crystal-lang
<FromGitter> <wyhaines> I was a freaking wizard with 6502 assembler. Those were the days!
alexherbo2 has quit [Ping timeout: 256 seconds]
<riffraff169> yeah i programmed the c64 back in the 80s....so fun stuff...people are still making games and demos for it