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
<raz> yup i'm just sticking with the regular mapping stuff so far
<FromGitter> <watzon> Clean? Or Clear?
<FromGitter> <watzon> Because I can't find a shard named clean anywhere
<FromGitter> <Blacksmoke16> its clear
<FromGitter> <Blacksmoke16> https://github.com/anykeyh/clear
<FromGitter> <watzon> Ok I’m aware of clear, just had never heard of Clean haha
hightower3 has joined #crystal-lang
<FromGitter> <tenebrousedge> what's a good way to deal with a possibly empty iterator?
<FromGitter> <tenebrousedge> preferably other than `rescue nil`
deavmi has quit [Quit: No Ping reply in 180 seconds.]
deavmi has joined #crystal-lang
<FromGitter> <ryanprior:matrix.org> @tenebrousedge: something like `iter.first unless iter.empty?` help?
<FromGitter> <tenebrousedge> hmmm, `iter.empty?` could work
<FromGitter> <ryanprior:matrix.org> you can also use something like `iter.first(n).to_a` and get an array of between 0 and n elements, which could be an empty array
<FromGitter> <tenebrousedge> I don't necessarily want a known number of elements
<FromGitter> <ryanprior:matrix.org> how do you decide when to stop? can you express it in a block? if so, `iter.take_while { |item| keep_going? item }.to_a`
<FromGitter> <tenebrousedge> it's either `iter.first` or `iter.find(&.foo?)`
<FromGitter> <ryanprior:matrix.org> The second one should work fine for an empty iterator, the first one I'd guard with `unless iter.empty?`
<FromGitter> <tenebrousedge> doesn't seem to work :/
<FromGitter> <tenebrousedge> wait
<FromGitter> <tenebrousedge> hmm, nope
<FromGitter> <ryanprior:matrix.org> https://repl.it/@ryanprior/empty-iterator#main.cr
<FromGitter> <tenebrousedge> I'm not sure how much I can reduce my example
<FromGitter> <tenebrousedge> It's just an AoC problem though so it's one file (https://gist.github.com/tenebrousedge/6dfd2688bae0eaba6a65beea5e738c1e#file-crystal-cr-L133)
<FromGitter> <tenebrousedge> the execution is somewhat convoluted due to the problem statement
<FromGitter> <tenebrousedge> maybe `next`?
<FromGitter> <tenebrousedge> I think `next`
<Andriamanitra> yeah next at least doesn't cause an exception, you'll need a check to see if it's Iterator::Stop though
<FromGitter> <tenebrousedge> `reject(Iterator::Stop)` should do
<FromGitter> <tenebrousedge> Andriamanitra any other opinions about that pile of silly nonsense?
<FromGitter> <Blacksmoke16> dont you have to worry about `reject` consuming the iterable tho?
<FromGitter> <tenebrousedge> nah, do it afterwards
<FromGitter> <tenebrousedge> `map(&.next).reject(Stop)`
<FromGitter> <Blacksmoke16> whats the goal here?
<Andriamanitra> tenebrousedge: i'm having trouble following the code to be honest but that might be more my fault than your code's
<FromGitter> <Daniel-Worrall> Is the bootstrapped compiler on Windows supposed to be able to build the compiler?
<FromGitter> <Daniel-Worrall> I'm getting some lovely linking errors
<FromGitter> <Daniel-Worrall> `fatal error LNK1120: 279 unresolved externals` :^)
<Andriamanitra> ..although going back to my code from day 11 i don't really understand it either any more, probably just a convoluted problem :D
<FromGitter> <tenebrousedge> yeah it's pretty obnoxious
<FromGitter> <tenebrousedge> but I kinda like the idea of using iterators for the sight lines, I can see reusing that for other grid problems...if I can get it working
teardown has quit [Ping timeout: 240 seconds]
<Andriamanitra> tenebrousedge: ooh, i like the use of #hash to check if it's still evolving! i need to keep that one in mind in case we get another one of those "find the cycle" problems
<FromGitter> <tenebrousedge> it seemed like the simplest implementation
f1reflyylmao has joined #crystal-lang
<FromGitter> <tenebrousedge> I mean I don't know. I definitely have a particular style of doing this
<Andriamanitra> i used a boolean that flips if there's any change and didn't like that solution very much
<FromGitter> <tenebrousedge> otoh that's more space friendly
f1refly has quit [Ping timeout: 256 seconds]
<Andriamanitra> yeah but requires keeping track of all the places where you might be changing something :\
teardown has joined #crystal-lang
<FromGitter> <tenebrousedge> did you see asterite's solution?
<Andriamanitra> not yet, i'll go check it out
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
<FromGitter> <Daniel-Worrall> I looped until previous = current
<FromGitter> <Daniel-Worrall> The set of object hashes is neat
HumanG33k has quit [Ping timeout: 264 seconds]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
_ht has joined #crystal-lang
<FromGitter> <mattrberry> After doing today's advent of code with sexprs the first time, I saw other people doing hacky operator overloads in ruby/python, so I was curious if I could do something similar in crystal. This is the best I could come up with: https://carc.in/#/r/a4rf ⏎ I'm wondering though if I could do it just by reopening the Int struct like you could in ruby rather than making MyInt, but it doesn't look like that
<FromGitter> ... works. I can only override certain operators on Int. For example, while overriding `%` works fine, attempting to override `+` doesn't do anything. Additionally, overriding `<<` seems to get into a weird loop until the stack overflows. Any idea why certain operators can be overridden but others can't? I saw that `+` and `*` aren ... [https://gitter.im/crystal-lang/crystal?at=5fdc64f24eba353cdfe45c47]
<FromGitter> <erdnaxeli:cervoi.se> what are sexprs ?
yxhuvud has quit [Read error: Connection reset by peer]
yxhuvud has joined #crystal-lang
<FromGitter> <postmodern:matrix.org> S-expressions
<FromGitter> <erdnaxeli:cervoi.se> ok
<oprypin> [04:06:49] <@Daniel-Worrall> Is the bootstrapped compiler on Windows supposed to be able to build the compiler?
<oprypin> yes and it does so regularly in the continuous build
<oprypin> (and whenevevr i fiddle with it)
zorp has quit [Ping timeout: 268 seconds]
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
oprypin has quit [Client Quit]
oprypin has joined #crystal-lang
<FromGitter> <Dan-Do> How do I convert an Int64 to slice of 8 bytes?
<straight-shoota> => https://crystal-lang.org/api/0.35.1/IO.html#write_bytes(object,format:IO::ByteFormat=IO::ByteFormat::SystemEndian)-instance-method
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
<FromGitter> <Dan-Do> perfect :)
<frojnd> What am I missing here? https://carc.in/#/r/a4k6
<frojnd> Trying to make a struct that reflects commented json structure...
<frojnd> Also how can I only use setter without .new word on a struct?
<FromGitter> <tenebrousedge> a setter?
<FromGitter> <tenebrousedge> on a struct?
<FromGitter> <tenebrousedge> that's not what structs are for
<FromGitter> <tenebrousedge> use `record` and `copy_from`
<FromGitter> <tenebrousedge> `record Foo, id : String`
<FromGitter> <tenebrousedge> er, `copy_with`
<frojnd> Can you edit my code please?
<FromGitter> <tenebrousedge> I have no idea what you're trying to do, but without a setter (and you should not use setters with structs) the object is just `record Verse, id : String`
<FromGitter> <tenebrousedge> ```record Verse, id : String ⏎ v = Verse.new("foo") ⏎ p v.id #=> "foo"``` [https://gitter.im/crystal-lang/crystal?at=5fdcae77c746c6431cc11583]
<frojnd> I'm trying to build that json string, example in comments in above link. With this example that you provided how can I add another verse id to the json?
<FromGitter> <tenebrousedge> you would need an array
<FromGitter> <lodenos> Hi everybody the 11th December was Fantastic. I have a weird question, is-it possible to get the AST of a Proc ? ⏎ My objective is get the AST send for a client write in crystal and make the compilation on place, like a master send some codes to compiling adn execute for the slave ⏎ I supporse for get the AST it’s only during the compilation to binary but just before with a macro save the AST as a string
<straight-shoota> yes, the AST only exists at compile time
<FromGitter> <lodenos> @straight-shoota Do u how get it ?
<straight-shoota> you could do something like this: https://carc.in/#/r/a4tb
<FromGitter> <tenebrousedge> is there some way to do it by using the compiler?
<straight-shoota> I don't think so
<straight-shoota> The major obstacle with this is that you really need the proc code as a literal. Even at compile time you can't just get the AST of a proc reference
<straight-shoota> for example when I do `proc = Proc(String, String).new do |x| x.upcase end; capture_proc proc` all the compiler sees is the variable `proc`
<straight-shoota> there's no way to retrieve the proc that was assigned to it as a value.
<FromGitter> <lodenos> I see
<FromGitter> <lodenos> I write an example give me 2mn
<FromGitter> <lodenos> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fdcbcf822f12e449bfa8dbd]
<FromGitter> <lodenos> https://carc.in/#/r/a4tk
<FromGitter> <Blacksmoke16> whats the goal here?
<FromGitter> <lodenos> That doesn’t work, but the idea it’s that get all the tree
<FromGitter> <lodenos> @Blacksmoke16 My objectiv it’s get all the AST of a Proc
<FromGitter> <Blacksmoke16> to do what?
<straight-shoota> replace fun with def
<straight-shoota> then it works
<FromGitter> <lodenos> And send the code compile by a client and executed
<FromGitter> <lodenos> XD
<FromGitter> <Blacksmoke16> 🤔
<FromGitter> <lodenos> But `procdata[1] # => "Proc(String, String).new do |x|\n amazing_fun(\"Crystal\")\n x.upcase\nend"`
<FromGitter> <lodenos> I have only the prototype of `def amazing_fun`
<FromGitter> <lodenos> Not the code of `def amazing_fun`
<FromGitter> <Blacksmoke16> this seems like not worth the effort
<FromGitter> <Blacksmoke16> not sure what benefit you're getting here?
<FromGitter> <asterite> What does it mean "send the code compile by a client and executed"?
<FromGitter> <lodenos> A Master send code at some Slaves, and slaves compile and execute the code received. Like Distributed
<FromGitter> <Blacksmoke16> why?
<FromGitter> <anthonyshull> just fyi, everyone is retiring the master/slave terminology
<oprypin> anthonyshull, just wait until "retiring" is deemed offensive
<FromGitter> <anthonyshull> meh, well if it is then i'll gladly stop using it. we've got lots of words.
<FromGitter> <Blacksmoke16> anyway, what benefit would that provide @lodenos ?
<FromGitter> <lodenos> @Blacksmoke16 Actually it’s juste an Idea, like research of the concept I’ve developed in C long time ago
<FromGitter> <Blacksmoke16> mk
<FromGitter> <lodenos> But my C version it’s so disgusting
<straight-shoota> how do you get the source code in C?
<FromGitter> <lodenos> Just read the `sources.c`and send like that
<FromGitter> <lodenos> with a septific Makefile
<FromGitter> <lodenos> A bit like OpenCL
<straight-shoota> you can do the same in Crystal
<straight-shoota> actually you have to because there's no way to get the definition of amazing_fun from the proc calling it
<FromGitter> <lodenos> Of course but I would like doing something really more elegant
sorcus has quit [Ping timeout: 260 seconds]
sorcus has joined #crystal-lang
<FromGitter> <lodenos> hum
<FromGitter> <lodenos> Really
oddp has joined #crystal-lang
<FromGitter> <Blacksmoke16> use it in what regard? how do you get one?
<FromGitter> <lodenos> If `def amazing_fun` get the body of function `amazing_fun`
<FromGitter> <Blacksmoke16> if you're inside of the method you can do `{{@def.body}}`
<FromGitter> <Blacksmoke16> otherwise you'd need a way to get the method, probably via like `{{MyType.methods.find ...}}`
<FromGitter> <lodenos> that it’s for method but for a function ?
<FromGitter> <Blacksmoke16> idt theres a way to access top level functions atm
<FromGitter> <Blacksmoke16> oh well i guess you can do `{{@type.methods}}` in this case
<FromGitter> <Blacksmoke16> assuming you're macro code is also at the top level
<FromGitter> <Blacksmoke16> your*
<FromGitter> <lodenos> hum
<FromGitter> <lodenos> The thing I would like to doing it’s look complicated
DTZUZU has quit [Quit: WeeChat 2.9]
<raz> blacksmoke: fyi, tested and working with athena https://gist.github.com/m-o-e/3d8937d884bf8a7c71bc4402411ced61
<raz> feel free to merge if you find it useful, `ART::Spec::APITestCase` was just too verbose for me ;)
<straight-shoota> why store cookies and response in the fiber?
<straight-shoota> cookies is somewhat explainable, but response is just the return value of the spec helper
<raz> just for quick access, i'm lazy
<straight-shoota> kay
<raz> specs are more readable w/o those temp assignments
<straight-shoota> no they're not
<straight-shoota> when I look at the spec I wonder where http_response comes from
<raz> nah you don't
<straight-shoota> with `http_response = get("/")` it's clear
<raz> if you don't wonder where get() comes from you have no business wondering where http_response comes from :p
<straight-shoota> too much magic in specs
<raz> yeh, matter of taste, feel free to leave that out if you use it ;)
<straight-shoota> will do :D
<FromGitter> <Blacksmoke16> *what have you done* :p
<raz> just some boilerplate removal :p
<FromGitter> <Blacksmoke16> i wouldnt be against having helper methods like `self.get("/")` versus `self.request("GET", "/")`
<FromGitter> <Blacksmoke16> but id rather keep the `APITestCase` 😉
<raz> sure, i didn't mean to change athena, was only offering it as an add-on ;) (personally i just didn't see the benefit of ATC, other than boilerplate ¯\_(ツ)_/¯
<FromGitter> <HertzDevil> how does the compiler itself figure whether a def is an operator
<FromGitter> <HertzDevil> the closest thing i could find is `Crystal::Type::SuggestableDefName = /\A[a-z_]/`
<FromGitter> <Blacksmoke16> the idea is that it enables code reuse
<FromGitter> <Blacksmoke16> i.e. you could imagine having something like `struct AuthenticatedUserRequestTestCase < ART::Spec::APITestCase`
<FromGitter> <Blacksmoke16> which redefines the request method to make the request as some default user
<raz> yeh i saw that, also the mocking stuff. i just prefer my tests dumb and straightforward.
<FromGitter> <jwaldrip:matrix.org> Is there support for ARM macs yet?
<raz> i don't want my tests to need tests :p
<FromGitter> <Blacksmoke16> ha, they're not *that* advanced
<FromGitter> <Blacksmoke16> test case stuff boils down to describe/it blocks anyway
<raz> yup, i didn't like the `def foo`-style
<raz> but it's all a matter of taste
<FromGitter> <Blacksmoke16> theres also this format
<FromGitter> <Blacksmoke16> ```test "it does something" do ⏎ # Your code here ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5fdd0bc9de608143152d5bfb]
<raz> hmm i dunno. didn't see that, and not sure what i'd gain from the subtly different syntax (`test` vs `describe`?) 🤔
<raz> so i just went and "ported" the little thinger i've always used ;)
<FromGitter> <Blacksmoke16> https://github.com/athena-framework/spec/blob/master/src/test_case.cr#L438-L457 ah i didnt make it public so doesnt show up in the docs
<raz> yeh well, i'm fine with what i got now. just normal crystal spec, with a few helpers sprinkled in to call endpoints
<FromGitter> <Blacksmoke16> 👌
<FromGitter> <Blacksmoke16> 🙆 lol what kind of emoji is this
<raz> looks like a guy airing his armpits
oddp has quit [Quit: quit]
_ht has quit [Remote host closed the connection]
teardown has quit [Remote host closed the connection]
teardown has joined #crystal-lang
<sorcus> Hi.
<sorcus> https://gist.github.com/MrSorcus/40236598de1ed11e0ff46a225ae07151 - why i get 'EVP_DecryptFinal_ex:bad decrypt'?
<sorcus> With `openssl enc` it's decrypted fine...
teardown has quit [Ping timeout: 240 seconds]
teardown has joined #crystal-lang