<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>
<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>
<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>
<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
<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)
<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.
<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>
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