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
<FromGitter> <Daniel-Worrall> Oh boy, reading the compiler gives me a head sore
teardown has quit [Ping timeout: 240 seconds]
teardown has joined #crystal-lang
<FromGitter> <watzon> HTTP::Client isn't currently capable of opening a persistent connection right? Does anyone know if someone has created a shard that does?
<FromGitter> <watzon> I'd love something like Python's `asyncio.open_connection` which gives you a readable and writable stream.
deavmi_ has quit [Read error: Connection reset by peer]
deavmi has joined #crystal-lang
<FromGitter> <Blacksmoke16> persistent in what regard? like just an `io` obj?
<FromGitter> <watzon> Basically yes
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/HTTP/Client.html#new(io:IO,host=%22%22,port=80)-class-method with the block version?
<FromGitter> <pebauer68> A small test environment for crystal functions, i hope it is useful ⏎ https://forum.crystal-lang.org/t/test-environment-for-crystal-functions/2821
<FromGitter> <watzon> I guess what I really need is just a TCPSocket. I actually need it to be protocol independent anyway.
<FromGitter> <watzon> Pretty cool @pebauer68
<FromGitter> <watzon> Yeah that's how I figured out it's what I need lol
<FromGitter> <pebauer68> > Pretty cool @pebauer68 ⏎ Thank you, what functions should i add next ?
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
<FromGitter> <HertzDevil> random thought: https://carc.in/#/r/a6ji
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
<oprypin> oof
<FromGitter> <watzon> Do any of the built in list types handle concurrency well? Or should I implement something myself?
<oprypin> watzon, dont handle. mutex and channels handle it
<FromGitter> <watzon> That's what I mean though. Is there a list type that wraps operations in a mutex already?
<oprypin> no
<FromGitter> <watzon> @Blacksmoke16 do you know if it's possible to get the return type of a `Call`?
deavmi has quit [Quit: Eish! Load shedding.]
deavmi has joined #crystal-lang
_ht has joined #crystal-lang
<hightower2> In macros, how/where do I access the documentation section of a `Def` (of a method)
<hightower2> hm, `doc`, but I'm having trouble accessing it... playing more
<hightower2> There is Node#doc, but not Def#doc
<FromGitter> <erdnaxeli:cervoi.se> where did you see Node#doc?
<hightower2> grepping through crystal source
<FromGitter> <erdnaxeli:cervoi.se> ok. It does not seems to be documented.
<FromGitter> <erdnaxeli:cervoi.se> But Def inherites from ASTNode, so it should have it too
<hightower2> Well, yes but if I do: {% m = @type.methods.last %}; p {{ m.doc }}, I get: Error: undefined macro method 'Def#doc'
<hightower2> Is there a way to remove certain ivars from showing in the default output of #inspect ?
<FromGitter> <naqvis> override `to_s(IO)`
<FromGitter> <Sija> @naqvis more like `inspect(io : IO)`
<FromGitter> <naqvis> Thanks @Sija
f1reflyylmao has quit [Ping timeout: 260 seconds]
<FromGitter> <HertzDevil> no you can't get the docs, because it isn't defined in `src/compiler/crystal/macros/methods.cr`
<FromGitter> <naqvis> `alias` isn't allowed with generic types? ⏎ https://carc.in/#/r/a6lk
f1refly has joined #crystal-lang
hightower2 has quit [Ping timeout: 264 seconds]
<FromGitter> <nothratal> Is someone using an rpm based distro? On opensuse I get an error from the repository
<FromGitter> <nothratal> I get an ```Access 'https://dist.crystal-lang.org/rpm/media.1/media' denied. ``` if I run any zypper commands
<FromGitter> <nothratal> zypper is opensuse's software installation tool
<straight-shoota> I have no idea how rpm works, but maybe the package repository on dist.crystal-lang.org is broken?
<straight-shoota> you can use https://bintray.com/crystal/rpm
f1reflyylmao has joined #crystal-lang
f1refly has quit [Quit: bye fags]
<FromGitter> <nothratal> maybe not fully functional but definitely not broken. I was able to install crystal.
<straight-shoota> so it worked but now it doesn't?
<FromGitter> <Blacksmoke16> @watzon idt
<FromGitter> <Blacksmoke16> would need a reference to the `Def`
f1reflyylmao has quit [Quit: bye fags]
f1refly has joined #crystal-lang
hightower2 has joined #crystal-lang
<hightower2> Hey how does one generally approach the design of a public API where structs are better for performance, but it is inconvenient to use them since it forces the user to recreate the whole struct to change just one field?
<hightower2> is there some elegant notation for this, or?
<FromGitter> <Blacksmoke16> if the object isnt immutable dont use structs
<hightower2> well it's hard to say... or sometimes a thing is rarely changed, but those changes require it to be a class
<raz> i say: use class, worry about performance later (aka: never)
<hightower2> wise, thanks
* raz says that with impunity while himself spending the second day on a premature optimization :p
<raz> sometimes it's just too tempting...
<hightower2> especially after you run a couple benchmarks :)
<raz> yup, those precious nanoseconds! 😬
<hightower2> watzon: for most basic types there is the Atomic(T)
<FromGitter> <naqvis> https://carc.in/#/r/a6oi ⏎ why this strange behavior?
<FromGitter> <naqvis> Thanks, but same behavior is seen if you try to create new array and assign that to missing keys
<FromGitter> <Blacksmoke16> https://carc.in/#/r/a6oj
<FromGitter> <naqvis> why hash is printed as blank?
<FromGitter> <Blacksmoke16> works fine
<FromGitter> <Blacksmoke16> because those keys dont exist and they're not being added to the hash, they're being added to that array
<FromGitter> <Blacksmoke16> https://carc.in/#/r/a6ok
<FromGitter> <naqvis> aah, but how come hash is ignoring the keys?
<FromGitter> <Blacksmoke16> > I’m pretty sure what’s happening is you are using https://crystal-lang.org/api/Hash.html#new(default_value:V,initial_capacity=nil)-class-method that overload. This is creates an array that is to be used as the value of the hash when a key is not known. Since arrays are a reference type, the same one is used in each case there is an unknown key. As such all the values end up in this array, and nothing
<FromGitter> ... in the actual hash.
<FromGitter> <Blacksmoke16> because you're not using the overload that allows you to set the value of the missing key
<FromGitter> <naqvis> thanks @Blacksmoke16
<FromGitter> <Blacksmoke16> https://carc.in/#/r/a6on
<FromGitter> <Blacksmoke16> yea so they just get added to `/dev/null` essentially
<hightower2> Is there a macro or something expanding to file:method:line_nr ?
<FromGitter> <Daniel-Worrall> There are constants for that
<hightower2> goodness, thanks
<FromGitter> <Daniel-Worrall> method would probably be a macro
<FromGitter> <Blacksmoke16> theres also methods in macro land for it
<hightower2> in macros, if I have {{*args}} which contains complete method arguments including type, default value etc., how do I get from there to argument names only?
<hightower2> like, right now, a method I generate ends up being: def some(x = 1) call_some_other(x = 1).... whereas I want the "= 1" in the second case to be removed
<FromGitter> <Blacksmoke16> got an example?
<hightower2> si barone, https://carc.in/#/r/a6or
Xeago has quit [Ping timeout: 268 seconds]
<hightower2> actually, I'm not sure if for this purpose (method aliasing), I even care about exact arguments, or I can just define a method with literal (*args, **args)
Xeago has joined #crystal-lang
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/Object.html#delegate(*methods,toobject)-macro
<FromGitter> <Blacksmoke16> and fwiw aliasing methods is frowned upon a bit in crystal land
<hightower2> yes, yes, of course
<hightower2> I wanted to copy parts of an existing API
<hightower2> which has many aliases... some even for a good/justified reason
<hightower2> can't use delegate here
<hightower2> got away with just (*args)
<FromGitter> <Blacksmoke16> okey dokey
woodruffw has quit [Ping timeout: 240 seconds]
woodruffw has joined #crystal-lang
<FromGitter> <Daniel-Worrall> Can I restrict a method to a tuple of any size?
<FromGitter> <Blacksmoke16> `arg : Tuple`?
<FromGitter> <Daniel-Worrall> Can I then type restrict the contents?
<FromGitter> <Daniel-Worrall> so they're all T?
<FromGitter> <Daniel-Worrall> `Error: can't declare variable of generic non-instantiated type Tuple(T)`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a6pd looks like you can use 2 overloads for it?
<FromGitter> <Blacksmoke16> otherwise no, idt that feature exists
<FromGitter> <Daniel-Worrall> I could totally leave it untyped... but it's for the compiler
<FromGitter> <Daniel-Worrall> Seems I can't do it with a property
<FromGitter> <Blacksmoke16> makes sense
<FromGitter> <Blacksmoke16> can you store it as an array, if its dynamic size that would make more sense no?
<FromGitter> <jrei:matrix.org> you can do like this https://play.crystal-lang.org/#/r/a6pn
<raz> blacksmoke: https://t.ly/lz1W athena afterburner :p
<FromGitter> <Blacksmoke16> @jrei:matrix.org smart move using free var as a tuple and splatting it
<FromGitter> <Blacksmoke16> raz: oh boy
<FromGitter> <jrei:matrix.org> @watzon: How Crystalizer is not what it says it is?
<FromGitter> <jrei:matrix.org> Annotations are lacking sure, I did not implement everything
<FromGitter> <jrei:matrix.org> Your example is what Crystalizer can do, or should be able to do
<FromGitter> <watzon> No it's just not what I thought it was. I was thinking of another project.
<FromGitter> <jrei:matrix.org> hum, what do you mean?
<FromGitter> <jrei:matrix.org> like bindata?
<FromGitter> <watzon> Exactly. That's the project I was thinking of, but I remembered crystalizer instead
<FromGitter> <jrei:matrix.org> ok. Using one or the other is a matter of state
<FromGitter> <jrei:matrix.org> Crystalizer is simpler, but lacks for now advanced annotations
<FromGitter> <jrei:matrix.org> I guess bindata was done before annotations were a real thing
<FromGitter> <jrei:matrix.org> note also that is has more runtime
teardown has quit [Ping timeout: 240 seconds]
<FromGitter> <watzon> Yeah neither is really what I needed for my use case anyway
<FromGitter> <jrei:matrix.org> what do have to do?
teardown has joined #crystal-lang
<FromGitter> <watzon> A whole lot of code gen. I'm taking a .tl file that looks like this https://github.com/LonamiWebs/Telethon/blob/master/telethon_generator/data/api.tl and using it to generate a bunch of classes which each need a serialize and deserialize method, or in my case `to_slice` and `from_reader`. Since I have to do a ton of code gen anyway it doesn't make a ton of sense to add extra overhead in the form of a convenience
<FromGitter> ... library when `IO::ByteFormat` works just fine.
<FromGitter> <watzon> With what I've got right now I basically end up with this ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5feb8c24aa6bb528c37bd3c4]
<FromGitter> <watzon> And then the reader is just a convenience class that makes it a bit easier to read bytes into specific values
<hightower2> Here's a nice logging helper macro, https://carc.in/#/r/a6q6
<FromGitter> <jrei:matrix.org> @watzon: looks like what you do is exactly what Crystalizer do under the ground
<FromGitter> <jrei:matrix.org> There is minimal overhead, maybe a bit more due to a StaticArray
<FromGitter> <Blacksmoke16> hightower2: fwiw you want to define `def inspect(io : IO) : Nil`
<FromGitter> <Blacksmoke16> then do like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5feb8e19dbb17f28c5a93090]
<hightower2> Blacksmoke16 yes, yes, this was just to wrap up the example
<FromGitter> <watzon> @jrei:matrix.org do you have any examples of using it in this way?
<hightower2> aha but yes, you are right, missed that one
<FromGitter> <jrei:matrix.org> hum, no overhead when converting to bytes compared to your example, though: https://github.com/j8r/crystalizer/blob/master/src/byte_format/serialize.cr
<hightower2> Blacksmoke16: I know there will be benefit to posting it, thanks! :)
<FromGitter> <jrei:matrix.org> @watzon: `Crystalizer::ByteFormat.serialize(some_struct)`
<hightower2> Blacksmoke16: I could have gone without String.build at all, and pass the original IO from the Log method (I assume there is one?), but I didn't want to clutter the usage with like "my io, 1, 2, 3" or "my 1, 2, 3, io"
<FromGitter> <Blacksmoke16> another question i have is do you really want to log when every object is created?
<FromGitter> <jrei:matrix.org> and to convert from bytes to your object, `deserialize` can be used. Note there are instances methods to customize endianess and IO
<hightower2> Blacksmoke16 no it's general purpose... that's just a working example I wrapped up... and the args could be anything, not necessarily 'self' that I used
<FromGitter> <Blacksmoke16> ok
<FromGitter> <jrei:matrix.org> hum, I just get to optimize more byteformat: a field cannot be nillable, so no need to have a way to store if the field is present or not
_ht has quit [Remote host closed the connection]
<FromGitter> <Daniel-Worrall> How can I compile code without prelude?
<FromGitter> <Blacksmoke16> `--prelude none` iirc
<oprypin> Daniel-Worrall, --prelude=empty
<FromGitter> <Blacksmoke16> so close
<FromGitter> <jrei:matrix.org> there are other prelude options than "empty"?
<FromGitter> <Daniel-Worrall> so what I needed this for was so I could run some debug pp lines in the compiler without it getting a shit ton of output from the prelude
<FromGitter> <Blacksmoke16> I'm surprised pp works without it
<FromGitter> <Daniel-Worrall> well pp is in the compiler code, not the code I'm running it on
<FromGitter> <Daniel-Worrall> so you build crystal with stdlib, pp included
<FromGitter> <Daniel-Worrall> then run it without the prelude
<oprypin> jrei:matrix.org, it's just a filename
<oprypin> you can do --prelude=char , it just won't work lol
<FromGitter> <Blacksmoke16> `--prelude=prelude`
<oprypin> thats the default, yes
<FromGitter> <jrei:matrix.org> --prelude=prelude and --prelude=empty...
<FromGitter> <jrei:matrix.org> It would be more logical to have `--no-prelude` then
<FromGitter> <jrei:matrix.org> but maybe it was thought to be configurable for the future
<FromGitter> <Daniel-Worrall> na, that just gives more options
<FromGitter> <Daniel-Worrall> you can target a file, keep prelude, or empty all in 1
<FromGitter> <jrei:matrix.org> ha yes it is a file name
<FromGitter> <jrei:matrix.org> what if my file is called "empty" :P
<FromGitter> <Daniel-Worrall> empty.cr
<FromGitter> <jrei:matrix.org> right
<oprypin> --prelude=windows_stubs is a thing
<oprypin> jrei:matrix.org, no i dont think you understand, when you write --prelude=empty, you *are* just loading a file that is called "empty"
<oprypin> which, funnily enough, is not empty
<oprypin> you can also do `--prelude=./empty` for your own local file
<FromGitter> <jrei:matrix.org> hum ok
<oprypin> is just a `require "$arg"`
<FromGitter> <jrei:matrix.org> not very clear from the CLI help
<FromGitter> <jrei:matrix.org> ok, that's a crystal file accessible from CRYSTAL_PATH, not just a regular one
<FromGitter> <jrei:matrix.org> ha yes it works has I thought, thanks
<FromGitter> <jrei:matrix.org> this means if I have locally a `lib/foo.cr`, I can `--prelude foo`
<oprypin> dont forget `--prelude=./foo`
<FromGitter> <jrei:matrix.org> :+1
<straight-shoota> in lib it should prob work without relative path
<FromGitter> <jrei:matrix.org> yes it does
teardown has quit [Remote host closed the connection]
<FromGitter> <nothratal> does someone know how to transform ruby's ```private```-scope in crystal? In ruby it's just: the rest of everything in this class is private :P
<oprypin> nothratal, please just dont?
<oprypin> u can make a dirty macro for that, e.g. `privatize do` but why
<FromGitter> <nothratal> currently merging some ruby code and have this private scoping everywhere....mostly I comment it with "really necessary?"
<FromGitter> <nothratal> maybe nobody is missing it
HumanG33k has quit [Ping timeout: 260 seconds]
<straight-shoota> just explicitly individual methods as private if they're meant to be private
teardown has joined #crystal-lang
<FromGitter> <Blacksmoke16> ^
<FromGitter> <Daniel-Worrall> If I'm changing the compiler so that the compiler then is no longer able to compile itself without changes, what is the proper way to go about it so that it works with CI? 2 PRs?
<straight-shoota> Definitely two PR and they'll need to be merged in two different major releases
<FromGitter> <Daniel-Worrall> yikes
<FromGitter> <Daniel-Worrall> So my changes are basically *no*
<straight-shoota> what are you doing?
<FromGitter> <Daniel-Worrall> Remember that yielding args from a 1 line block being only able to access the first variable? I've changed it so that if there is more than 1 argument yielded, it will splat and return a tuple. So it'll break some 1 liners that call a method that will yield 2 args and ignore the 2nd one
<FromGitter> <Daniel-Worrall> In a different branch, I went and made the yields consistently tuples manually to demonstrate all the places they're used
<straight-shoota> I don't follow what you mean exactly. What's a 1 line block?
teardown has quit [Ping timeout: 240 seconds]
<FromGitter> <Daniel-Worrall> Like `foo(&.itself)`
<FromGitter> <Daniel-Worrall> Sorry, I'm definitely limited on the correct nomenclature
<straight-shoota> ah okay
<straight-shoota> I use short block syntax to describe that
teardown has joined #crystal-lang
<straight-shoota> So what's the motiviation for that change?
<straight-shoota> I don't see how it would be particularly useful if I get a tuple everywhere when there are more than one block argument
<FromGitter> <Daniel-Worrall> Motivation is to give access to the other block arguments in the short block syntax
<straight-shoota> but how? deconstructing the tuple?
<FromGitter> <Daniel-Worrall> yeah, if you need the first, you could `foo(&.[0].method)`
<straight-shoota> well, currently, I can just do `foo(&.method)`:P
<FromGitter> <Daniel-Worrall> yeah, but then you could do [1], [2] etc
<FromGitter> <Daniel-Worrall> with whatever you need
<FromGitter> <Daniel-Worrall> I forgot the exact example I gave last week but it was with the hash
<straight-shoota> I think then the code becomes so bulky that it's not worth it
<FromGitter> <Blacksmoke16> isnt this essentially like https://github.com/crystal-lang/crystal/pull/9218
<FromGitter> <Daniel-Worrall> Looks like similar motivations
<straight-shoota> yeah, there have been several approaches to this in the past
<FromGitter> <Daniel-Worrall> I didn't want to actually propose this specific change, more show it in action
<FromGitter> <Daniel-Worrall> and it gave me a good reason to dive into compiler internals so I can help in the future
<straight-shoota> that'd definitely be great =)
<FromGitter> <Blacksmoke16> go implemented https://github.com/crystal-lang/crystal/issues/9802 for me ❀️
<FromGitter> <Blacksmoke16> implement*
<straight-shoota> we'll probably end up with a special syntax for this, like in #9218
<DeBot> https://github.com/crystal-lang/crystal/pull/9218 (Compiler: add short block syntax &(..., &1))
<FromGitter> <Daniel-Worrall> heh, I'd love to tackle some compiler bugs maybe, instead of new features
<FromGitter> <Daniel-Worrall> So it seems it's just shelved for post 1.0
<FromGitter> <Daniel-Worrall> Maybe I should talk about my intentions more :^)
<straight-shoota> new features are typically not hold back by missing implementation, but specification and decision on that
teardown_ has joined #crystal-lang
<FromGitter> <Daniel-Worrall> yeah, that's 1 reason why
<FromGitter> <Daniel-Worrall> why I would prefer to tackle bugs rather than feature implementation
teardown has quit [Ping timeout: 240 seconds]
<FromGitter> <Blacksmoke16> i have good list of those as well πŸ˜†
HumanG33k has joined #crystal-lang
HumanG33k has quit [Max SendQ exceeded]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang