<FromGitter>
<dscottboggs_gitlab> I feel like I'm really close with that last example :/
<FromGitter>
<Blacksmoke16> will do
<FromGitter>
<Blacksmoke16> would have to be a new construct id think
<FromGitter>
<Blacksmoke16> if you think about it a macro just expands to crystal code
<FromGitter>
<dscottboggs_gitlab> yeah, I'm just trying to reuse some macro code though, I'd be super surprised if no one's run into that yet
<FromGitter>
<dscottboggs_gitlab> although I guess with nested macros it's less of an issue
<FromGitter>
<Blacksmoke16> wait
<FromGitter>
<Blacksmoke16> are the three times within the same block? like within same method or something?
<FromGitter>
<dscottboggs_gitlab> within the same class
<FromGitter>
<Blacksmoke16> i mean like would you be able to wrap everything in `{% begin %} / {% end %}`?
<FromGitter>
<dscottboggs_gitlab> but how does that get me a method?
<FromGitter>
<dscottboggs_gitlab> (function)
<FromGitter>
<Blacksmoke16> well if you're able to do that, you would be able to do the formatting logic one, assign it to a new macro var then just reference that var going forward where you need it
<FromGitter>
<Blacksmoke16> but if you need it 3 diff places that you cant wrap then yea it wont help you
<FromGitter>
<dscottboggs_gitlab> yeah I'm trying to define an Enum of every language and a method with a `case...when` to associate each language with it's ISO 639-1 code, all from a NamedTuple macro variable that contains each enumeration. So the 3 instances are in the original enum definition (I.E. Languages::English), the `#language_code` method and the `.from_language_code` class method.
<FromGitter>
<aarongodin> qq -- is there a way to reflect/enumerate the instance variables on an object?
<FromGitter>
<aarongodin> Actually, I have a good feeling the answer is no, as it wouldnβt make sense at compile time
<FromGitter>
<aarongodin> Or rather, maybe it would. Iβm confusing myself now lol
jemc has quit [Ping timeout: 246 seconds]
<FromGitter>
<neutrinog> is there a way to make instance variables hidden from a subclass?
<FromGitter>
<neutrinog> to avoid namespace pollution in a library and to prevent third party developers from accidentally overwriting something important.
<FromGitter>
<neutrinog> Or am I stuck with composition over inheritance?
<FromGitter>
<mavu> @neutrinog maybe put them in thier own struct/class and only access them through that? that will reduce the number of variables to 1.
sagax has quit [Ping timeout: 245 seconds]
_whitelogger has joined #crystal-lang
sagax has joined #crystal-lang
gangstacat has quit [Ping timeout: 245 seconds]
gangstacat has joined #crystal-lang
badeball_ has joined #crystal-lang
badeball has quit [Ping timeout: 245 seconds]
druonysus has quit [Ping timeout: 245 seconds]
sz0 has quit [Quit: Connection closed for inactivity]
sagax has quit [Read error: Connection reset by peer]
ashirase has quit [Ping timeout: 245 seconds]
ashirase has joined #crystal-lang
sagax has joined #crystal-lang
chickendan has joined #crystal-lang
return0e_ has joined #crystal-lang
<chickendan>
Hey, everyone! Quick beginner question: is there a cumulative fold somewhere in the stdlib? Rust and haskell have 'scan' for example, dlang has cumulativefold.
ashirase has quit [Ping timeout: 246 seconds]
ua has quit [Ping timeout: 246 seconds]
ashirase_ has joined #crystal-lang
sagax_ has joined #crystal-lang
blassin has quit [Ping timeout: 255 seconds]
sagax has quit [Ping timeout: 255 seconds]
badeball_ has quit [Ping timeout: 255 seconds]
return0e has quit [Ping timeout: 255 seconds]
Vexatos has quit [Ping timeout: 255 seconds]
RX14 has quit [Ping timeout: 255 seconds]
<chickendan>
Currently I'm doing this: csum = 0; arr.cycle.each do |x| csum += x ... Would love to be able to eliminate that csum var.
<FromGitter>
<dscottboggs_gitlab> I think you may have to implement that
<chickendan>
Alright, fair enough, just wanted to make sure I'm not overlooking something in the docs.
<FromGitter>
<dscottboggs_gitlab> true
<FromGitter>
<yxhuvud> Hmm. So basically you are asking for an iterator version of reduce. *thinking*
<chickendan>
Yxhuvud: I'm redoing AOC18 in crystal. Found your solutions on github, you are basically doing the same as above. Intermediate values would be slicker.
<FromGitter>
<dscottboggs_gitlab> this class, once instantiated, would have all the `Iterator` methods on it: https://crystal-lang.org/api/0.27.2/Iterator.html β β so something like `CumulativeSum(Int32).new([1, 2, 3]).first(5)`
<FromGitter>
<asterite> we don't have cummulative fold in our Iterator but we could add it. I'm thinking what would the types be... I guess the input types and return types must all be the same, right?
<FromGitter>
<asterite> or some kind of union which I can't figure out how to name
<FromGitter>
<dscottboggs_gitlab> what's with the code inside a string literal?
<chickendan>
Template parameter, should short for a lambda expr.
<chickendan>
just*
<FromGitter>
<dscottboggs_gitlab> idk it just seems weird to me haha. It looks like an eval, but D is compiled so it must be a macro?
<chickendan>
Basically like c++ templates where you would write recurrence<...>(1,1). Crystals/lisps macros are mixins in d, slightly different and not as slick to be honest.
<FromGitter>
<dscottboggs_gitlab> oh, so the code in quotes is a literal text based macro rather than evaluating to AST nodes then?
<FromGitter>
<asterite> I hope this will be improved in the future
<FromGitter>
<straight-shoota> mps, it's totally fine to ignore these spec failures. They're just about what we expect the error message should look like, but that differs between libc implementations.
<FromGitter>
<straight-shoota> The second one can probably be trivially fixed by replacing `flag?(:linux)` with `flag?(:gnu)`
<FromGitter>
<straight-shoota> I'm not sure if we need to be so specific at all, it would probably suffice to check that it either contains `bind` or `listen`. But I guess being a bit more strict avoids accidentally triggering unexpected errors which would fulfill the expectation.
<FromGitter>
<straight-shoota> Apart from this, it looks really great π If we can get #7479 into 0.28.0 to simplify distribution, we should be able to include alpine in our CI stack. This would catch any issues with musl right away π
<FromGitter>
<vivus-ignis> hi good people! is there a way to pass a pointer to a pointer in crystal? β say, i have a C function that I'
<FromGitter>
<vivus-ignis> m wrapping
<FromGitter>
<vivus-ignis> and it has an argument STRUCT **t
<FromGitter>
<vivus-ignis> pointerof(pointerof(t)) doesn't work here
<FromGitter>
<vivus-ignis> specifically, this is the function i'm wrapping: β int tar_open(TAR **t, char *pathname, tartype_t *type, int oflags, int mode, int options);
<mps>
straight-shoota: thanks for explanation, I will prepare upgrade to the 0.27.2 for Alpine linux with these tests skipped
<FromGitter>
<vivus-ignis> oh, ok, i just declared another variable: ` tp = pointerof(t)` and then did pointerof(tp). that works
<FromGitter>
<fernandes> anyone got let's encrypt certs working with http/server? I'm getting a bad time hahah β β `SSL_accept: error:1407609C:SSL routines:SSL23_GET_CLIENT_HELLO:http request (OpenSSL::SSL::Error)` β β any tip is appreciated ;) [https://gitter.im/crystal-lang/crystal?at=5c755cd58a7def0752ddec57]
<FromGitter>
<fernandes> I just did something stupid... working flawlessly :)
<FromGitter>
<asterite> @vivus-ignis you should probably pass `out t`
<FromGitter>
<asterite> in C libs it's pretty common to receive a pointer to something and have that function "fill" it with something meaningful. Then `out` can be used in those cases to avoid some boilerplate.
<FromGitter>
<vivus-ignis> very useful
jemc has joined #crystal-lang
<FromGitter>
<GaryMiller> @j8r Thanks for the Benchmark find! Some of the versions were a little out of date and I was surprised to see of the languages very fast in some benchmarks and very slow in others. Most all benchmarks are oriented more towards math that text manipulation I got 17 times speed up in going from Python to Pypy. looks like I could potentially see another 3 to 5 times speedup going to Crystal once the Windows
<FromGitter>
... native version is available.
<FromGitter>
<arnavb> Hi! Can I ask for help related to a bug I'm experiencing here?
<FromGitter>
<arnavb> Not really a bug, more like a problem I'm unable to solve
<FromGitter>
<Blacksmoke16> sure
<FromGitter>
<arnavb> Ok, so I'm trying to create an API wrapper. To do this, I created a Serializable JSON object using JSON::Serializable
<FromGitter>
<arnavb> Is there any way I can add custom instance variables to such a class? I tried: ```require "json" β β class House β include JSON::Serializable β property address : String ... [https://gitter.im/crystal-lang/crystal?at=5c7567d70966d91204ecc211]
<FromGitter>
<arnavb> But I get this error: `instance variable '@address' of House was not initialized directly in all of the 'initialize' methods, rendering it nilable. Indirect initialization is not supported.`
<FromGitter>
<vladfaust> @asterite, @RX14 websockets should be able to pass a error on close according to https://tools.ietf.org/html/rfc6455#section-7.4. Is it possible right now? `socket.close("1000")` gives me `Invalid WebSocket frame: invalid status code 12592`
<FromGitter>
<Blacksmoke16> @arnavb when using the `JSON::Serializable` you would set it up without a `initialize` method
<FromGitter>
<Blacksmoke16> where you supply a default value, other option would be to maybe make the other property nilable
<FromGitter>
<Blacksmoke16> default value isnt a bad idea, as the constructor would have a non-nilable type guard on it, so you *should* never get in that state, vs if you set it nilable, that could cause some problems as then you'd have to do nil checking
<FromGitter>
<Blacksmoke16> would you also be expecting `other_value` to be serialized?
<FromGitter>
<arnavb> @Blacksmoke16 No, I'm not going to convert the instance back to JSON. The instance variable will be used for HTTP requests.
<z64>
would just store that value with the serializable object
<z64>
instead of inside it
<FromGitter>
<arnavb> This might be an XY problem, though, I'm starting to wonder.
<z64>
`house_data = {123, House.from_json(str)}`, etc.
<z64>
or wrap it in some other thing, like a `record Data, value : Int32, house : House`
<FromGitter>
<arnavb> True, I would make a nested class. Would there be any way to access the json attributes directly from the enclosing class itself? i.e instead of `instance.json_data.member`, but rather `instance.member`?
<z64>
`def member; @json_data.member; end`
<FromGitter>
<arnavb> Doing this for every single JSON field seems tedious. Looks like I might have to write a macro....
<z64>
you can use `delegate` macro already if you want. `delegate a, b, c, to: @json_data`
<z64>
dont really recommend it though. just doing explicit access should be fine, no need to waste time trying to compose a transparent object. `data.value`, `data.house.address`, etc..
<FromGitter>
<arnavb> That's actually really helpful. I guess I could use this. I'm still wondering if this is an XY problem. Before I actually go forward with this, I'll just what I'm trying to solve here: β β My goal is to make a wrapper for the Github API. My library has a class `Client`, which end users will instantiate with authentication, etc. I've created a function, `user`, which takes a parameter and returns the
<FromGitter>
... corresponding GH user endpoint, loaded into a `User` object. However, a user has a lot of attributes (repositories, followers, etc.). To avoid instantiating everything at once, I want to pass a copy of the internal HTTP client I'm using to the User class itself. This way, when a certain member is requested, I can almost lazy-request ... [https://gitter.im/crystal-lang/crystal?at=5c757a0265ffa019ea5447ce]
<FromGitter>
<Blacksmoke16> sorry had lunch, sounds like you're on the right track
<FromGitter>
<arnavb> Cool! I guess I'm gonna go forward with what z64 suggested. You guys have been really helpful. Thanks!
<z64>
yw
jemc has quit [Ping timeout: 246 seconds]
jemc has joined #crystal-lang
Vexatoast has joined #crystal-lang
ua has quit [Excess Flood]
Vexatos has quit [Ping timeout: 255 seconds]
ua has joined #crystal-lang
snapcase has quit [Ping timeout: 272 seconds]
<mps>
j8r: straight-shoota: crystal 0.27.2 is uploaded to Alpine edge. enjoy and thanks for help
<oz>
gonna use that soon enough to deploy a small web api. :)
<mps>
bug reports and issues are welcome on bugs.alpinelinux.org
<FromGitter>
<j8r> π
<mps>
j8r: hope you will try it soon :)
Simerax has joined #crystal-lang
<Simerax>
hey, im currently experimenting with non buffered IO via stdin. For this I basically spawn a process and do STDIN.raw read_char in a loop. If there is something typed I send the char via channel back to the main process. This works fine however Signals like Ctrl+C or others do not manage to get past my input loop. They are just captured like every other key. Of course I could just say "if key is Ctrl+C do xyz" but I would like to
<Simerax>
still be able to use the Standard Signals-mechanism. Any suggestions or ideas?
<FromGitter>
<straight-shoota> Simerax, reading from the raw stream is probably not a good idea. I'd suggest using a library specialized for reading keyboard input. I don't have any experience with that, so I can't recommend anything specific.
lucasb has quit [Quit: Connection closed for inactivity]
<FromGitter>
<j8r> Simerax , it may be also an issue of your terminal if it doesn't send a signal when CTRL+C