RX14 changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.27.1 | Fund Crystal's development: http://is.gd/X7PRtI | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Gitter: https://gitter.im/crystal-lang/crystal
jemc has quit [Ping timeout: 250 seconds]
<fullforce> rkeene: ill try that
<fullforce> rkeene: that seemed to work, thanks
johndescs has quit [Ping timeout: 246 seconds]
johndescs has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> @gring @aarongodin https://forum.crystal-lang.org/t/asynchronous-http-requests/466/10?u=scott
<FromGitter> <codenoid> hi
<FromGitter> <codenoid> tf
<FromGitter> <codenoid> when crystal has forum.crystal-lang.org
<FromGitter> <codenoid> cool dude
<FromGitter> <dscottboggs_gitlab> idk a month or so ago
<FromGitter> <Blacksmoke16> couple months ago
<FromGitter> <Blacksmoke16> more than that
<FromGitter> <Blacksmoke16> early December 2018
<FromGitter> <dscottboggs_gitlab> oh my
* FromGitter * dscottboggs_gitlab is bad at keeping track of time
<FromGitter> <Blacksmoke16> confirmed
<FromGitter> <dscottboggs_gitlab> hey Mr. Macro Wizard
<FromGitter> <dscottboggs_gitlab> is there a way to define a function/method to use in macro land? like ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c74a027fec94e507780ab36]
<FromGitter> <dscottboggs_gitlab> (you're Mr. Macro Wizard @Blacksmoke16 )
<FromGitter> <dscottboggs_gitlab> lol
<FromGitter> <Blacksmoke16> i try :P
<FromGitter> <dscottboggs_gitlab> no idea how to do that though? :(
<FromGitter> <Blacksmoke16> oh that was a question
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Blacksmoke16> im thinking no
<FromGitter> <dscottboggs_gitlab> damn
<FromGitter> <dscottboggs_gitlab> I'll make a forum post and maybe we'll learn something together
<FromGitter> <Blacksmoke16> πŸ‘
fullforce has left #crystal-lang [#crystal-lang]
<FromGitter> <dscottboggs_gitlab> https://forum.crystal-lang.org/t/how-to-define-a-reusable-function-for-use-in-macros/475 if you want to follow the topic
<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> <Blacksmoke16> fair enough
f1refly has quit [Ping timeout: 264 seconds]
ylluminate has quit [Quit: Textual IRC Client: www.textualapp.com]
jemc has joined #crystal-lang
f1refly has joined #crystal-lang
<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> @aarongodin this might work? ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5c74e5cded21832d370f8914]
<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.
sagax_ is now known as sagax
badeball has joined #crystal-lang
blassin has joined #crystal-lang
Vexatos has joined #crystal-lang
ua has joined #crystal-lang
<FromGitter> <asterite> there's reduce: https://crystal-lang.org/api/0.27.2/Enumerable.html#reduce%28%26block%29-instance-method
<FromGitter> <dscottboggs_gitlab> @aarongodin you can do that at compile time but not at runtime
lucasb has joined #crystal-lang
<FromGitter> <vladfaust> Is that a bug? https://carc.in/#/r/6dcu
<FromGitter> <vladfaust> No, it is not
<FromGitter> <vladfaust> T is unknown
<chickendan> asterite: I would like to get the intermediate values. [1,2,3].cycle.cumulsum.first(5) should be [1,3,6,7,9].
<chickendan> in dlang would be this: [1,2,3].cycle.cumulativeFold!"a+b".take(5)
<FromGitter> <dscottboggs_gitlab> I'm sorry, @chickendan I'm not sure what's happening here...
<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> @chickendan does this work? https://carc.in/#/r/6dcz
<FromGitter> <dscottboggs_gitlab> just a rough sketch
<chickendan> @dscottboggs_gitlab, thanks, but what am I missing here? "in main.cr:15: undefined method 'wrap'; wrap (@index -= @array.size)"
<FromGitter> <dscottboggs_gitlab> oh I messed up
<chickendan> Sorry, first day of crystal. :)
<chickendan> Btw. how would I combine this with the cycle method?
<FromGitter> <dscottboggs_gitlab> I wrote that `wrapped_index` method as `wrap(index)` but then changed it and didn't get the whole thing
<chickendan> This is what I have in rust and dlang: https://pastebin.com/0C0LpCiW
<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> ugh my `wrapped_index` method is not working https://carc.in/#/r/6ddf/edit
<FromGitter> <yxhuvud> @asterite It could create the coolest implementation of fibonacci though :)
gangstacat has quit [Quit: Ĝis!]
<FromGitter> <asterite> I have this so far: https://play.crystal-lang.org/#/r/6ddj
<FromGitter> <asterite> let me try the fibonacci...
<FromGitter> <asterite> Hmm... I'm not sure fibonacci can be done... or how?
<FromGitter> <dscottboggs_gitlab> ☝️ February 26, 2019 8:45 AM (https://gitter.im/crystal-lang/crystal?at=5c7542f78a7def0752dd3121) oh my...
<FromGitter> <asterite> actually it needs to be a class, just in case
<FromGitter> <yxhuvud> hmm, perhaps not unless you save both values each iteration. Bleh.
return0e has joined #crystal-lang
return0e_ has quit [Ping timeout: 250 seconds]
<FromGitter> <dscottboggs_gitlab> interesting, I thought to create a `first` case but thought I could figure some way around it.
<FromGitter> <asterite> @yxhuvud but you can implement factorial ;-)
laaron has joined #crystal-lang
gangstacat has joined #crystal-lang
<chickendan> Thanks, everyone, you're a lovely bunch. :)
<chickendan> Btw., here's a dlang fib range impl: https://run.dlang.io/is/4GRa0g
<mps> straight-shoota: building 0.27.2 on Alpine I've got next fails for test (make spec) http://tpaste.us/baEL
<mps> I prepared patch which disables (change 'it' to 'pending') for these tests
<mps> is it ok to 'skip' these three tests?
<mps> patch is here: http://tpaste.us/7vwj
<mps> if you (or anyone else) have time please look at these tests and tell me could we release 0.27.2 with these fixes
<FromGitter> <asterite> chickendan: here's fib in Crystal (tap is just there to make it shorter/cooler :-P)
<chickendan> asterite: how 'bout this, cool, eh? https://run.dlang.io/is/Ycw4gm
<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> <m0rozov> Hey! ⏎ ⏎ I have this problems: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7550690966d91204ec14b0]
<FromGitter> <asterite> yes, as far as I remember in D you generated code at compile time by manipulating strings. It's similar to Crystal in a way
<FromGitter> <m0rozov> i try kemal example from github and this error :(
<FromGitter> <asterite> @m0rozov maybe the answer is somewhere here: https://github.com/crystal-lang/crystal/issues?q=library+not+found+for+-lssl+is%3Aissue+is%3Aclosed
<FromGitter> <m0rozov> @asterite, I can not find a similar problem ⏎ ⏎ ps. I have this problem on MacOs
<FromGitter> <m0rozov> and don't find lssl packages on this os
<FromGitter> <asterite> you need to somehow have the openssl package in your system
<FromGitter> <m0rozov> oh! ⏎ ⏎ @asterite, i did it ⏎ ⏎ ```export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"``` ... [https://gitter.im/crystal-lang/crystal?at=5c755207d2d62067b70d500d]
<FromGitter> <asterite> cool! :-)
<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 πŸ‘
<DeBot> https://github.com/crystal-lang/crystal/pull/7479 (Add detection of linux environment in compiler config)
<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> <vivus-ignis> tried, didn't work, @asterite
<FromGitter> <vivus-ignis> however, i did change this function's signature
<FromGitter> <vivus-ignis> let me try `out` once more
<FromGitter> <vivus-ignis> cool stuff, out is smart! thanks, @asterite ! it recognized that a function needs a pointer to a pointer
<FromGitter> <vivus-ignis> niice
DTZUZO has joined #crystal-lang
<FromGitter> <vivus-ignis> crystal is damn cool
<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> so would be like
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c7568b82ca5ec547443b058]
<FromGitter> <Blacksmoke16> also using `from_json`
<FromGitter> <Blacksmoke16> instead of `new`
<FromGitter> <Blacksmoke16> then whatever other properties you want to add, just have to add a property for them
<FromGitter> <Blacksmoke16> or were you wanting to add properties that don't exist in the json?
<FromGitter> <arnavb> I want to add properties that don't exist in the JSON @Blacksmoke16
<FromGitter> <arnavb> In other words, I want to instantiate the class with 1. The JSON and 2. Some custom instance variables
<FromGitter> <arnavb> Sorry my original code example didn't reflect this, forgot to include in when quickly typing out an example.
<FromGitter> <Blacksmoke16> yea i see now
<FromGitter> <vladfaust> @asterite ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5c756b4053efa912037d0ab6]
<FromGitter> <vladfaust> I'm using https://www.npmjs.com/package/wscat for testing
<FromGitter> <Blacksmoke16> @arnavb yea thats kinda tricky
<FromGitter> <Blacksmoke16> one option would be https://play.crystal-lang.org/#/r/6dfa
<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> <Blacksmoke16> when you do `to_json`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/6dfg default might be way to go, less anyone else has any ideas?
RX14 has joined #crystal-lang
<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
<z64> \o/
<mps> z64: thanks
<mps> oz: thanks to you also :)
<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?
Simerax has quit [Quit: https://quassel-irc.org - Komfortabler Chat. Überall.]
chickendan has quit [Quit: leaving]
<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
sagax has quit [Ping timeout: 272 seconds]
return0e has quit [Ping timeout: 240 seconds]