ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.24.2 | 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
<FromGitter> <Sija> @RX14 u here?
<RX14> yeah
<crystal-gh> [crystal] mohd-akram opened pull request #5970: Improve static compilation support (master...static-compile) https://git.io/vpqGh
<RX14> not any more
<RX14> it's 1am
<FromGitter> <girng> lmao
<RX14> b y e
<FromGitter> <Sija> yeah, it’s night mode for sure
<FromGitter> <j8r> @asterite thanks, my bad I need to put some other conditions
<FromGitter> <Sija> @RX14 I was hoping you’d explain me what do u mean with your comment regarding benchmarking this seemingly insignificant change
<FromGitter> <girng> i love CRYSTAL
<FromGitter> <BrucePerens> @bew fixed, thanks!
<FromGitter> <bew> @asterite I'm trying to understand why #5752 happens, but can't seems to find how private things works, do you remember sth about it?
<DeBot> https://github.com/crystal-lang/crystal/issues/5752 (Private alias in toplevel are not private)
<FromGitter> <BrucePerens> @RX14 If I create a string from a literal, does the data memory start from the readonly text of the ELF, and if I modify the string do I then get copy-on-write? This is an implementation detail that language users would not see.
<FromGitter> <bew> strings are immutable, so as soon as you do a string modification you get a new (allocated) string
greengriminal has joined #crystal-lang
greengriminal has quit [Quit: This computer has gone to sleep]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
duane has joined #crystal-lang
<FromGitter> <BrucePerens> @bew OK, fixed in the document. Thanks!
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
<FromGitter> <girng> is there something similar to PHP's `preg_replace($pattern, $replacement, $string);`, but with a limiter?
<FromGitter> <asterite> bew because aliases are expanded to whatever the aliased type is, eagerly, so the privateness is lost. Probably super hard to fix. I'd really like to remove private types from the language, they only make things complex
<FromGitter> <girng> basically, i want to limit the string to have 10 newlines, if anymore, they need to be replaced
<FromGitter> <asterite> Use gsub with a block and keep a counter
<FromGitter> <girng> ok
<FromGitter> <girng> let me try
<FromGitter> <girng> plz dont give answer
<FromGitter> <girng> i want to see if i can do this
<FromGitter> <asterite> Sure. I actually searched how to do that in Ruby :-P
<FromGitter> <girng> OMG...
<FromGitter> <girng> ok this is all i got https://play.crystal-lang.org/#/r/3wnf
<FromGitter> <girng> i give up, i don't UNDERSTAND why it's not working
<FromGitter> <girng> `Returns a String where all occurrences of the given string are replaced with the block's value.`
<FromGitter> <ezrast> What is the block's value if counter <= 10?
<FromGitter> <girng> im using an if statement, if counter is greater than 10, return "" (which is the returned for the block)
<FromGitter> <girng> which is a BLANK string...
<FromGitter> <girng> which is the blocks value a BLANK string
<FromGitter> <girng> return value*
<FromGitter> <ezrast> what result are you expecting?
<FromGitter> <girng> only to replace the `\n` atfter the counter is greater than 10
<FromGitter> <ezrast> so the block works properly when the counter is greater than 10, yes? It's the other case that's the problem.
<FromGitter> <girng> yes, if greater than 10, return "" that replaces the rest of the \n's
<FromGitter> <girng> `the given string are replaced with *the block's value*.`
<FromGitter> <ezrast> I'm not asking about when it's greater than 10
<FromGitter> <ezrast> do you know what value an if statement with a falsey condition evaluates to?
<FromGitter> <girng> it evalutes tof alse, which shouldn't return anything
<FromGitter> <girng> so iuno why its replacing all the \n's
<FromGitter> <girng> if it's not returning anything, `block` doesn't have a value to replace anything
<FromGitter> <ezrast> wrong on both counts
<FromGitter> <girng> ok
<FromGitter> <girng> well, that's what i got out of it from reading the description
<FromGitter> <girng> it quite literally says that so
<FromGitter> <girng> where all occurrences of the given *string are replaced with the block's value*.
<FromGitter> <ezrast> an if statement that doesn't execute evaluates to nil: https://carc.in/#/r/3wnl
<FromGitter> <ezrast> and nil is a value that can be returned
<FromGitter> <girng> ok that makes that sense
<FromGitter> <girng> however, why is nil replacing my string?
<FromGitter> <ezrast> every single \n gets replaced by the return value of your block. Knowing what you now know, what values is it possible for your block to return?
<FromGitter> <girng> so, all of them are replaced with a nil value, until greater than 10, of which are replaced by ""?
<FromGitter> <ezrast> yep
<FromGitter> <girng> but when i do puts or p
<FromGitter> <girng> it doesn't show NIL
That_Guy_Anon1 has joined #crystal-lang
<FromGitter> <girng> im so confused...
<FromGitter> <girng> but your EXAMPLE, it shows NIL
<FromGitter> <girng> ..............
<FromGitter> <ezrast> gsub runs `.to_s` on the thing to make it a string
<FromGitter> <girng> oh, your using `pp`?
<FromGitter> <girng> let me try that
<FromGitter> <girng> https://play.crystal-lang.org/#/r/3wnn still doesn't show `nil`
<FromGitter> <girng> i give up
<FromGitter> <ezrast> gsub can't just nest a random object inside a string; it has to convert the object into a string
<FromGitter> <ezrast> > > pp nil
<FromGitter> <ezrast> oops
That_Guy_Anon has quit [Ping timeout: 255 seconds]
<FromGitter> <ezrast> consider https://carc.in/#/r/3wno
That_Guy_Anon1 has quit [Remote host closed the connection]
<FromGitter> <girng> so when it gets converted to a string the `nil` isr eplaced, even when using `p`
<FromGitter> <girng> and @oprypin said `p` is a debugging tool
<FromGitter> <girng> why remove the nil's then
<FromGitter> <girng> not fair at ALL
<FromGitter> <ezrast> p isn't removing the nils
<FromGitter> <ezrast> gsub is converting them to their string representation
<FromGitter> <ezrast> it has to
That_Guy_Anon1 has joined #crystal-lang
<FromGitter> <ezrast> because gsub returns a string
<FromGitter> <girng> but p is a debugging tool, i should see them just like how the new lines get converted to \n
<FromGitter> <girng> because in my example, to me, it looks like my gsub is replacing all of them with "", which isn't true. it's actually replying some with nils
<FromGitter> <girng> but those are not printed or shown..
<FromGitter> <girng> even when using `p`
<FromGitter> <ezrast> no, it's replacing all of them with ""
<FromGitter> <girng> wat, it hought they were replaced with nil, then the rest are were the blank string ("")
<FromGitter> <ezrast> they're replaced with `nil.to_s`
<FromGitter> <girng> which translates to = ""?
<FromGitter> <ezrast> yes
<FromGitter> <girng> ic
<FromGitter> <girng> ok so the only way for gsub to work
<FromGitter> <girng> is i need to pass in the current string it's replacing through the block
<FromGitter> <girng> so i can return that string instead of nil ("")
<FromGitter> <girng> correct?
<FromGitter> <girng> how i can make it so the blocks value doesn't replace ANYTHING
<FromGitter> <ezrast> you already know what value it's replacing, "\n"
<FromGitter> <girng> yes but i need to return the string not a value if i want to keep it
<FromGitter> <girng> im only trying to convert the first 10 \n's
<FromGitter> <girng> wait, no
<FromGitter> <girng> i mean convert the \n's after there is 10
<FromGitter> <girng> why i use a counter
<FromGitter> <ezrast> replacing a "\n" with a "\n" is the same as not replacing it
<FromGitter> <girng> i got it ??
<FromGitter> <ezrast> there you go
<FromGitter> <girng> Ok i think i know what went wrong here
<FromGitter> <girng> i thought i was enumerating through every WORD. of which i am not. i'm only enumerating through the \n's lol
<FromGitter> <girng> sorry about that, thanks for your cordiality through this
rain1 has joined #crystal-lang
<FromGitter> <girng> i also though, it would automatically return "\n" and replace the nils . which is not true (my bad). that's why i tried to just do it with a 1 liner
<FromGitter> <girng> i also thought*
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
duane has quit [Ping timeout: 248 seconds]
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
binBASH has quit [Ping timeout: 276 seconds]
binBASH has joined #crystal-lang
Yxhuvud has quit [Quit: No Ping reply in 180 seconds.]
Yxhuvud has joined #crystal-lang
qard has joined #crystal-lang
qard has quit [Quit: qard]
<FromGitter> <girng> @asterite ok finally got it in a two liner: https://play.crystal-lang.org/#/r/3wp6 :)
<FromGitter> <girng> ty for help asterite n ezrast
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
<FromGitter> <girng> https://play.crystal-lang.org/#/r/3wpc/edit ⏎ ⏎ is this a bad way to check for the amount of linebreaks? split "makes an array" not sure if that is fine, opyrprin prob doesn't approve of this :P
<FromGitter> <Givralix> there's a count method in String @girng https://crystal-lang.org/api/0.24.2/String.html#count%28other%3AChar%29-instance-method
<FromGitter> <girng> im not sure if that will work https://play.crystal-lang.org/#/r/3wph
<FromGitter> <girng> looks like it counts the characters
<FromGitter> <Givralix> oh :/
<FromGitter> <girng> but i mean i can use the split("\n").size, but just curious if it's liek bad or just fine
<FromGitter> <girng> i should be ok right. the string im parsing will be less than 1500 in bytes
<FromGitter> <bararchy> Well, if you only want to count how many "\n" you have then its not really optimal to split, as you're creating a new array
<FromGitter> <girng> yeah, which is allocated on the heap right
<FromGitter> <girng> and puts pressure on GC?
<FromGitter> <bararchy> I'll do something like ` counter = 0 ; string.each_char { |c| counter +=1 if c == "\n" } `
<FromGitter> <girng> hmm same issue as before, it's a character
<FromGitter> <girng> \n is a word i guess
<FromGitter> <bararchy> '\n'
<FromGitter> <bararchy> I think it should work
<FromGitter> <girng> all false
<FromGitter> <girng> is there a `each_word` method?
<FromGitter> <bararchy> @girng https://play.crystal-lang.org/#/r/3wpn
<FromGitter> <bararchy> Working
<FromGitter> <girng> wtf
<FromGitter> <girng> why doens't mine work lol
<FromGitter> <bararchy> Because you use "\n" and not '\n'
<FromGitter> <girng> but it's looping through each character
<FromGitter> <girng> how does it match \n???
<FromGitter> <girng> WTFF
<FromGitter> <girng> that's two characters
<FromGitter> <bararchy> @girng \n is what is called 'control character' its not really 2 Char , its a single on called LF
<FromGitter> <bararchy> Its just visually looks like 2 Char
<FromGitter> <girng> interesting
<FromGitter> <bararchy> @girng also \s = space , \t = Tab
<FromGitter> <girng> so the each_char is better because it basically just increments a counter instead of making a whole new array and filling it
<FromGitter> <bararchy> Yeha
<FromGitter> <bararchy> And will work better for big Strings too
<FromGitter> <girng> i could prob create something cool where i can just do "".mycustommethodnamehere or something?
<FromGitter> <girng> then just call that on the string, and have it return counter orsomething
<FromGitter> <bararchy> @girng I think string.count will also work if you use '\n'
<FromGitter> <bararchy> As a Char
<FromGitter> <girng> little tiny library if you will
<FromGitter> <bararchy> Try it
<FromGitter> <girng> oh it does work
<FromGitter> <girng> @Givralix sorry about that, you were right
<FromGitter> <girng> `\n` for control characters im guessing, and "" for full / real strings
<FromGitter> <girng> \`\` i mean
<FromGitter> <girng> '' i mean
<FromGitter> <girng> wow, fail :D
PickleRick has joined #crystal-lang
PickleRick has left #crystal-lang [#crystal-lang]
flaviodesousa has joined #crystal-lang
alex`` has joined #crystal-lang
Ven`` has joined #crystal-lang
baweaver is now known as lemur
lemur is now known as baweaver
alex`` has quit [Ping timeout: 240 seconds]
That_Guy_Anon1 is now known as That_Guy_Anon
Ven` has joined #crystal-lang
Ven`` has quit [Ping timeout: 240 seconds]
<FromGitter> <sdogruyol> morning
That_Guy_Anon has quit [Ping timeout: 276 seconds]
<FromGitter> <girng> morning @sdogruyol how are u doing
<FromGitter> <sdogruyol> fine, and you girng
<FromGitter> <girng> very good
<FromGitter> <girng> learning more and more crystal everyday
<FromGitter> <girng> slow and steady wins the race
That_Guy_Anon has joined #crystal-lang
<FromGitter> <sdogruyol> yeah, seems like you're having fun 👍
<FromGitter> <girng> i'm breaking the conditioning of crappy core values nodejs indoctrinated me in. im sick of it
<FromGitter> <sdogruyol> like what?
<FromGitter> <straight-shoota> morning =)
<FromGitter> <girng> types
<FromGitter> <girng> there are soo many TYPES and they are all super important
<FromGitter> <sdogruyol> morning @straight-shoota
<FromGitter> <girng> to know which type does what. in nodejs it seems like i never knew anything besides a string or number
<FromGitter> <sdogruyol> I feel you...I've done some Nodejs back in 0.8 - 0.10 days
<FromGitter> <sptorin_twitter> How I can get all matches from regexp, like flag /regexp/g? For example need get all numbers from line: `"1q2w".match(/\d+/).not_nil!.to_a` - this get only first match
<FromGitter> <sdogruyol> glad that I escaped callback hell
<FromGitter> <girng> Agree!
Jenz has joined #crystal-lang
That_Guy_Anon has quit [Ping timeout: 240 seconds]
Jenz has left #crystal-lang [#crystal-lang]
Ven` has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven`` has joined #crystal-lang
<FromGitter> <sdogruyol> wtf...the new reddit design is so ugly..
<FromGitter> <girng> ikr
<FromGitter> <girng> dat popup when u click on a thread rofl
<FromGitter> <sdogruyol> thanks god there's a rollback to old design
<FromGitter> <girng> i only use reddit cuz programmingcirclejerk and crystal lang sub
<FromGitter> <sdogruyol> same, just some subreddits
<FromGitter> <girng> yeah thank goodness they let u opt out of it lol
<FromGitter> <girng> i would be pretty mad...
<FromGitter> <girng> well, i just wouldn't visit the site anymore. more time in sublime for crystal :D
<FromGitter> <girng> turn negative into a positive, right!?
<FromGitter> <sdogruyol> lol
rohitpaulk has quit [Ping timeout: 264 seconds]
rohitpaulk has joined #crystal-lang