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
deavmi has quit [Ping timeout: 260 seconds]
deavmi has joined #crystal-lang
<FromGitter> <3n-k1> is this a bug, or part of crystal's type inference? https://play.crystal-lang.org/#/r/9juf ⏎ i feel like since i explicitly typed `f` as taking an argument of type `IFoo`, it should only be able to access things from that module, nothing else
<FromGitter> <Blacksmoke16> it only would accept types that include that module
<FromGitter> <Blacksmoke16> which in this case your method does, and compiler knows that other method exists
<FromGitter> <Blacksmoke16> your type*
<FromGitter> <3n-k1> i can understand that i guess, just feels icky to me lol
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <wyhaines> The way that works is the way that I would expect it to.
<FromGitter> <mwlang> Does build time for Crystal projects grow linearly with lines of code like a C or C++ project would or does build time depend on what was changed since the last compile/build like a Pascal project?
<FromGitter> <Blacksmoke16> i find it depends on what your code is, a lot of unions dont help
<FromGitter> <mwlang> well, that's helpful -- tells me that at least design decisions can factor into build times.
<FromGitter> <mwlang> my project is starting to gain enough of a code base that watching it compile is becoming a thing.
<FromGitter> <mwlang> vs. just "crystal build" <blink> "done"
<FromGitter> <mwlang> so what I'm starting to ask or reflect on is whether decision choices factor into the equation at all or if it's going to be a linear thing.
<FromGitter> <mwlang> I guess with unions, we're talking about time spent resolving all implicit typecasting.
<FromGitter> <Blacksmoke16> yea, compile times have been getting worse as time goes on (apparently due to LLVM version upgrades)
djuber has joined #crystal-lang
<FromGitter> <mwlang> Oh, good. Others are already noticing a big change between 0.29 and 0.35. (that's the other thing I also did..upgraded Crystal across the board)
<FromGitter> <Blacksmoke16> that would do it
f1refly has quit [Ping timeout: 264 seconds]
f1refly has joined #crystal-lang
_whitelogger has joined #crystal-lang
chachasmooth has quit [Ping timeout: 256 seconds]
chachasmooth has joined #crystal-lang
_whitelogger has joined #crystal-lang
_whitelogger has joined #crystal-lang
zorp has joined #crystal-lang
<FromGitter> <3n-k1> compiler says i found a bug. did i really, or am i just doing something illegal? https://play.crystal-lang.org/#/r/9jwa
<FromGitter> <mwlang> hmmm...I broke something...how do I figure out what/where? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f38c231e8eb3939a49570ff]
zorp has quit [Quit: {#`%${%&`+'${`%&NO CARRIER]
<FromGitter> <mwlang> turns out, cannot have same named module as a core module...or so it seems. ⏎ ⏎ ```module Series::Enumerable(T) ⏎ #... ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f38c94aaecae32e8ec72ad8]
andremedeiros has quit [Quit: ZNC 1.8.1 - https://znc.in]
andremedeiros has joined #crystal-lang
sorcus has joined #crystal-lang
_whitelogger has joined #crystal-lang
<oprypin> i'm confused about making bindings to a lib function which returns you a pointer to a struct
<oprypin> first let's assume that the library itself owns the pointer. and i need the ability to modify that struct in-place, i can't just return it as a value
<oprypin> so maybe i make a dummy class that just stores a pointer to that
<oprypin> then what really sucks is that every time i call that library function i'll be getting a different dummy object that has that same pointer
<oprypin> this is in addition to the fact that sometimes i need to clean up the objects when they're owned by me and sometimes i don't
<oprypin> my point isn't that i don't understand some part of this process, but that i don't see any non-messy way to represent this in Crystal
<oprypin> this was my prior solution btw, make a special subclass that disables the finalizer: https://github.com/oprypin/crsfml/blob/73717a9c7ba2/src/graphics/obj.cr#L3910 - this worked acceptably because it's rare in this lib to get an unowned reference. but what if in another lib they were pervasive
zorp has joined #crystal-lang
<FromGitter> <alexherbo2> is crystal lazy when it compiles?
<FromGitter> <alexherbo2> or I have to use `.each` explicitely
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3906ccaecae32e8ec7a7f8]
<FromGitter> <alexherbo2> is my `argv` required to avoid multiple iterations?
<FromGitter> <alexherbo2> why dir only support string?
<FromGitter> <alexherbo2> instead of path
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f390a8822a7e979dbe49f7c]
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f390abb87848e2119ebe8cf]
<FromGitter> <alexherbo2> I tried this
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f390c053e6ff00c2897df35]
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f390c29367ff60c32b7a5ec]
<FromGitter> <alexherbo2> how to specify the block argument type and return value?
<FromGitter> <alexherbo2> can blocks have named parameters?
<FromGitter> <iambudi> > how to specify the block argument type and return value? ⏎ ⏎ @alexherbo2 `def test(&block : Int32, Int32 -> Int32)` after -> is the return type
<FromGitter> <Aaron-JM> Does anyone know the wchar_t conversion for crystal?
_whitelogger has joined #crystal-lang
<yxhuvud> oprypin: you might be able to use a dummy struct instead if you want to avoid the indirection. as it is only a pointer (and some methods interacting with said pointer, it should work fine.
<oprypin> yxhuvud, it works for unowned pointers. with a struct i cant ensure destruction of the unowned pointer
<oprypin> unless there's a way to tell gc about ti
<oprypin> yxhuvud, it works for unowned pointers. with a struct i cant ensure destruction of the **owned** pointer
<FromGitter> <alexherbo2> thanks budi
<yxhuvud> opryppin: Crystal uses a conservative gc. There is no such thing as an unowned pointer - the GC will see the pointer.
<yxhuvud> You might have a problem if you are interacting with a lib that insists on destructing the objects you have itself if it doesn't keep proper pointers around.
<yxhuvud> or ah, what you mean when you say unowned pointer was the opposite of what I meant :D
<yxhuvud> so what you are saying make sense. That is a bit icky indeed.
<yxhuvud> sounds like a very non-nice library to interact with.
<oprypin> yxhuvud, thats almost all libraries though
<oprypin> it is important for a library to not have to expose its structs' exact fields because they're subject to change
<oprypin> if the struct is supposed to remain opaque, it always is passed by pointer. and crystal has no definition of it, so it doesn't know how to allocate it then, only C knows
<oprypin> from that it follows that crystal also doesnt know how to deallocate it
<oprypin> o shit i just found what i was looking for
<oprypin> the lib allows you to "SetAllocatorFunctions"
<oprypin> so i just set it to GC.mallocc and forget about needing to deallo?
* FromGitter * dscottboggs_gitlab just looked up what "conservative" GC means
<FromGitter> <dscottboggs_gitlab> oh no...
<oprypin> yea https://stackoverflow.com/a/7629459 looks good
<FromGitter> <dscottboggs_gitlab> yeah but not how I thought it worked. I.E. if you call `LibC.malloc` it will still get tracked by the GC.
<oprypin> dscottboggs_gitlab, im not sure about that
<oprypin> that would break so many things
<oprypin> like if theres a C library that offsets all its stored pointers by -4
<oprypin> the gc would just wreck everything
<yxhuvud> yeah, and if you are not telling the lib you are not using stuff you might end up never releasing it
<oprypin> dscottboggs_gitlab, it frees only memory that it was informed about
<FromGitter> <dscottboggs_gitlab> oh ok
<oprypin> and i also think that maybe it doesnt scan the entire heap for things that could be referring to it, but only the crystal-owned parts of it. but could be wrong
<FromGitter> <dscottboggs_gitlab> thanks for clarifying
HumanG33k has joined #crystal-lang
f1refly has quit [Ping timeout: 244 seconds]
f1refly has joined #crystal-lang
<FromGitter> <alexherbo2> @dscottboggs_gitlab I may have missed something, but how does your example work?
<FromGitter> <alexherbo2> ```snippets = Hash(Path, Hash(String, Snippet)).new do ⏎ Hash(String, Snippet).new ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5f3937e7ce98da26eccebefd]
<FromGitter> <alexherbo2> shouldn't be:
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f39380aa1190a2e95f6ee5f]
<FromGitter> <alexherbo2> ?
<FromGitter> <dscottboggs_gitlab> uhh...
<FromGitter> <dscottboggs_gitlab> yes
<FromGitter> <dscottboggs_gitlab> my mistake
<FromGitter> <alexherbo2> I have something working :p
<FromGitter> <dscottboggs_gitlab> sweet!
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f3938791226fc2133593b92]
<FromGitter> <alexherbo2> what do you think?
<FromGitter> <alexherbo2> I'm not very happy with the `Snippet`, `Scope`, `Snippets` declaration
<FromGitter> <alexherbo2> we do not see immediately the hierarchy structure
<FromGitter> <alexherbo2> (I'm open to change the snippets structure too)
<FromGitter> <dscottboggs_gitlab> looks pretty reasonable to me TBH
<FromGitter> <alexherbo2> my end goal is to generate a json easy to manipulate for externals editors with `jq` or something
<FromGitter> <dscottboggs_gitlab> If it works, anything else is down to aesthetics and maintainability.
<FromGitter> <wyhaines> @alexherbo2 Better than jq: https://github.com/Blacksmoke16/oq
<FromGitter> <alexherbo2> I'm in a rush :p
<FromGitter> <Blacksmoke16> 😉
<FromGitter> <dscottboggs_gitlab> why the rush?
<FromGitter> <alexherbo2> I started to learn rails a week at school, I had no snippets for my editor
<FromGitter> <dscottboggs_gitlab> oh i see
<FromGitter> <alexherbo2> I don't remember anything
<FromGitter> <alexherbo2> so I wanted snippets to ease my learning
<FromGitter> <alexherbo2> I'm a snail
<FromGitter> <alexherbo2> by @Blacksmoke16 <3
<FromGitter> <alexherbo2> thanks @wyhaines !
* FromGitter * dscottboggs_gitlab just expected the result of `.as_bool?` to be truthy ⏎ ⏎ Fucks sake
<FromGitter> <dscottboggs_gitlab> looks like it's time for a point-release of Jenerator lol
<FromGitter> <alexherbo2> is oq like what crystal is for ruby?
<FromGitter> <alexherbo2> pretty much same syntax of differ?
<FromGitter> <alexherbo2> oh
<FromGitter> <dscottboggs_gitlab> not really
<FromGitter> <alexherbo2> it uses `jq` internally no?
<FromGitter> <dscottboggs_gitlab> yes
<FromGitter> <dscottboggs_gitlab> oq just converts between a bunch of data serialization formats
<FromGitter> <alexherbo2> it's jq with an intermediate layer for handing different input/output format?
<FromGitter> <alexherbo2> oq -> jq -> oq
<FromGitter> <dscottboggs_gitlab> yeah it just forwards the CLI args on to `jq` for processsing.
<FromGitter> <alexherbo2> it's nice
<FromGitter> <dscottboggs_gitlab> indeed!
<FromGitter> <alexherbo2> by looking at the doc, there is only `-i` for input and `-o` for output to remember; all between step is forwarded to jq
<FromGitter> <alexherbo2> have you discussed with jq author to have it built-in jq?
<FromGitter> <Blacksmoke16> thats the idea yea, are also some other options for format specific stuff mainly XML
<FromGitter> <Blacksmoke16> i thought about trying to write c bindings but 😬 idk what im doing and just calling the process is a lot easier ha
<FromGitter> <alexherbo2> 👍
<FromGitter> <dscottboggs_gitlab> also I've heard the `jq` codebase is really weird and hard to work with
<FromGitter> <alexherbo2> :(
<FromGitter> <alexherbo2> jq is not well-written?
<FromGitter> <dscottboggs_gitlab> well...it works....and it's fast... so in that sense it is
<FromGitter> <dscottboggs_gitlab> haven't personally looked at the codebase, just going by what I heard
<FromGitter> <alexherbo2> can `alias` be written as `struct` or that a different thing?
<FromGitter> <alexherbo2> I would like to declare: ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5f393c6ab7818b3998febeff]
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f393c7060892e0c6975eae8]
<FromGitter> <alexherbo2> as a deep structure
<FromGitter> <alexherbo2> so that when you look at it you immediately see what Snippets should look like
<FromGitter> <dscottboggs_gitlab> you could make Scope and Snippets inherit from the types you're aliasing them as instead
<FromGitter> <dscottboggs_gitlab> `class Scope < Hash(String, Snippet)`
<FromGitter> <dscottboggs_gitlab> not sure if you can put something inside a class then put that type into the inheritance, but it's worth a shot
<oprypin> sadly, this crashes:
<oprypin> `LibImGui.igSetAllocatorFunctions(->(size, data) { GC.malloc(size + 4) + 4 }, ->(ptr, data) { }, nil)`
<oprypin> `LibImGui.igSetAllocatorFunctions(->(size, data) { GC.malloc(size) }, ->(ptr, data) { }, nil)`
<oprypin> guess i'll have to make do with
<oprypin> >> class A; end; class B; end; p! A.allocate.as(Int32*).value, B.allocate.as(Int32*).value
<DeBot> oprypin: (A.allocate.as(::Pointer(Int32))).value # => 158 - more at https://carc.in/#/r/9jxt
<oprypin> if u know what i was going for 😉
<oprypin> wtf does this really work
<oprypin> `LibImGui.igSetAllocatorFunctions(->(size, data) { p = GC.malloc(size + 12); p.as(Void**).value = p; p + 8 }, ->(ptr, data) { }, nil)`
<oprypin> ah shit no just the +8 is what makes it work. guess the pointer has to be aligned
<oprypin> this is next level
<oprypin> now... any way to get a hold of a typeid?
<oprypin> the only way I've seen is `A.allocate.as(Int32*).value`
<oprypin> yxhuvud, i think i have solved the puzzle
<FromGitter> <dscottboggs_gitlab> holy crap oprypin lol
<oprypin> https://carc.in/#/r/9jy7 would do it along with `LibImGui.igSetAllocatorFunctions(->(size, data) { GC.malloc(size + sizeof(Void*)) + sizeof(Void*) }, ->(ptr, data) { }, nil)`
<oprypin> >> class A; end; class B; end; p! A.crystal_type_id, B.crystal_type_id
<DeBot> oprypin: A.crystal_type_id # => 797 - more at https://carc.in/#/r/9jy9
<oprypin> why is it different lol
<oprypin> yes crystal_type_id is not usable, have to keep using this trick
<oprypin> see here, i casted it as A but it shows up as B because the typeid dictates it
<FromGitter> <alexherbo2> does `reject!` and in-place method break the lazy chain?
<oprypin> alexherbo2, i think there's little to no laziness to speak of in the first place
<FromGitter> <dscottboggs_gitlab> `Iterator` does not implement `#reject!` https://crystal-lang.org/api/0.35.1/Iterator.html @alexherbo2
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 240 seconds]
<FromGitter> <alexherbo2> is there a method to get the subpath relative to a root?
<FromGitter> <alexherbo2> example: `/home/alex/snippets` is my root and `/home/alex/snippets/ruby/rails/routes` is my path, I want `ruby/rails/routes`
<FromGitter> <alexherbo2> currently I do a `Dir.cd` to each root, and a relative `walk(Path["."])`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/9jyp like this/
<FromGitter> <alexherbo2> I tried it before asking but got
<FromGitter> <alexherbo2> ```Error: undefined method 'relative_to' for Path```
<FromGitter> <Blacksmoke16> :thinking: got an example?
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f394f0be8eb3939a496ae43]
<FromGitter> <Blacksmoke16> a reduced example*
r0bby has quit [Ping timeout: 272 seconds]
<FromGitter> <alexherbo2> it's a L42
<FromGitter> <alexherbo2> at*
<oprypin> alexherbo2, https://crystal-lang.org/api/0.35.1/Path.html#relative_to?(base:Path):Path?-instance-method
r0bby has joined #crystal-lang
<FromGitter> <Blacksmoke16> what version you on?
<FromGitter> <Blacksmoke16> idt it was added until `0.35.0`
<oprypin> ye
<FromGitter> <alexherbo2> 1) 34
<FromGitter> <Blacksmoke16> that would do it
<FromGitter> <alexherbo2> 🤦
<FromGitter> <dscottboggs_gitlab> 😂
<FromGitter> <alexherbo2> not sure how to update my crystal on nix XD
<FromGitter> <dscottboggs_gitlab> you mean https://nixos.org/ ?
<FromGitter> <Blacksmoke16> i think its a community supported package
<FromGitter> <dscottboggs_gitlab> looks like you might wanna reach out to one of these guys https://nixos.org/nixos/packages.html?attr=crystal&channel=nixpkgs-unstable&query=crystal
<FromGitter> <dscottboggs_gitlab> @alexherbo2 you could also use asdf (https://nixos.org/nixos/packages.html?attr=asdf&channel=nixpkgs-unstable&query=asdf)
<FromGitter> <Blacksmoke16> or snap
<FromGitter> <Blacksmoke16> or whatever package manager your os uses (assuming your not on nixos)
<FromGitter> <Blacksmoke16> or build from source
<FromGitter> <dscottboggs_gitlab> could you build 0.35 with 0.27?
<FromGitter> <dscottboggs_gitlab> or would you have to do each of the 8 versions in order? 😬
<FromGitter> <Blacksmoke16> he said hes on `0.34.0`
<FromGitter> <dscottboggs_gitlab> oh ok
<FromGitter> <dscottboggs_gitlab> I see that now
<FromGitter> <alexherbo2> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f39549087848e2119ec9b66]
<oprypin> @alexherbo2 u are building crystal master with crystal 0.34
<oprypin> that is not supported
<oprypin> u can build crystal 0.35 with crystal 0.34
<oprypin> how can I replace the last occurrence of a regex?
<oprypin> nvm did .rindex and .insert
<oprypin> >> "Foo".rindex(/\b/)
<DeBot> oprypin: # => 0 - https://carc.in/#/r/9jyx
<oprypin> sigh
<oprypin> ruby says 3, ok bug report ready
<FromGitter> <alexherbo2> the static build misses pcre and libevent
<oprypin> oh
<FromGitter> <j8r> right @alexherbo2 , you have to get the `.a` somewhere else
<FromGitter> <alexherbo2> do you think this script can be of some use as contrib/ ?
zorp has quit [Ping timeout: 246 seconds]
<FromGitter> <acoolstraw> hey
<FromGitter> <acoolstraw> I'm still having problems with generating documentation for crystal-gobject, could anyone help? https://github.com/jhass/crystal-gobject/issues/74
alexherbo2 has joined #crystal-lang
duane has joined #crystal-lang