<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> 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?
<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]
<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`
<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 ?
<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
<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