ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.23.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
tilpner has joined #crystal-lang
yopp has joined #crystal-lang
maxpowa has joined #crystal-lang
olbat[m] has joined #crystal-lang
<FromGitter> <codenoid> hi, how to define json value inside crystal variable ?
<FromGitter> <codenoid> `{"key":"val","key":"val"}` , yup, crystal doesnt support single quote `'`
<Papierkorb> hash syntax is `{ "foo" => "bar" }` - Note the hashrocket
<FromGitter> <codenoid> a json value
<FromGitter> <codenoid> its a json
braidn[m] has joined #crystal-lang
TheGillies has joined #crystal-lang
rizo[m] has joined #crystal-lang
thelonelyghost has joined #crystal-lang
vegai has joined #crystal-lang
byteflame has joined #crystal-lang
Renich[m] has joined #crystal-lang
jplatte has joined #crystal-lang
watzon has joined #crystal-lang
sija[m] has joined #crystal-lang
sz0 has quit [Quit: Connection closed for inactivity]
w-p has joined #crystal-lang
onionhammer has quit [Quit: WeeChat 1.7]
onionhammer has joined #crystal-lang
hightower2 has quit [Remote host closed the connection]
<FromGitter> <jwoertink> Has anyone ran in to any issues naming a class the same as something that's in the crystal stdlib?
<FromGitter> <jwoertink> I have a crecto model named `Event`, but when I try and use it, I get `Event is not a class, it's a module`
w-p has quit [Ping timeout: 248 seconds]
<FromGitter> <cevarief> Any update regarding to support multi threading (parrarel) ?
<FromGitter> <jwoertink> The language isn't really moving that fast anymore. I doubt much progress has been made on that. There's this branch https://github.com/crystal-lang/crystal/tree/thread-support which hasn't been updated in a while.
<FromGitter> <jwoertink> I would urge anyone that has experience with that sort of stuff to hop in and knock out some issues to help out :)
<FromGitter> <johnjansen> @jwoertink you have named your model the same as a module from somewhere else ;-)
<FromGitter> <jwoertink> haha. I know
<FromGitter> <jwoertink> I want my model named `Event`
<FromGitter> <jwoertink> because it's like things you go out and do, parties, concerts, games, etc...
<FromGitter> <jwoertink> I had to namespace my model so it will work. Not horrible
DTZUZO has quit [Read error: Connection reset by peer]
DTZUZO has joined #crystal-lang
DTZUZO has quit [Read error: Connection reset by peer]
DTZUZO has joined #crystal-lang
mike_ has joined #crystal-lang
mike_ has quit [Client Quit]
_whitelogger has joined #crystal-lang
rizo[m] has joined #crystal-lang
byteflame has joined #crystal-lang
<FromGitter> <johnjansen> @jwoertink why dont you put all your models into a namespace so you can still use event … im assuming that wont break anything
<FromGitter> <jwoertink> That's what I ended up doing
<FromGitter> <jwoertink> it's a little annoying, but not horrible
<FromGitter> <Qwerp-Derp> I'm not sure if I'm doing this right...
<FromGitter> <Qwerp-Derp> Is anyone with a decent knowledge of C (and preferably GTK+) on?
<FromGitter> <Qwerp-Derp> I've implemented all the functions for GApplication
<bmcginty> Qwerp-Derp: Have you tried running the gtk and gobject stuff through the libgen shard?
<FromGitter> <sdogruyol> Morning everyone
alex`` has joined #crystal-lang
<FromGitter> <bararchy> Morning :)
<FromGitter> <codenoid> hi, how to statically define this value ( `{"key":"val","key":"val"} ` ) inside crystal variable
<FromGitter> <sdogruyol> @codenoid ⏎ ⏎ ```STATIC_VAR = {"key":"val","key":"val"}``` [https://gitter.im/crystal-lang/crystal?at=5992ab3b162adb6d2ef851b6]
<FromGitter> <coderbuzz> Morning...
bmcginty has quit [Ping timeout: 240 seconds]
<FromGitter> <codenoid> nope, wont work @sdogruyol
<FromGitter> <codenoid> it's a json value, please, ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5992b1b8c101bc4e3a1c1644]
<FromGitter> <sdogruyol> @codenoid https://play.crystal-lang.org/#/r/2j4o
bmcginty has joined #crystal-lang
bmcginty has quit [Ping timeout: 240 seconds]
<FromGitter> <Qwerp-Derp> bmcginty Whoa, that's neat :)
<FromGitter> <codenoid> my static value is `{"key":"val","key":"val"}` not `{"key" => "val","key" =>"val"}`
<FromGitter> <sdogruyol> the first is a `NamedTuple` the second is a `Hash`
<FromGitter> <Qwerp-Derp> @codenoid `=>` is Crystal syntax for key-value pairs
bmcginty has joined #crystal-lang
<FromGitter> <codenoid> but its json value :(
<FromGitter> <Qwerp-Derp> Ohhhhh
<FromGitter> <Qwerp-Derp> Sorry, my mistak
<FromGitter> <sdogruyol> @codenoid i still don't get your point
<FromGitter> <Qwerp-Derp> I don't think you can do that, You might have to wrap it around a `toJSON` thing
<FromGitter> <sdogruyol> just use a `String` then
<FromGitter> <bew> @codenoid you want `var = %({"your": "json"})`
<FromGitter> <codenoid> why crystal didnt read first `"` and last `"` as a opening and closing string
<FromGitter> <codenoid> @bew cool thanks @bew
<FromGitter> <bew> 😄
<FromGitter> <bew> Because `%()` `%[]` and `%<>` are other string separators
<FromGitter> <drujensen> or you could escape all the inner quotes ```"\"key\": \"val\",\"key2\": \"val\”}”``` but that is some ugly code ;)
_whitelogger has joined #crystal-lang
bmcginty has quit [Ping timeout: 255 seconds]
bmcginty has joined #crystal-lang
<FromGitter> <G4BB3R> a ⏎ ⏎ ```test``` [https://gitter.im/crystal-lang/crystal?at=5992c0f74bcd78af56457856]
<FromGitter> <G4BB3R> I need help, very beginner here. I am using Crecto, look my Repo.cr ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ After a few minutes waiting it throws an huge exception: ... [https://gitter.im/crystal-lang/crystal?at=5992c16a76a757f808a6e247]
<FromGitter> <krypton97> To be honest, I find it easier to work directly with the stdlib than the orm
<FromGitter> <sdogruyol> @fridgerator can definitely help with that @G4BB3R
<FromGitter> <G4BB3R> @krypton97 can I see a snippet of inserting/querying with your method? :)
<FromGitter> <sdogruyol> it's written by the author of crecto :D
<FromGitter> <sdogruyol> would definitely help you
<FromGitter> <krypton97> This is for inserting
<FromGitter> <krypton97> begin # assert for unique fiels ⏎ SQLITE.exec "INSERT INTO users VALUES (?, ?, ?, ?)", SecureRandom.uuid, username, email, password ⏎ rescue ⏎ message = "Field already taken" ⏎ render "views/register.ecr" ... [https://gitter.im/crystal-lang/crystal?at=5992c4394bcd78af5645872d]
<FromGitter> <krypton97> I'll paste for querying too
<FromGitter> <krypton97> res = SQLITE.query_one?("SELECT id, username, email, password FROM users WHERE username = ?", username, as: {String, String, String, String}) ⏎ if !res || res.last != password ⏎ message = "Invalid username or password" ⏎ render "views/login.ecr" ⏎ else ... [https://gitter.im/crystal-lang/crystal?at=5992c47b76a757f808a6f09e]
<FromGitter> <krypton97> This is it pretty much all.
<FromGitter> <sdogruyol> @krypton97 I also prefer your way
<FromGitter> <sdogruyol> SQL is simple enough :)
<FromGitter> <G4BB3R> damn now I can't decide xD ⏎ I was trying crecto because it seems to be productive ⏎ but this is very simple too
<FromGitter> <krypton97> Working with databases is one of the reasons I decided not to use go
<Papierkorb> krypton97, sidenote, please don't write a users table like that for production purposes.
<FromGitter> <G4BB3R> why?
<FromGitter> <krypton97> anyway, I'm working on an auth sample with kemal
<FromGitter> <krypton97> ikr lol
<FromGitter> <G4BB3R> I am using Kemal too :)
<FromGitter> <G4BB3R> The else after rescue is when everything is fine, without exceptions?
<Papierkorb> yes
<FromGitter> <G4BB3R> Great. thanks people
linuksz has joined #crystal-lang
bmcginty has quit [Ping timeout: 248 seconds]
bmcginty has joined #crystal-lang
<linuksz> what's wrong with it? (the last 3 line contains the error, but i don't know what's wrong)
<FromGitter> <straight-shoota> @linukzs What's the error message?
<FromGitter> <bew> I think you want `input: nil` in the process creation line
<linuksz> input: nil works
<linuksz> but why should it be nil when i want to use it
<linuksz> ?
<FromGitter> <bew> it's kinda weird we know (it'll be changed soon), specifying nil will allows you to control the process. Using true will just let the terminal (where you run your program) interact witg the process, not your program.. (makes sense?)
<linuksz> so it always controls the input, but when it's true, i can write text for dmenu from the terminal?
<linuksz> and when it's nil, it can be accessed from the program?
<FromGitter> <bew> Exactly
<linuksz> can i do the same thing with the output of the program?
<FromGitter> <bew> It'll be clearer when #4445 is merged
<Papierkorb> ... Or just `curl http://example.com` - Yes, with backticks.
<linuksz> but why do the above example use a memory io
<linuksz> ?
<FromGitter> <G4BB3R> What is the idiomatic way to transform (a | nil) into a ? I mean, giving it a default value if nil
<FromGitter> <bew> It depends, how do you assign a ?
<Papierkorb> G4BB3R, `a || "some default"`
<Papierkorb> Watch out for when used on a `Bool?`
<FromGitter> <Qwerp-Derp> Has anyone used libgen?
<bmcginty> Qwerp-Derp: Yes. I couldn't get it to remove common prefixes from things, but that was my only issue.
<crystal-gh> [crystal] RX14 closed pull request #4773: Expand: show expanded macro name and its location (master...feature/crystal-expand/show-expanded-macro-name-and-location) https://git.io/v7R44
<FromGitter> <Qwerp-Derp> Hmmm, what do I put in the "descriptions" field?
<FromGitter> <Qwerp-Derp> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5992d2d34bcd78af5645c4b7]
<FromGitter> <Qwerp-Derp> Currently I have this, but it doesn't work
hightower2 has joined #crystal-lang
early has quit [Quit: Leaving]
<FromGitter> <Qwerp-Derp> bmcginty?
<FromGitter> <Qwerp-Derp> I'm confused as to why this syntax: ⏎ ⏎ ```a, b : Int32``` [https://gitter.im/crystal-lang/crystal?at=5992d3dd1c8697534abd029a]
<FromGitter> <Qwerp-Derp> is available in `struct`s, but not `class`es
<travis-ci> crystal-lang/crystal#dc877a8 (master - Expand: show expanded macro name and its location (#4773)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/264696038
<travis-ci> crystal-lang/crystal#dc877a8 (master - Expand: show expanded macro name and its location (#4773)): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/264696038
early has joined #crystal-lang
<FromGitter> <Qwerp-Derp> Hello?
<FromGitter> <sdogruyol> hi @Qwerp-Derp
<FromGitter> <Qwerp-Derp> Hello @sdogruyol!
<FromGitter> <Qwerp-Derp> I'm having problems with libgen, can you help?
<FromGitter> <sdogruyol> sorry, I don't have much experience with libgen @Qwerp-Derp
<FromGitter> <cevarief> Is there any amber video tutorial i can watch 😄 ?
<FromGitter> <G4BB3R> There is no way to load from DB and it receive a json with correct column names instead of list with values?
<RX14> "a json" do you mean a named tuple?
<FromGitter> <krypton97> you can get the result as a tuple
<FromGitter> <krypton97> I made a function that converts that tupple to json
<RX14> you want something like this: https://github.com/crystal-lang/crystal-db/pull/56
<FromGitter> <krypton97> ===converts tuples to json=== ⏎ ⏎ def to_json(keys : Tuple, values : Tuple) : String ⏎ if keys.size != values.size ⏎ puts "Different tuple sizes!" ... [https://gitter.im/crystal-lang/crystal?at=5992de7a80d90ca024fe5123]
<FromGitter> <krypton97> I
<FromGitter> <krypton97> ex: to_json({"name", "email",}tuple)
<RX14> please please don't do that
<RX14> that's no escaping at all
<RX14> use JSON.build
<FromGitter> <krypton97> Not sure if needed
<FromGitter> <krypton97> Yeah I've used that before
<FromGitter> <krypton97> require "json" ⏎ ⏎ string = JSON.build do |json| ⏎ json.object do ⏎ json.field "name", "foo" ... [https://gitter.im/crystal-lang/crystal?at=5992dedf1c8697534abd31ac]
<RX14> it's always needed
<FromGitter> <krypton97> In my case the data is queried from the database
<FromGitter> <krypton97> not directly from the user
<RX14> and where does the data in the db come from?
<RX14> and what if you make a mistake
<FromGitter> <straight-shoota> data from the database might include special characters which need to be escaped in JSON
<RX14> it's very little more effort to use JSON.build there
<RX14> JSON.build { |json| json.object { key.zip(values).each { |key, value| json.field key, value } } }
<FromGitter> <straight-shoota> And it's probably even faster than concatenating strings...
<FromGitter> <krypton97> I guess I'ma wrap the json builin
<FromGitter> <codenoid> hmm, https://play.crystal-lang.org/#/r/2j68
<FromGitter> <krypton97> looks nice
<FromGitter> <G4BB3R> @FromIRC ⏎ ⏎ > **<RX14>** you want something like this: https://github.com/crystal-lang/crystal-db/pull/56 ⏎ It does not works yet, right? I tried it and it gives an error "DB::Database#query_all' is expected to be invoked with a block, but no block was given" [https://gitter.im/crystal-lang/crystal?at=5992dfc2210ac26920859023]
<RX14> yes that PR is not merged yet
<FromGitter> <codenoid> it's a `Valid JSON`
<FromGitter> <codenoid> but why, 😟
<RX14> because crystal play is broken
<FromGitter> <codenoid> ```code paste, see link``` ⏎ ⏎ actually [https://gitter.im/crystal-lang/crystal?at=5992e0632723db8d5ea69e15]
<RX14> why did you gsub ' out?
<RX14> that's so weird
<FromGitter> <codenoid> idk :O
<FromGitter> <codenoid> eh
<RX14> it's entirely unneeded
<FromGitter> <codenoid> is i did it ?
<FromGitter> <codenoid> yes,
<FromGitter> <Qwerp-Derp> Argh, does anyone on have any experience with libgen?
<FromGitter> <Qwerp-Derp> I don't know why my thing doesn't work
<RX14> also you want to use sub not gsub @codenoid
<FromGitter> <codenoid> aahh
<RX14> you want to remove the first instance of angular.callbacks._0( not every instance
<RX14> @codenoid ignore that error on crystal play
<RX14> it is nothing to do with your code
<RX14> it is broken
<FromGitter> <codenoid> not about crystal playground
<FromGitter> <codenoid> but about json parser and my json value
<RX14> Unexpected char '/' at 1:36441 is the correct error
<RX14> not that on in play.crystal-lang.org
<FromGitter> <codenoid> i dont find anything
<RX14> it's most likely an escaping issue in the string
<RX14> yup
<RX14> you need a %q string
<RX14> so that backslash escapes are processed properly
<RX14> it's literally because you pasted it into a string literal
<RX14> that \ chars needed to be doubly escaped
<RX14> or use %q
<FromGitter> <codenoid> HAHHAAAA
<FromGitter> <codenoid> IT'S WORK
<FromGitter> <codenoid> YOU SAVE MY LIFE RX14
<FromGitter> <codenoid> wait, i''l write some blog post
linuksz has quit [Remote host closed the connection]
<RX14> what?
<FromGitter> <krypton97> mvp
DTZUZO has quit [Ping timeout: 260 seconds]
<FromGitter> <sdogruyol> Congrats @codenoid
DTZUZO has joined #crystal-lang
DTZUZO has quit [Ping timeout: 260 seconds]
DTZUZO has joined #crystal-lang
<FromGitter> <bew> bmcginty, about your issue with libgen not removing common prefixes, I just had the same and fixed it: you need a rename rule, that remove the prefix from the fun name
miihael has joined #crystal-lang
snsei has joined #crystal-lang
miihael has quit [Quit: Page closed]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
sz0 has joined #crystal-lang
hightower has joined #crystal-lang
hightower is now known as hightower4
greengriminal has joined #crystal-lang
hightower4 has quit [Ping timeout: 276 seconds]
snsei has quit [Remote host closed the connection]
snsei has joined #crystal-lang
greengriminal has quit [Quit: Leaving]
<alex``> How to get the API documentation for offline usage?
<FromGitter> <bew> you can generate the documentation from the crystal code with `make doc`
<alex``> Thanks
<FromGitter> <kazzkiq> 😢 `Can't use Hash(K, V) in unions yet, use a more specific type`
saadq has quit [Ping timeout: 255 seconds]
linuksz has joined #crystal-lang
<FromGitter> <bararchy> I wish we had this project in Crystal
<FromGitter> <bew> what are you waiting for? go ahead :D
DTZUZO has quit [Ping timeout: 240 seconds]
<FromGitter> <fridgerator> the world is your oyster
DTZUZU has quit [Quit: WeeChat 1.9]
<FromGitter> <Jeremy-Pichon> Hi guys, I hope you are all doing well! :) ⏎ I need some help about the langage. ⏎ Can we translate a String to Symbol ? ⏎ My problem is: I get a list of file in a folder, and I want to call the function inside (that have the same name of the file). [https://gitter.im/crystal-lang/crystal?at=59932a2b4bcd78af56477fef]
<FromGitter> <Jeremy-Pichon> thanks for the answer
<FromGitter> <johnjansen> You can't dynamically create symbols. When you compile your program, each symbol gets assigned a unique number.
<Papierkorb> Jeremy-Pichon, there's no `#send` like in Ruby either. Use a `case` statement instead.
<FromGitter> <Jeremy-Pichon> ok, thanks a lot 👍
saadq has joined #crystal-lang
sstory has joined #crystal-lang
sstory has left #crystal-lang [#crystal-lang]
<crystal-gh> [crystal] txe opened pull request #4832: Win: define Win32 API functions (master...win-lib) https://git.io/v7Fcz
<FromGitter> <LuckyChicken91_twitter> is there a method like .sub but that its adding something?
saadq has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> do you have an example input/output?
<oprypin> LuckyChicken91_twitter, i noticed that last time you used sub(index, "") and you see it only as deleting something maybe? well obviously it doesnt have to be that way
<FromGitter> <LuckyChicken91_twitter> okay
<FromGitter> <LuckyChicken91_twitter> im still a bit conditined to ruby that you can do string[0] += "text" but unfortunately this doesnt work in crystal
<FromGitter> <johnjansen> string[0] returns a char, not a string
<FromGitter> <LuckyChicken91_twitter> i know
<FromGitter> <bew> If I understand correctly, you want to insert some text at a specific position of the string
<FromGitter> <LuckyChicken91_twitter> yes
<FromGitter> <LuckyChicken91_twitter> excatly
<FromGitter> <bararchy> btw, why don't we have `String#gsub!()` ?
<FromGitter> <LuckyChicken91_twitter> yes! why?
<RX14> strings aren't mutable
<FromGitter> <bararchy> Oh
<FromGitter> <LuckyChicken91_twitter> ouh
saadq has joined #crystal-lang
saadq has quit [Ping timeout: 246 seconds]
saadq has joined #crystal-lang
imusingnotepad has joined #crystal-lang
<oprypin> LuckyChicken91_twitter, so, like, when you decide what you actually want to do, maybe you could ask that, instead of "how can I do this weird thing from Ruby"
<FromGitter> <LuckyChicken91_twitter> okay will do this next time
<FromGitter> <LuckyChicken91_twitter> but im saying sometimes "because this is not working: *Some code*" so that people better understand what im meaning
<FromGitter> <sdogruyol> Ruby ❤️
<oprypin> Ruby 😠
<FromGitter> <sdogruyol> Woot
<FromGitter> <LuckyChicken91_twitter> ruby is awesome
<FromGitter> <elorest> Also love ruby and crystal.
greengriminal has joined #crystal-lang
<Papierkorb> *cough* String#replace()
<Papierkorb> Err String#insert
<FromGitter> <LuckyChicken91_twitter> how could i check if theres an "ehh" at the beginning of the string "ehhweeheehh" with an if-query? because this is not working: `if mystring[0..2]=="ehh"`
<FromGitter> <bew> you can use `String#starts_with?`
<FromGitter> <LuckyChicken91_twitter> oh nice
<RX14> not sure why your query wouldn't work though?
<FromGitter> <elorest> Yeah you could but also that code you wrote does work. https://carc.in/#/r/2j8m
<FromGitter> <LuckyChicken91_twitter> oh ehm..
<Papierkorb> But use String#start_with? in any case.
<FromGitter> <LuckyChicken91_twitter> okay
<FromGitter> <elorest> Working: https://carc.in/#/r/2j8n but yeah still use start_with
DTZUZO has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> why cant i detect a "\n"? https://carc.in/#/r/2j90
linuksz has quit [Quit: Leaving.]
<Papierkorb> LuckyChicken91_twitter, what have you tried to resolve the issue?
<FromGitter> <LuckyChicken91_twitter> im trying to check if theres an "\n" at the beginning
<Papierkorb> We see that. But what have you tried to resolve the issue of it "not working"?
<Papierkorb> If anything, you should have another look what we just told you
snsei has quit [*.net *.split]
snsei has joined #crystal-lang
<FromGitter> <LuckyChicken91_twitter> the issue isnt resolved yet
<FromGitter> <elorest> https://carc.in/#/r/2j97
<FromGitter> <LuckyChicken91_twitter> ooh thank you very much
<FromGitter> <elorest> Or with `starts_with?` ⏎ https://carc.in/#/r/2j9c
<FromGitter> <bew> @elorest Also works with a `Char`, => no String object allocation (https://carc.in/#/r/2j9d)
greengriminal has quit [Quit: This computer has gone to sleep]
<Papierkorb> bew, Except for the additional branching in the string version, as for a string literal, there's no allocation happening
<Papierkorb> bew, read that as "both are fine", neither allocate extra memory. The Char version is *sliightly* faster of course, but apart from that..
<FromGitter> <bew> Papierkorb: even for the String object (a few bytes I now)
<FromGitter> <bew> ?
<FromGitter> <bew> yeah for sure
<Papierkorb> bew, the String is constant and exists completely in the .rodata afaik, thus, no run-time overhead of it being there
<FromGitter> <bew> I wasn't speaking about the bytes of the string, but the crystal-lang String object (which has a pointer to .rodata to the actual string)
<Papierkorb> .rodata exists anyway and is just copied into memory by the ELF loader. Technically, it's slightly more involved than that. But before you notice that, you probably have many other things to optimize first ;) - String is pretty much a `Tuple(UInt8*, Int32)` in terms of size, so it's not even really a reference. Also one of the reasons you can't inherit from String.
<FromGitter> <LuckyChicken91_twitter> who here is finding `.empty?` at a string unnecessary? because you can write `if string==""`faster than `if string.empty?`
<FromGitter> <bew> @LuckyChicken91_twitter shorter, but nor necessarily faster
<Papierkorb> No, String#empty? is fine and having to write `foo == ""` is crap.
<Papierkorb> Not to mention consistency with other Enumerable types
<FromGitter> <elorest> @bew good point.
<FromGitter> <LuckyChicken91_twitter> oh so comparing `if string.empty?` and `if string==""` in benchmark then =="" would be slower?
<Papierkorb> Of course.
<FromGitter> <LuckyChicken91_twitter> aah okay good to know
<Papierkorb> But that's not the reason for it. It's idiomatic to ask something if it's empty.
<Papierkorb> It's less idiomatic to ask if something equals something empty
<FromGitter> <bew> Papierkorb: in program.cr String is noted as inheriting from reference, then it's instance_vars are declared, but I can't find any other "weird" stuff about string.. can you give me some pointer on what is really special about it?
<Papierkorb> bew, also hard-declaring the inst_vars in the compiler makes it kinda special ;)
<FromGitter> <akzhan> hi all :) ⏎ ⏎ where am i wrong? i want to get index of element that less than 16: ⏎ https://play.crystal-lang.org/#/r/2j9g [https://gitter.im/crystal-lang/crystal?at=59934eed210ac2692087bf24]
<FromGitter> <akzhan> ```arr = [ 1, 4, 16, 25 ] ⏎ ⏎ idx = arr.bsearch_index { |x| x < 16 } ⏎ ⏎ p idx``` ⏎ ⏎ prints nil [https://gitter.im/crystal-lang/crystal?at=59934f7f2723db8d5ea8b7e3]
imusingnotepad has quit [Quit: Page closed]
xiljin has quit [Quit: ...]
<FromGitter> <bew> @akzhan it's weird, it doesn't try all elements: https://carc.in/#/r/2j9t
<FromGitter> <bew> Thanks Papierkorb!
<oprypin> bew, Papierkorb, so what's really happening with a string is it's a pointer to some bytes, the first 4 of which are size and the rest are contents - the "some bytes" can be in heap or rodata (not 100% sure)
<oprypin> wow except it's not 4 bytes but 3*4 bytes {TYPE_ID, bytesize.to_i, size.to_i}
<FromGitter> <tonobo> hiho, i've a question releated to compile time checks. It corrected that your doing such checks, e. g handling possible nil access? So if conditions on instance variables are not working, is there any possibility to skip this compile time check convert into runtime checks?
<Papierkorb> oprypin: String stores the string data just after the three @vars. It doesn't have a pointer to it, as the address to it is really "pointerof(String) + 12 Bytes"
<FromGitter> <bew> oprypin: I thing that only the content can be in heap or rodata, the rest (+ the pointer) is allocated by the GC with GC.malloc_atomic
<FromGitter> <bew> wut
<Papierkorb> oprypin: And yes, the data can be anywhere. I expect the `@size` (which is the size in Chars) to be correctly initialized by the compiler, so it doesn't have to be written to (which would cause a segfault within .rodata) later on
<FromGitter> <tonobo> oprypin: i know the situation but isn't quite inperfomant by allocation each on heap? what happens with arrays?
<oprypin> bew, there is no rest https://carc.in/#/r/2ja2
<RX14> ^
<oprypin> tonobo, your worries are caused by some misunderstanding, there is no problem with this, in fact llvm probably eliminates this entirely
<FromGitter> <bew> yeah I just got understood
<hightower2> sdogruyol: there?
<RX14> a string has no pointer
<RX14> it simply has a header + data which are always contiguous
<oprypin> well actually it does, a String is only a pointer
<oprypin> to what you just said
<RX14> it is a pointer
<RX14> it doesn't HAVE a pointer
<FromGitter> <bew> yep
<FromGitter> <bew> very interesting
<oprypin> indeed
<Papierkorb> bew, that whole structure is placed in .rodata by the compiler (Well, the linker). The linker will then happily give the program a pointer to that data (it doesn't care what it is). That's actually what the linker's job is mostly about: Resolving such pointers (in linker-speak, symbols)
<FromGitter> <bew> genius
<FromGitter> <bew> you resolved my last question ;)
<RX14> @tonobo are you talking about `if foo = @foo` ?
<oprypin> RX14, yes
<oprypin> bew, Papierkorb, another fun fact that i wanted to confirm before saying https://carc.in/#/r/2ja3 character-size is in fact calculated on first access
<FromGitter> <tonobo> yeah
<Papierkorb> This happens at link-time, that's (technically) after compile-time, but way before run-time: It's before the binary program is written to disk.
<RX14> in that case, 99% of the time you're only copying a pointer
<RX14> that's just a number
<RX14> it goes in a register and so that will essentially be 0 cost
<RX14> in fact it will be cheaper
<RX14> because it's 1 load from the ivar to the local var 9assuming it's inr egisters)
<RX14> instead of a load every time you use @foo
<FromGitter> <tonobo> oh ok
<oprypin> RX14, dont you think llvm will ignore the copy entirely
<RX14> which the former semantic would imply
<RX14> it might do
<RX14> it might not
<Papierkorb> oprypin: A string from literal has the size calculated, a run-time string on the heap will do it lazily
<oprypin> well sure that's what i was trying to show
<RX14> oprypin, it probably isn't optimized out over non-inlined function calls
<RX14> because if the function call isn't aligned llvm likely can't say whether the call modifies the ivar
<RX14> in that case it has to load again
<FromGitter> <bew> so cool... I love crystal, it resolves a lot of amazing problems in a clean way, so interesting to read and to learn about them
<RX14> String is the only thing I know which does that trick @bew
<Papierkorb> Same
<RX14> and it's kind of a pain because very string constructor has to recreate it's binary form from scratch
<FromGitter> <tonobo> but if i just create a pointer, isn't is the same as using the orig pointer? because if the process A will free them and process B will access the data then i access a nil pointer?
<oprypin> this is not really new though, i know that Nim has exactly the same implementation of string
<oprypin> and probably many before it
<Papierkorb> yeah
<RX14> @tonobo if you use `@foo` you're loading the value of that from memory. That memory might be a pointer in itself, but it might not be.
<Papierkorb> Why invent something new if a good approach has been battle-tested for ages. (Well, every approach has its own issues lul)
<RX14> oh yeah it's nothing new
<RX14> putting headers on strings has been around for ages
<Papierkorb> Pascal did it ..?
<FromGitter> <bew> yeah, personally I only know well Crystal, compilers and stdlib of all other languages are still blackbox (less and less over time though)
<oprypin> Papierkorb, did pascal actually do that but with a 1 byte header?
<RX14> bet they didn't support utf8 though
<oprypin> lol
<Papierkorb> oprypin: possibly. Never used pascal nor delphi heh
<FromGitter> <bew> how many years have you been working with bytes & code & programming & stuff?
<Papierkorb> Proc is fun too. And depressingly boring after you know the trick.
<FromGitter> <bew> ahah
<Papierkorb> Though works well and boring is kinda good in a sense
<FromGitter> <bew> simple is better!
<FromGitter> <akzhan> just found - search_index - I need to only one form of condition passed (>=).
<oprypin> Papierkorb, ok strings in pascal are actually even more stupid than i thought http://www.xuebuyuan.com/350751.html
<oprypin> of course modern implementations of pascal have nothing to do with this
<Papierkorb> oprypin: ... Who comes up with that
<Papierkorb> > Like C's strings, it is also null-terminated, which meant that Delphi automatically appends a zero byte at the end (actually 2 zero bytes)
<Papierkorb> Mh, who would use 16bit chars in the system API anyway?
<Papierkorb> Oh .. Windows.
<FromGitter> <tonobo> Could you explain why your doing it such diffenent as golang it does. Are there a mentionable difference between performance or are there security aspects?
<oprypin> akzhan, sorry i missed your question. i was checking out this method just a few days ago, ended up with this strangely example https://carc.in/#/r/2iqs (with same example data, it seems :p)
<oprypin> tonobo, doing what
<Papierkorb> tonobo, "different" in which sense? Though in general, the design philosophies are completely different
<FromGitter> <tonobo> Golang will panic if a nil pointer has been accessed?
<oprypin> tonobo, and crystal will not let you do that
<FromGitter> <tonobo> yeah
<FromGitter> <tonobo> :D
<Papierkorb> Wait, golang didn't fix the one billion dollar mistake?
<oprypin> nope, it made it even worse
<Papierkorb> got to be fucking kidding me
<oprypin> mfw
<oprypin> Papierkorb, how's this for a fun read https://news.ycombinator.com/item?id=14986482
<oprypin> regardless of the actual article which may be baloney, there are some fun comments to read
<oprypin> how did humanity arrive to this point
<FromGitter> <tonobo> Are there some reasons why they won't to "fix" it?
<oprypin> that would mean making a new programming language
<oprypin> and they don't appear to be good at that
<FromGitter> <tonobo> So its just a root decision fail?
<FromGitter> <faustinoaq> oprypin, but they have a big team and resources 💰
<Papierkorb> tonobo, that's not an easy task. I don't know Golang, but the type system is a central part of every language, and has to be carefully designed from the get go, as changes later can and will break things all over the place
<oprypin> akzhan, but yeah your simple example shows the typical use case perfectly
<Papierkorb> tonobo, imho the biggest plus of Crystal may look surprisingly simple at first: Union typing, that is, that you can allow a type like `String | Int32`, meaning "Strings and Int32s are fine, everything else is not". Now the creators added `Nil` to the mix, which is not nothing, but a real type. Unlike in C or Java, where you can still pass `null` instead of the pointer that was expected (Modern C++ enforces this too). And now suddenly that
<Papierkorb> simplistic feature becomes a full-blown solution to the "one billion dollar mistake". Not so boring after all
<FromGitter> <tonobo> yeah i like crystal , the ideas behind, the syntax, ruby :D
<Papierkorb> It also saves us from cluttering our code with pesky `Just(x)` and other waste of bytes. Other languages like Java are broken by design w.r.t this particular problem.
<FromGitter> <tonobo> i've wirtten multiple small golang projects. And you need to write specs which hopefully triggers all nil pointer exceptions. Back to my original question, are there any performance differences by not checking the nil pointer? E.g I'am easily able to write code without allocations on heap.
<Papierkorb> It saves you a single branch per variable (more or less), which I wouldn't really count as such as most CPU branch predictors will catch that and make it an almost no-op. Though not having it at all makes it even faster ;)
<Papierkorb> The real issue is that you're cluttering your source code, which (as all kind of clutter) makes it harder to read. Also, you can just forget to check for nils.
<FromGitter> <tonobo> mhm
<RX14> i absolutely agree that union types are the single most important feature in crystal
<RX14> it enables the feel of duck typing when writing method bodies, in a compiled statically-typed langauge. which is something i've never come across before
<FromGitter> <straight-shoota> @RX14 agree
<FromGitter> <tonobo> Yes, looks great :D
<FromGitter> <tonobo> I'm getting started right now with crystal and wan't to learn something about the internals.
<FromGitter> <tonobo> Also great support, guys ! :D
<oprypin> yeah +1 to "i absolutely agree that union types are the single most important feature in crystal"
<hightower2> It's awesome
<FromGitter> <faustinoaq> 👍
<FromGitter> <tonobo> Why did you decide to a make garbage collected language, not as just does?
<Papierkorb> *as Rust ?
<FromGitter> <tonobo> yes :D
<oprypin> tonobo, "because Ruby" can answer a lot of things
<oprypin> without garbage collection everything becomes entirely different
<Papierkorb> tonobo, I'm not a creator, but also, making a language (and/or environment) which automatically manages memory without a GC is hard. See Rust: They do it, which is impressive. But the price is that it becomes much harder to use.
<FromGitter> <tonobo> Ok, you're right. Rust's borrowing feels strange by using it :D
<FromGitter> <tonobo> Are there any issues open right now which recommends me to avoid crystal in production?
<oprypin> probably. but people do it anyway
<FromGitter> <tonobo> :D
<FromGitter> <fridgerator> lol
<RX14> don't use crystal in production when you've worked out foryourself when to use it in production
<RX14> because if you're asking the answer is no
<RX14> s/when/until
<FromGitter> <tonobo> yeah
<FromGitter> <tonobo> Thanks a lot guys :D
<FromGitter> <crisward> @sdogruyol How's the survey gone... planning on publishing something?
greengriminal has joined #crystal-lang
<crystal-gh> [crystal] oprypin opened pull request #4834: Fix parsing of '!=' after an identifier (master...not-equal) https://git.io/v7Fxf
alex`` has quit [Ping timeout: 246 seconds]
<FromGitter> <faustinoaq> > Submissions will be accepted until around September 12th, 2017. ⏎ So, I think is not ready yet
justinmcp_ has quit [Quit: No Ping reply in 180 seconds.]
justinmcp has joined #crystal-lang
txdv has quit [Ping timeout: 240 seconds]
hightower4 has joined #crystal-lang
hightower2 has quit [Ping timeout: 255 seconds]
txdv has joined #crystal-lang
<Papierkorb> Let there be hacks so thou can (Qt-)signal state https://gist.github.com/Papierkorb/651fab1d02d69a9521ff5a12169b747d
<hightower4> Papierkorb, oh man, wonderful