ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.32.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
ur5us has joined #crystal-lang
return0e has quit [Remote host closed the connection]
<FromGitter> <Blacksmoke16> heres prob a stupid question, how do you get form data params from a request?
<FromGitter> <Blacksmoke16> i.e. `curl --request POST --url http://localhost:3000/login --header 'content-type: application/x-www-form-urlencoded' --data email=example@gmail.com curl --request POST --url http://localhost:3000/login --header 'content-type: application/x-www-form-urlencoded' `
<FromGitter> <Blacksmoke16> i.e.
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e3a1a92fe0e6f74e901637b]
<FromGitter> <Blacksmoke16> `request.query_params # => HTTP::Params(@raw_params={})`
<FromGitter> <Blacksmoke16> nvm, its in the body, duh
<alex``> when implementing an iterator, I have `next` returning `@time += @step`
<alex``> but then, I never have the current begin value when doing object.each, no?
* FromGitter * tenebrousedge nods
<alex``> what is the correct way to do?
<alex``> value = @time; @time += @step; value looks quite verbose
<alex``> oh no
<alex``> there is not something to increment but return the current value?
<FromGitter> <tenebrousedge> you could initialize @time to `@time - @step`
<alex``> the time.beging would be inacurate
<FromGitter> <tenebrousedge> or rather `@begin - @step`
<alex``> step can be changed in the object life
<alex``> time = @time
<alex``> @time += @step
<alex``> time
<alex``> I have fixed my time range
<alex``> but I'm not happy with the way I do it
<alex``> :/
<FromGitter> <ezrast_gitlab> `@time.tap{ @time += @step }`?
<FromGitter> <tenebrousedge> I don't think that does what you want it to do
<FromGitter> <tenebrousedge> hmm, maybe
* alex`` confused with the tap modifying self in the block returning unchanged time
<FromGitter> <tenebrousedge> it doesn't
<FromGitter> <tenebrousedge> it works for integers, but not time
<FromGitter> <tenebrousedge> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5e3a21f173ddad4acd924e44]
<alex``> it does not work yeah
<FromGitter> <ezrast_gitlab> Oh yeah value types only I guess
<alex``> still returning next value
<alex``> I guess there is no shortcut to my 3 lines
<FromGitter> <tenebrousedge> you could initialize @time in `next`: ⏎ ⏎ ```def next ⏎ @time ||= @begin - @step ⏎ @time += @step ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5e3a22aef301780b8367ddcb]
<alex``> hm
<FromGitter> <tenebrousedge> you'd have to declare `@time : Time` in the class body somewhere
<alex``> isn't `time = @time; @time += @step; time` more idiomatic?
<FromGitter> <tenebrousedge> `||=` is pretty idiomatic
<alex``> @tenebrousedge if you have to implement an iterator for integer, how you would write `next`?
<alex``> returning the next value?
<alex``> of current
<alex``> s/of/or/
<alex``> the example of crystal makes it return 0 but it doesn't show what if produced value would be used
<FromGitter> <tenebrousedge> I mean, I'd probably do what I outlined there. But Crystal does what you suggest https://github.com/crystal-lang/crystal/blob/master/src/range.cr#L374
<FromGitter> <ezrast_gitlab> Hm, tapping works if you do ⏎ ⏎ ```b = Time.utc ⏎ (b2 = b).tap { b += 5.hours }``` [https://gitter.im/crystal-lang/crystal?at=5e3a2a2c58f02e3497634c6f]
<FromGitter> <tenebrousedge> ew
<FromGitter> <ezrast_gitlab> which is weird; Time actually is a value type so I don't know why it doesn't behave the same as Int32
<FromGitter> <tenebrousedge> I would assume that `Time` has internal state, and `Int` doesn't
alex`` has quit [Quit: WeeChat 2.7]
alexherbo2 has quit [Quit: The Lounge - https://thelounge.chat]
ur5us has quit [Ping timeout: 272 seconds]
_ht has joined #crystal-lang
_ht has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
<FromGitter> <kingsleyh> hi - is it possible to specify multiple scripts for postinstall for shards? the examples only show a since postinstall
return0e has joined #crystal-lang
Yxhuvud has quit [Ping timeout: 265 seconds]
chachasmooth_ has quit [Ping timeout: 246 seconds]
chachasmooth has joined #crystal-lang
<FromGitter> <j8r> @tenebrousedge is right
<FromGitter> <j8r> @ezrast_gitlab In you example, I don't get why you use tap nor `b2 = b`
<FromGitter> <j8r> maybe it's a typo, because doing `(b = b2).tap { b += 5hours }` won't modify `b`
<FromGitter> <j8r> It could be possible to modify an ivar of `Time`, but the object is made immutable
ur5us has quit [Ping timeout: 248 seconds]
chachasmooth_ has joined #crystal-lang
chachasmooth has quit [Ping timeout: 272 seconds]
alex` has joined #crystal-lang
alex` is now known as Guest56192
Guest56192 is now known as alex``
<alex``> I have a question about the option parser; if I want to add a command-line program with default options `<program> --<option> <value>`, does adding the same option after override it?, i.e. `<program> "$@" --<option> <value>` vs `<program --<option> <value> "$@"`
<alex``> some option could cumulate, I don’t know if it is possible, for example passing multiple options like `git -c option1=value -c option2=value`
<alex``> does it run multiple times, or a single
<FromGitter> <Blacksmoke16> @kingsleyh not directly, but you can do like `make && make something_else && make install` etc
<FromGitter> <mavu> Is anyone here using scry with CoC in vim?
melthelesbian has quit []
melthelesbian has joined #crystal-lang
dostoyevsky has joined #crystal-lang
alexherbo2 has joined #crystal-lang
return0__ has joined #crystal-lang
return0e has quit [Ping timeout: 265 seconds]
<FromGitter> <ezrast_gitlab> @j8r I'm not actually trying to solve a problem anymore; I just don't understand why `a` and `b` behave inconsistently here, and why line 14 gives the value of `c` rather than `c2`: https://carc.in/#/r/8ikr
<FromGitter> <ezrast_gitlab> What about it?
<FromGitter> <j8r> @ezrast_gitlab what is inconsistent?
<FromGitter> <j8r> for me it is
<FromGitter> <tenebrousedge> I was going to contrast that with the Int#+ method, but apparently those are handled by LLVM directly
<FromGitter> <j8r> avoid avoid different scoped variable having the same name
<FromGitter> <ezrast_gitlab> @j8r `a.tap` returns the old value of a, `b.tap` returns the new value of b, and `(c2 = c).tap` returns a value that never belongs to c2 at all
<FromGitter> <j8r> @ezrast_gitlab https://play.crystal-lang.org/ please :)
<FromGitter> <ezrast_gitlab> I posted a carc link above but https://play.crystal-lang.org/#/r/8ikz
<FromGitter> <tenebrousedge> this is even more fun https://carc.in/#/r/8il0
<FromGitter> <tenebrousedge> and in Ruby: https://repl.it/repls/ColorfulVelvetyGames
<FromGitter> <straight-shoota> In your examples `tap` actually has no effect on anything. It just yields `self` to the block which isn't used as a block argument.
<FromGitter> <straight-shoota> `p x .tap { x += y }` is equivalent to `p x; x += y`
<FromGitter> <tenebrousedge> except that `Time` can be mutated by the block and `Int32` can't
<FromGitter> <ezrast_gitlab> @tenebrousedge += doesn't mutate; it makes a copy and reassigns the variable
<FromGitter> <ezrast_gitlab> @straight-shoota no it isn't: https://play.crystal-lang.org/#/r/8il5
<FromGitter> <straight-shoota> Yeah, that was simplified.
<FromGitter> <tenebrousedge> @ezrast_gitlab is there some other operative definition of mutation here?
<FromGitter> <straight-shoota> The point is, this has nothing to do with blocks.
<FromGitter> <tenebrousedge> who said it did?
<FromGitter> <straight-shoota> The examples all use `tap`
<FromGitter> <tenebrousedge> because it returns `self`
<FromGitter> <straight-shoota> Yes, it can be used for demonstration, but it's not that cause
<FromGitter> <tenebrousedge> and the difference is that `self` with the integers will always be the same value, where `self` with a `Time` object can have a different value
<FromGitter> <straight-shoota> I understood that this was the assumption
<FromGitter> <straight-shoota> Int32 is a primitive and Time is a struct. `+=` on a primitive really just assigns a new value.
<FromGitter> <tenebrousedge> right
<FromGitter> <straight-shoota> But calling methods on a struct to modify its properties actually does some magic to actually alter the existing struct's value instead of assigning a completely new struct
* FromGitter * tenebrousedge nods
<FromGitter> <straight-shoota> So it behaves a bit like a reference
<FromGitter> <ezrast_gitlab> 1) doesn't modify in place though
<FromGitter> <ezrast_gitlab> should be: + doesn't modify in place though
<FromGitter> <straight-shoota> Yeah that's not what you'd expect from a `+` method
<FromGitter> <straight-shoota> `+` returns an altered instance, `+=` assigns the altered instance
<FromGitter> <tenebrousedge> so I can't speak to how Crystal/LLVM handles these things, but in Ruby integers are not objects in the same sense that everything else is; they're more like locations in memory that are interpreted as numerical values. There is no way to change what that memory value represents, so `+=` doesn't do that
<FromGitter> <tenebrousedge> `+=` is something that happens to the variable, not to the underlying object
<FromGitter> <straight-shoota> Structs are objects but on the stack. So technically, they'd behave like primitives. But there are a few extra rules in the language that alter that behaviour to make it better usable. When you call a method on a struct which changes its internal state, that change should not only affect a copy but the original value where the method was called on.
return0__ has quit [Read error: Connection reset by peer]
return0e has joined #crystal-lang
melthelesbian has quit [Ping timeout: 252 seconds]
JuanMiguel has joined #crystal-lang
JuanMiguel has quit [Client Quit]
ur5us has joined #crystal-lang
<FromGitter> <ezrast_gitlab> So `Time` and `+` were a distraction and I apologize for not factoring them out earlier. This is 100% a bug: https://play.crystal-lang.org/#/r/8im3
_ht has joined #crystal-lang
<FromGitter> <straight-shoota> Yeah, `self` in `#tap` references a stack value when it's no longer available.
HumanG33k has joined #crystal-lang
HumanG33k has quit [Remote host closed the connection]
HumanG33k has joined #crystal-lang
<FromGitter> <dscottboggs_gitlab> oh buddy! that's fun!
_ht has quit [Remote host closed the connection]
<FromGitter> <j8r> mint-lang on HN! https://news.ycombinator.com/item?id=22246615
<FromGitter> <tenebrousedge> again?
<FromGitter> <dscottboggs_gitlab> First I've heard of it. Looks pretty nice at first-glance
Human_G33k has joined #crystal-lang
HumanG33k has quit [Ping timeout: 260 seconds]
sagax has quit [Remote host closed the connection]
sagax has joined #crystal-lang
melthelesbian has joined #crystal-lang
lunarkitty has quit [Ping timeout: 245 seconds]
lunarkitty has joined #crystal-lang
ur5us has quit [Ping timeout: 245 seconds]
ur5us has joined #crystal-lang
chachasmooth_ has quit [Quit: Quit]
chachasmooth has joined #crystal-lang
<FromGitter> <PercussiveElbow> Does anyone know if the XML stdlib module isn't safe to use with the parallelism preview? Parsing different HTTP response in two separate fibres using XML.parse_html and I'm getting invalid mem access exceptions. The issue only occurs with parallelism flag though, same code without the flag works fine.
<FromGitter> <PercussiveElbow> Thinking it may be related to https://github.com/crystal-lang/crystal/pull/8707 but the two fibres aren't sharing data, they're parsing totally separate responses.
<FromGitter> <tenebrousedge> I would assume just about everything isn't thread-safe
<FromGitter> <PercussiveElbow> Apologies if this is too tech support-y, loving the language :)
<FromGitter> <PercussiveElbow> Yeah I had assumed that much already, but I (probably naively) thought it would be fine so long as the two fibres weren't reading/writing the same response variable
<FromGitter> <tenebrousedge> I would naively think that as well
<FromGitter> <tenebrousedge> but invalid mem access usually means that such things are not fine. But do you have an isolateable test case?
<FromGitter> <Daniel-Worrall> I don't know if the http calls are thread safe so it could end up trying to look at the same response
<FromGitter> <kingsleyh> I use Mint a lot - for all my projects - I love it