ChanServ changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.22.0 | Fund Crystal's development: http://is.gd/X7PRtI | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/crystal-lang/crystal | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/ | Logs: http://irclog.whitequark.org/crystal-lang
<sauer2> Phew, it works without Nil. Thank you @bew !
<FromGitter> <bew> I think that in a BlockStatement there should be an array of Statement, it feels logic. IMO if you don't always have statements in a BlockStatement, it that there is something wrong in how you use your data structures, and that something should be fixed, not by changing the data structure but adding a check where needed
<FromGitter> <bew> you're welcome ;)
<sauer2> it is, now, along with some more of those cases.
<sauer2> Well, see you around.
sauer2 has quit [Quit: Page closed]
<FromGitter> <bew> yep! going to sleep now, see'you
Aytan72 has quit []
<FromGitter> <luislavena> @mgarciaisaia @bcardiff any ETA release of binaries for 0.23.0?
<FromGitter> <mgarciaisaia> It should have been *today*, but running into some issues - tomorrow, hopefully?
<FromGitter> <luislavena> @mgarciaisaia I think I can survive one more day :wink:
<FromGitter> <luislavena> Thank you for the quick response! :smile:
<FromGitter> <mgarciaisaia> Lucky me :)
<FromGitter> <johnjansen> ok this could be a dumb question, but how do you test an IO for EOF? (without falling back to exceptions)
foca has quit [Ping timeout: 240 seconds]
z64 has quit [Ping timeout: 240 seconds]
foca has joined #crystal-lang
z64 has joined #crystal-lang
<crystal-gh> [crystal] MakeNowJust opened pull request #4631: Format: show backtrace when formatting bug found (master...fix/crystal-format/show-backtrace-when-bug-found) https://git.io/vQcwW
rohitpaulk has joined #crystal-lang
Kug3lis is now known as Kug3lis_off
Kug3lis_off is now known as Kug3lis
Kug3lis is now known as Kug3lis_off
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <krypton97> Is there an auto formatter extension for crystal?
<FromGitter> <bew> There is : crystal tool format
<FromGitter> <sdogruyol> crystal tool format
<FromGitter> <bew> :)
rohitpaulk has quit [Ping timeout: 240 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
Raimondii has joined #crystal-lang
Raimondi has quit [Ping timeout: 268 seconds]
Raimondii is now known as Raimondi
<FromGitter> <akzhan> @faustinoaq you may be allowed to —cross-compile x86_64-macosx-darwin
Philpax has joined #crystal-lang
bjz has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
flaviodesousa has joined #crystal-lang
snsei has joined #crystal-lang
snsei_ has joined #crystal-lang
snsei_ has quit [Client Quit]
snsei has quit [Ping timeout: 258 seconds]
<FromGitter> <krypton97> Is crystal tool format same as gofmt aka formats the code on saving
<FromGitter> <bew> the crystal formatter is a formatter, it doesn't do anything on his own. However you can configure your editor to format the file everytime you save it!
<FromGitter> <krypton97> Nice
<FromGitter> <krypton97> That's what I wanted to know, ty
<FromGitter> <akzhan> @krypton97 Almost every Crystal language IDE plugin allows to format on save. And you may run it by yourself too.
<FromGitter> <lilijreey> @akzhan Is there have any document that Crystal design?
<FromGitter> <akzhan> I don’t know :) look at crystal-lang.org site :) or you need something like https://crystal-lang.org/2015/03/04/internals.html ?
<FromGitter> <bew> what do you mean by "document that crystal design" ?
<FromGitter> <lilijreey> @bew Crystal Language design paper
<FromGitter> <bew> oh, I don't think there is such a paper ATM, it's all in crystal core dev team's heads, but it would be good to have it written down!
<FromGitter> <sdogruyol> hey everyone
<FromGitter> <sdogruyol> how are you?
<FromGitter> <bew> fine! & you?
<FromGitter> <lilijreey> me to
<FromGitter> <sdogruyol> great
<FromGitter> <sdogruyol> @lilijreey welcome
<FromGitter> <lilijreey> @bew How to become crystal core developer ?
<FromGitter> <lilijreey> @sdogruyol Thx :smile:
<FromGitter> <sdogruyol> @lilijreey contribute to Crystal and do a lot of pull requests :)
<FromGitter> <lilijreey> @sdogruyol Right :+1:
<FromGitter> <sdogruyol> @lilijreey what's your current programming language of choice?
<FromGitter> <lilijreey> I need learning LLVM first. I new user Java for web dev. But I'am not like java. I used to C++/Ruby/Erlang/Lua
<FromGitter> <lilijreey> dislike not 'not like' 哈哈
<FromGitter> <bew> cool a Lua guy ;)
<FromGitter> <sdogruyol> yeah
<FromGitter> <sdogruyol> wish i knew some chinese :P
<FromGitter> <sdogruyol> japanese would be okay
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
bjz has quit [Client Quit]
chimkan has joined #crystal-lang
chimkan has quit [Client Quit]
chimkan has joined #crystal-lang
chimkan has quit [Client Quit]
chimkan has joined #crystal-lang
<FromGitter> <codenoid> sup
chimkan has quit [Client Quit]
<FromGitter> <codenoid> how to get my current local ip address in crystal ?, like in linux i do `` ifconfig `` and i got ⏎ `` inet addr:192.168.100.12 `` ,
chimkan has joined #crystal-lang
<FromGitter> <codenoid> and also, any body have example code crystal write file ? , thanks
<FromGitter> <codenoid> ^^ like shell exec
<FromGitter> <bew> what do you mean?
<FromGitter> <codenoid> ok, 1.how to execute OS command on via crystal and get the result, 2. how to write file and edit file with crystal , thanks
<FromGitter> <akzhan> File.open «wow.txt», «w» { |f| f.write … } ?
<FromGitter> <bew> to exec a command, you can use `Process.run` or ⏎ ⏎ `````` [https://gitter.im/crystal-lang/crystal?at=5953a0ab703e565c335181ee]
<FromGitter> <sdogruyol> @codenoid running a shell command https://play.crystal-lang.org/#/r/29l6
<FromGitter> <bew> ```output = `some_command arg1, arg2````
<FromGitter> <bew> oups, without the comma ><
<FromGitter> <codenoid> ok, just with single quote
<FromGitter> <akzhan> Read/write https://play.crystal-lang.org/#/r/29l7
<FromGitter> <bew> they are back-quotes
<FromGitter> <codenoid> thanks^^
nikkkk has joined #crystal-lang
<FromGitter> <codenoid> is crystal syntax totally same like ruby ?
<FromGitter> <bew> @mverzilli what do you mean "using StackOverflow as KB for Crystal" in https://github.com/crystal-lang/crystal/issues/4628#issuecomment-311649456 ?
nikkkk has quit [Quit: Textual IRC Client: www.textualapp.com]
<FromGitter> <mverzilli> KB=Knowledge Base
<FromGitter> <mverzilli> StackOverflow is a perfect fit and has amazing SEO
<FromGitter> <mverzilli> and we learned from Luis that it lets you answer your own questions
rohitpaulk has quit [Ping timeout: 240 seconds]
<FromGitter> <sdogruyol> yeah
<FromGitter> <bew> oh perfect, thx!
<FromGitter> <sdogruyol> please follow https://stackoverflow.com/questions/tagged/crystal-lang on SO :)
<FromGitter> <bew> @mverzilli yu should shoose your own answer to mark the question as "resolved"
rohitpaulk has joined #crystal-lang
<FromGitter> <mverzilli> I will, but SO forces me to wait for 2 days
<FromGitter> <bew> oh didn't knwo that
<FromGitter> <mverzilli> hope it sends me reminder too :P
chimkan has quit [Quit: chimkan]
rohitpaulk has quit [Ping timeout: 276 seconds]
rohitpaulk has joined #crystal-lang
<FromGitter> <sdogruyol> @mverzilli who's in charge of releases from now on? @mgarciaisaia
<FromGitter> <mverzilli> @bcardiff, @mgarciaisaia, @waj, myself
<FromGitter> <sdogruyol> cool :+1:
<FromGitter> <sdogruyol> Is there anything that the community can help with the release process
<FromGitter> <sdogruyol> i'm curious about discovering more ways to improve colloboration between core team and the community
<FromGitter> <mverzilli> with release in particular it is a bit complicated due to keys for repos and so on
<FromGitter> <mverzilli> *this* release in particular is a bit more tricky because we made some changes to the omnibus scripts and are trying to get rid of llvm 3.5
<FromGitter> <mverzilli> we're still aiming at one release per month, this one slipped to two months because of that
<FromGitter> <bew> what is the omnibus thing exactly?
<FromGitter> <sdogruyol> @mverzilli thanks for the info
<FromGitter> <mverzilli> it's a set of scripts we use to generate crystal binaries and packages for the different target distros, os's, etc
<FromGitter> <mverzilli> the process generally takes quite long, each time we try it it takes hours to do everything
<FromGitter> <codenoid> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5953b721ad9c781843ac380f]
<FromGitter> <sdogruyol> @mverzilli what's required to make it faster / better?
<FromGitter> <codenoid> sir, crystal wont directly read my file after i upload it
<FromGitter> <codenoid> or crystal need some time ? sleep ?
<FromGitter> <Freezerburn> What's the correct way to use Dir.blob to get all files recursively in a specific directory? I attempted to use "Dir.blob [File.join(dir_one, dir_two) + "/**/*"]", but that didn't give me any files. Subsequently: Is blob documented anywhere?
<FromGitter> <codenoid> same :(
chimkan has joined #crystal-lang
<FromGitter> <codenoid> oh
<FromGitter> <codenoid> ah silly mistake
<FromGitter> <bew> @Freezerburn try `Dir["**/*"]`
<FromGitter> <codenoid> read function inside write function
chimkan has quit [Client Quit]
<FromGitter> <bew> (which is the same as `Dig.glob "**/*"`, and it's `glob` not `blob`)
hightower has joined #crystal-lang
chimkan has joined #crystal-lang
<FromGitter> <sdogruyol> i'd really really like to have something like this for Crystal https://github.com/mitchellh/gox //cc @RX14
<FromGitter> <codenoid> :sparkles:
<FromGitter> <Freezerburn> @bew I think not using a code tag or something ate the double star I put in. The problem I'm having is that using `**/*` doesn't allow me to specify the exact dir I want to list all the files for. Do I need to cp to the dir first, or is there a way to do `Dir[someDir + "**/*"]`?
<FromGitter> <Freezerburn> `Dir[someDir + "/**/*"]`, rather
<FromGitter> <bew> well, `Dir.glob "/tmp/**/*.cr"` works
<FromGitter> <bew> you might prefer to use `Dir.glob File.join("/tmp", "**/*.cr")`
<FromGitter> <bigtunacan> @sdogruyol How is that different from the built in --cross-compile?
<FromGitter> <davidbe> Crystal should be here to!: http://howistart.org/
<FromGitter> <sdogruyol> @bigtunacan installing toolchains, configuring flags e.g
<FromGitter> <Freezerburn> @bew You're completely correct and I am silly, because I misspelled a directory name >.<
chimkan has quit [Quit: chimkan]
<FromGitter> <bew> it would also save the crystal -> LLVM's IR compilation, and reuse it for multiple targets IMO
<FromGitter> <bew> @Freezerburn ahah, you'll double, triple check next time ;)
chimkan has joined #crystal-lang
xiljin has quit [Ping timeout: 260 seconds]
xiljin has joined #crystal-lang
hightower has quit [Ping timeout: 240 seconds]
<FromGitter> <bcardiff> @codenoid the written file needs to be closed probably.
<FromGitter> <codenoid> > read function inside write function
<FromGitter> <codenoid> ?
Kug3lis_off is now known as Kug3lis
<FromGitter> <krypton97> where I can read more about " thing do |arg| " syntax
<FromGitter> <krypton97> ?
<FromGitter> <krypton97> it kinda confuses me
<FromGitter> <codenoid> i ithink it just array / hash value (?)
<FromGitter> <krypton97> so u're saying that I'm itterating an array?
<FromGitter> <krypton97> I read that, gonna give it a closer look
<FromGitter> <krypton97> so that's a method
<FromGitter> <bew> I agree that when you're not from a ruby background, understanding blocks takes time
<FromGitter> <codenoid> me too from plain text background
<FromGitter> <bew> in your little example, `thing` is a method that accepts a block
<FromGitter> <krypton97> thanks for the support!
<FromGitter> <mverzilli> @sdogruyol as with everything else, it requires work ¯\_(ツ)_/¯
<FromGitter> <sdogruyol> @mverzilli yeah, i wish we could distribute some work :)
<FromGitter> <bew> missing `\` in your beautiful smiley :confused:
onionhammer1 has joined #crystal-lang
onionhammer has quit [Ping timeout: 240 seconds]
<FromGitter> <mverzilli> lost in paste
<FromGitter> <codenoid> crystal is ruby crystal is ruby repeatly 59230759823759827398523 time
<FromGitter> <sdogruyol> @codenoid what?
<FromGitter> <codenoid> white i google it like "write file in crystal" > "write file in ruby"
Philpax has quit [Ping timeout: 260 seconds]
<FromGitter> <krypton97> by methods, do they mean a simple function or functions that belongs to a class
<FromGitter> <bew> both
<FromGitter> <krypton97> great
<FromGitter> <krypton97> ty!
bjz has joined #crystal-lang
Nouv has joined #crystal-lang
<FromGitter> <krypton97> def loop ⏎ i= 0 ⏎ while(i < 10) ⏎ yield i ⏎ i += 1 ... [https://gitter.im/crystal-lang/crystal?at=5953cc8a76a757f808b5949c]
<FromGitter> <krypton97> is it possible to get that right?
<FromGitter> <drujensen> super happy to find crystal on jwt.io! https://jwt.io
<FromGitter> <krypton97> or isn't it a specific behaviour
<oprypin> krypton97, loop is a built in function that everything relies on. you replaced it.
<Papierkorb> krypton97, 1) #loop is already defined 2) brackets around conditions are superfluous 3) Use `10.times do |i| ... end` instead
<Nouv> Was the crystal parser written by hand?
<Papierkorb> Nouv: Yes
<Nouv> Wow
<Papierkorb> krypton97, Or `0.upto(9) do |i| ... end` if you like that more
<Papierkorb> Nouv: ?
<Nouv> parser.cr is one complicated file
<Nouv> Papierkorb: Is it recursive descent?
<Papierkorb> As is any parser, generated or not
<Nouv> Fair
<FromGitter> <krypton97> thank you all, I fixed it based on compiler output till the end
<FromGitter> <bew> no, not recursive descendent :/
<Papierkorb> Nouv: Yes it is, as is usual for a handwritten one. thus it's LL(k), may be LL(1) even
<FromGitter> <bew> is it? Oo
<Papierkorb> What else?
<Papierkorb> It's not table driven, that's for sure
<Nouv> Could have been top down order precedence?
<FromGitter> <bew> Papierkorb, oh yes, mixed it with PEG parser
<FromGitter> <sdogruyol> @Nouv are you a compiler person? :)
rohitpaulk has quit [Ping timeout: 255 seconds]
<Nouv> @sdogruyol: Trying to learn! I think I understand basic lexing and parsing (recursive descent), now looking into semantic analysis. Yourself?
<Papierkorb> Nouv: Have a look at the semantic/ sub-dir, tons of visitors for that in there
<Nouv> Ooh
<Yxhuvud> Papierkorb: there is different hard when it comes to parsers though. compare to parse.y in the ruby source tree. You may want to get protective gear for your eyes first though
<Papierkorb> Yxhuvud: The #ifdefs for ripper are really the finishing touch
<FromGitter> <fridgerator> @drujensen thats cool!
<Nouv> Yxhuvud: Oh my god
<Papierkorb> Yxhuvud: I was referring at that such parser are by their nature complex, not that some are especially ugly
<Papierkorb> Though yeah, ruby's .y is quite a treat lul
<Yxhuvud> I wonder how much of that is due to the lack of power in the parser engines. Ie how much simpler could they be if it were built on something like Marpa?
flaviodesousa has quit [Quit: KVIrc 4.2.0 Equilibrium http://www.kvirc.net/]
<FromGitter> <sdogruyol> @nouv i am a beginner too. Interested in contributing to Crystal compiler
<Nouv> @sdogruyol: Ah. I'm just interested out of curiosity, I knew that crystal was self-hosting so decided to look into it a bit more
<FromGitter> <bew> I thought crystal lexer/parser wasn't perfect, but that ruby's .y is woow ugly as hell
<Yxhuvud> it is also a lot older to be fair
<FromGitter> <bew> and it's generating C
<Nouv> It's also auto generated, right?
<Papierkorb> for a PoC for a proposal addition to the ruby language I once hacked something into its parser. Wasn't fun, but it somehow worked.
<Papierkorb> Nouv: What, Crystals? No. Ruby? Yep, auto generated
<Nouv> Papierkorb: Yeah I meant ruby, sorry
<Papierkorb> Nouv: That .y file is most likely fed into yacc or bison
<FromGitter> <sdogruyol> I love Crystal's parser
<Nouv> Papierkorb: Bison I think
<FromGitter> <sdogruyol> So simple and easy to read
tatey has quit [Quit: ZNC - http://znc.in]
tatey has joined #crystal-lang
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 276 seconds]
<Nouv> Where do things like IO (filesystem access for example) come in the compiler process? Is that something that LLVM deals with, or do you have to write assembly? Terrible question I know
Kug3lis is now known as Kug3lis_off
<FromGitter> <krypton97> any way to workarround this?
<FromGitter> <krypton97> def many ⏎ yield 1 ⏎ yield 1,2 ⏎ yield 1,2,3 ⏎ end ... [https://gitter.im/crystal-lang/crystal?at=5953d9ef703e565c3352b0b2]
<oprypin> krypton97, what is this supposed to do?
<oprypin> Nouv, file system access is done using Crystal, calling POSIX APIs
<FromGitter> <krypton97> to puts the sum, but first and second yield takes only 1/2 args not 3
<FromGitter> <krypton97> how can I cover all the cases?
<FromGitter> <krypton97> if possible
<Nouv> oprypin: I guess my question should then be - how does crystal interact with an api?
<oprypin> Nouv, through C ABI - dynamically linked libc
<oprypin> i think
<RX14> Nouv, i suggest you read up about syscalls and libc
<Nouv> RX14: Thanks! I know I have no idea about any of this, was looking for a direction to head in. I'll go for that, thanks!
<RX14> Nouv, crystal's IO abstraction comes from the stdlib which calls into libc which executes syscalls
<RX14> thats the high level
<Nouv> RX14: And libc is linked using llvm?
<RX14> libc is witten in C and crystal binaries dynamically link to libc
<RX14> libc is likely compiled using gcc actually
<oprypin> means how linking to crystal happens
<Papierkorb> linked to the binary by your systems dynamic linker when you instruct your system to execute that binary
<RX14> Nouv, you're touching on a lot of topics which go quite deep here, it's really quite hard to explain it so you truly understand it over public IRC
<Nouv> Right, okay
<Nouv> I have to go, but thank you for your help!
Nouv has quit [Quit: Nouv]
rohitpaulk has joined #crystal-lang
<hightower3> Hey, how do I solve this: I want a function to take arbitrary number and type of args. I can do this with def func( *args) . However, I have trouble when I want to save that to some instance var like @args, since I must specify type, which I don't know in advance.
<hightower3> Is this a solvable problem or simply can't be done?
<Papierkorb> Generic, but for that you have to know the type in advance somehow ("educated guess"), OR if you're passing that to #initialize it can auto-deduce it, OR you go with the good old OOP Base-class-Generic-class container approach if you really really need this
<hightower3> Papierkorb, how would #initialize work? I have def initialize(*args), but if I use (*@args) or if in the body I say @args= args, I get "Can't infer the type of instance variable '@args'"
<hightower3> (Is this because I don't actually call it from anywhere yet, I just added that class/method?)
<Papierkorb> Please gist the whole code of that class.
<hightower3> Papierkorb, https://carc.in/#/r/29pi
<Papierkorb> the class needs to be a Generic
<Papierkorb> And then @argument to be of that generic type
<hightower3> Got a little bit closer but don't see the final solution: https://carc.in/#/r/29pr
<FromGitter> <mgarciaisaia> :point_up: June 28, 2017 6:17 AM (https://gitter.im/crystal-lang/crystal?at=5953743fceb5bef82ebbe7d3) ⏎ ⏎ It's on my to-do list
<hightower3> Papierkorb, Mm, I would try to avoid using Arrays, because where I want to go with this is that when someone calls X.new.call( obj), I execute something like obj.call( @operator, *@argument). And I can't do *@arg if it's an Array
<hightower3> Am I misdesigning how one would do this in Crystal, or?
<Papierkorb> hightower3: we don't know what you're trying to build, thus we can't say if it's mis-designed or not
<Papierkorb> hightower3: and my code serves as example, just change it to what you need
<hightower3> An object where I store method name (@operator in my example) and intended arguments (*@argument). Then, when someone calls obj.call( other_obj), I want to invoke method other_obj.@operator( *@argument)
<Papierkorb> That's not possible
<Papierkorb> #send doesn't exist
<hightower3> ok, thanks. I'll try getting around that with blocks then
<Papierkorb> Sounds over-complicating/over-engineering to me
<Papierkorb> If you have a "named" operator, and two objects you want to compare by it, why not have a simple method which takes the operator, a, b, then throws `operator` into a case statement and calls the operator method accordingly on a and b?
<Papierkorb> If you want it fancier (for whatever reason), that case statement could return a Proc(T, Bool) like in `def f(op, a) case op when :< then ->(b){ a < b } end`
<Papierkorb> But I'd prefer the first solution over the Proc-returning solution
<hightower3> Papierkorb, right, I named it @operator but in general it can be any method
Kug3lis_off is now known as Kug3lis
thews_ is now known as thews
thews has quit [Changing host]
thews has joined #crystal-lang
Kug3lis has quit [Quit: Textual IRC Client: www.textualapp.com]
<hightower3> What's the general solution for when I have something like: def x( arg : [] of SomeClass), and then due to arg being an Array I am unable to call *arg inside method body?
mooe has joined #crystal-lang
<hightower3> Oh I see, in the specific case where I needed it, I see that Crystal supports saying array[from..to]= array2, and it does what I wanted to do by saying *array2
<hightower3> Is 'x.class===Char' equal to x.is_a? Char ?
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
bjz has joined #crystal-lang
<FromGitter> <dippersauce> For the life of me I cannot figure out the syntax for File's .new method ```new_file = File.new(old_file_path : new_text, 'w')``` throws a syntax error "expecting token 'CONST', not 'new_text'" Would someone be kind and inform me of the proper syntax?
<FromGitter> <krypton97> are there packages that standardlib is missing/?
<FromGitter> <straight-shoota> @dippersauce the method expects a filename as string and optionally a mode as string
<FromGitter> <straight-shoota> if you want to write `new_text` to the file at `old_file_path` you can call `File.write(old_file_name, new_text)`
<FromGitter> <straight-shoota> @krypton97 yes, of course. see https://github.com/crystal-lang/crystal/wiki/Roadmap#standard-library for examples
<FromGitter> <dippersauce> So there's no way to create the file and write into it in one go using the built in methods?
<FromGitter> <dippersauce> Just wondering out of laziness.
<FromGitter> <straight-shoota> `File.write(old_file_name, new_text)` does that
<FromGitter> <dippersauce> Ok.
<FromGitter> <dippersauce> I'll give that a try, thanks for the help @straight-shoota
rohitpaulk has quit [Ping timeout: 268 seconds]
<FromGitter> <codenoid> sir, can i run compiled crystal app without having crystal language in my computer ?
rohitpaulk has joined #crystal-lang
<FromGitter> <dippersauce> Yes, the crystal compiler emits native code via LLVM. Crystal is not a runtime dependant language.
<FromGitter> <codenoid> god bless crystal
<FromGitter> <johnjansen> anyone know of a dns resolver for crystal
<FromGitter> <dippersauce> Hell yeah, I'm loving so far as well. Everything I've wanted in a language.
<RX14> @johnjansen well you can resolve a domain to an IP using the stdlib
<RX14> anything more like CNAME and A records I don't know
<FromGitter> <johnjansen> @RX14 how did i miss that
<RX14> you want Socket::Addrinfo.resolve
<FromGitter> <johnjansen> thanks Chris, thats awesome
rohitpaulk has quit [Ping timeout: 260 seconds]
rohitpaulk has joined #crystal-lang
rohitpaulk has quit [Ping timeout: 260 seconds]
<hightower3> Hey why am I getting an error in this simple example: https://carc.in/#/r/29r5 ?
<hightower3> Actually I didn't isolate the example really well, working on it
<Papierkorb> hightower3: Check the return type of Enumerable#index
<FromGitter> <straight-shoota> `[0, 0, 0]` is an `Array(Int32)` whereas `a`is an `Array(Bool | Int32)`
<hightower3> Papierkorb, right, that's why I say I didn't isolate the example really well. I did test that result of index is non-nil
<Papierkorb> hightower3: what types could it possibly be?
<FromGitter> <straight-shoota> https://carc.in/#/r/29ra
<FromGitter> <johnjansen> nice @straight-shoota
<hightower3> Papierkorb, only Int once I am inside 'if idx'?
<Papierkorb> hightower3: yes
<Papierkorb> johnjansen, hightower3, straight-shoota, that #map is highly inefficient. Better would be: `[0, 0, 0] of Int32 | Bool`
<FromGitter> <johnjansen> :-)
<FromGitter> <straight-shoota> Yes, of course. I would have used `[0.as(Int32 | Bool), 0.as(Int32 | Bool),0.as(Int32 | Bool)]` as a more efficient way, but thats harder to read. ⏎ I actually didn't know that the literal with `of` works like that, really nice ;)
<FromGitter> <johnjansen> neither did I, but on reflection its so obvious
<Papierkorb> Same works for literal hashes
<FromGitter> <straight-shoota> indeed
<hightower3> Hm crap, https://carc.in/#/r/29rf works, so that means my specific problem is not related to #index but some other peculiarity of the code
<hightower3> Appears I had to handle the case where list is nil, gotten further now
<hightower3> Ooh, wonderful! Have a first solid piece of code written in Crystal that works/passes my spec tests
Nouv has joined #crystal-lang
<Nouv> Could anyone please point me to where in the crystal source it handles syscalls?
<RX14> Nouv, it doesn't, libc handles the syscalls
Nouv has quit [Ping timeout: 240 seconds]
<FromGitter> <bew> more: kernel handle the syscalls, crystal only call them
<FromGitter> <bew> no?
<RX14> yes but i think that's what Nouv meant
Nouv has joined #crystal-lang
<Nouv> I apologize for my appallingly bad connection .. if I DC again just fax me the answer or something.
<Nouv> But yes, does anyone know where in the compiler syscalls are handled?
<RX14> Nouv, libc handles the syscalls
<FromGitter> <johnjansen> sorry no fax machine … i can do morse over LF
<Papierkorb> Nouv: I think you're confusing the compiler with the "runtime"
<Nouv> Papierkorb: Hm, my ignorance shows
<Nouv> I thought the runtime was an interpreter thing?
<Papierkorb> Nouv: The compiler doesn't handle it, it just (through LLVM) emits machine code for a CALL, or SYSCALL if you write one manually with inline assembler
<FromGitter> <bew> oh no you right RX14, libc only wrap the syscalls, e.g. `write` is transformed to `syscall(SYS_write, ...);` or somethign close to that
<RX14> @bew a bit more than that actually I think
<Papierkorb> Nouv: Far from it, a runtime in itself is just something that runs under, or alongside, a running application, providing useful functionality to the running program
<RX14> Nouv, the compiler turns crystal sourcecode into execurtable machinecode
<RX14> the standard library is also written in crystal
<Nouv> Papierkorb: Crystal is both a compiler and runtime then?
<Papierkorb> Nouv: Crystal compiles (and links) code into real machine code, that stuff isn't interpreted anymore (well ...)
<RX14> and parts of it are included in each crystal binary
<RX14> none of the compiler is included in each crystal binary
<Papierkorb> Nouv: the `crystal` program gives you access to the crystal compiler, and crystals standard library provides you with a runtime
<FromGitter> <bew> RX14: https://goo.gl/EkY93H
<Nouv> RX14: hm
<Papierkorb> Nouv: You use `crystal` to build your program (source code -> ... -> binary), and that binary has no dependency on Crystal itself anymore (the compiler might as well have never existed). It contains however code from the stdlib.
<Nouv> Ah I see
<RX14> @johnjansen i never learnt morse... I should one day
<Nouv> compiled code from the stdlib?
<Papierkorb> Nouv: The stdlib is normal Crystal code, offering useful functionality to you for various tasks. E.g., the crystal program `puts "Hello"` uses the puts method provided by the stdlib to print a string on the screen
<Nouv> I think I get that
<FromGitter> <johnjansen> ``````
<Nouv> Papierkorb: So the stdlib is the part of the program that handles syscalls?
<Papierkorb> Nouv: The stdlib provides methods that may do syscalls, directly, or indirectly through another library (e.g. libc)
<Papierkorb> Nouv: There's no "handling" of it, user space programs commonly do not implement syscalls
<Papierkorb> Nor can they
<Nouv> I suppose then that my question should be: when I compile the program `puts "Hello"`, how exactly does Crystal call into libc to print that?
<Nouv> I don't know how to phrase it correctly but I think the basis of my question is how does IO happen at all
<RX14> @johnjansen would be useful for my ham radio hobby
<RX14> Nouv, well there's a write syscall that the kernel implements
<Papierkorb> Nouv: Ok, create a file foo.cr, type `puts "Hello"` into it, then build it with this command: `crystal build --release foo.cr`
<RX14> thats the basic starting point
<Papierkorb> Nouv: I assume you have access to binutils, which you have when you're on Linux, BSD oder MacOS
<RX14> libc will create a C function which calls this syscall and returns the result
<Nouv> I'm on macOS
<RX14> crystal links to libc and uses that syscalls
<Papierkorb> Nouv: Executing that program `./foo` will print out "Hello", correct?
<Nouv> Papierkorb: Right
<Papierkorb> Nouv: Next, run this command: `ldd foo` this will print out all dynamic libraries your program depends on.
<Nouv> Papierkorb: "Command not found" hah
<Papierkorb> Nouv: Google says `otool -L foo` will do something akin to that
<Papierkorb> Nouv: All of these libraries are *dynamically* linked by your systems kernel to make the program work, and then it's executed. You should see a line mentioning `libc` or so. That's the well known, not that magic (just a little bit...) libc we're talking about
<FromGitter> <johnjansen> wow @RX14 nice work … see if you can raise ZL1MRC some time … he’s a good friend of mine
<FromGitter> <RX14> haha new zealand's a bit far on 5 watts ssb
<Papierkorb> Nouv: Next, objdump is a tool (on linux, heh) which can disassemble and look into ELF files. Let's dump the dynamic symbol table, shall we? https://gist.github.com/Papierkorb/234535f3c65ff93263fbf767485322b3
<FromGitter> <johnjansen> ;-)
<Nouv> Papierkorb: I see what you mean
<Papierkorb> Nouv: A symbol is a function (like fwrite), or a global variable (like errno). In that dump ^, you find all dynamic symbols our programs either requires from another dynamic library, or which it provides
<Papierkorb> Nouv: You see tons of GLIBC mentions, yep, those are those we require from our libc (on my machine that is)
<Nouv> Papierkorb: Right
<Papierkorb> Nouv: On line 19 in my dump, you find `write`. Yep that's good ol' write(2)
<Nouv> Papierkorb: So the generated code that calls the libc functions is in the llvm IR?
<Papierkorb> Nouv: And exactly what Crystal uses to write stuff. But does it? https://gist.github.com/Papierkorb/407b0ebff77bfb7a9d0cbe28d709bbe5#file-disassemble-foo-L3246 There it is: The CALL (here: CALLQ) to write(2), in IO::Buffered, which our STDOUT from Crystal is
<Papierkorb> Nouv: But look above, that code comes from: IO::FileDescriptor#unbuffered_write<Slice(UInt8)>:Int32 - That is, IO::FileDescriptor class, #unbuffered_write method, taking a single Slice(Uint8) as argument, returning a Int32
<Nouv> Oh wow
<Papierkorb> Nouv: And on line 264, that is LibC.write, or our write(2)
<Papierkorb> Nouv: Ok, and next thing write(2) does it it will itself do a platform specific SYSCALL (There are lists showing which platforms support which, including mapping, if you google for them), in this case, eventually, it'll do a SYS_WRITE into STDOUT
<Nouv> Ahh
<Papierkorb> Nouv: And that's the moment our "Hello\n" will be sent off to the kernel for it to be written, which will later on end up on our monitor screen
<Papierkorb> Where you can enjoy the marvel that is of printing a few characters ;)
<Nouv> :D
<Papierkorb> Questions anyone?
rohitpaulk has joined #crystal-lang
<Nouv> Papierkorb: Where is the class LibC defined?
<Papierkorb> Nouv: that's not a class, but a `lib`, defined in Crystal
<Nouv> Papierkorb: Thank you so much for taking the time to help me by the way, it would have taken me 10x longer to try to figure that out myself
<Papierkorb> Nouv: https://github.com/crystal-lang/crystal/tree/master/src/lib_c they're platform dependent, so there are many. All should be equivalent however, and you as Crystal user shouldn't note any difference. You can just write `LibC.write(2, "Hello\n", 6)` in your `foo.cr`, run it, it'll behave exactly the same
<Papierkorb> ^ That is, file descriptor 2 (or STDERR, 1 is STDOUT), buffer "Hello\n", and 6 Bytes to write.
<FromGitter> <bew> Nice deep short course Papierkorb !
<Papierkorb> A few questions keep rising here, feel sometimes like I should just write a blog on stuff like that
<FromGitter> <bew> or at least a wiki page for crystal with this ;)
<Nouv> Papierkorb: So I see that the LibC.write function signature is defined here: https://github.com/crystal-lang/crystal/blob/master/src/lib_c/amd64-unknown-openbsd/c/unistd.cr#L39
<Nouv> Papierkorb: But .. where is the function body? Did I miss the entire point?
<Papierkorb> Nouv: That there just says that there will be a function `write` at runtime, taking the given three arguments.
<Nouv> Ahh
<Nouv> Papierkorb: And at runtime llvm links libc?
<Papierkorb> Nouv: Throw that LLVM stuff out, at runtime, there's no LLVM anymore
<Nouv> Okay, thrown
<Papierkorb> Nouv: Your operating system kernel does the linking for you.
<FromGitter> <bew> Are you sure about that?
<Papierkorb> 100%
<Papierkorb> bew, though it's nothing you couldn't do in user-space using mmap() and mprotect() and, of course, an ELF reader (or whatever format you use)
<Nouv> Papierkorb: does llvm play any role in this at all? Does it compile information telling the operator system kernel what to link?
<FromGitter> <sdogruyol> @papierkorb you should definitely write these info down, or maybe a blog post would be a great great resource
rohitpaulk has quit [Ping timeout: 240 seconds]
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter> <straight-shoota> true, it's really informative to read all this stuff
<FromGitter> <sdogruyol> it's gold
bjz has joined #crystal-lang
<RX14> Nouv, what to link is part of the ELF object file which LLVM writes, so yes it does tell the linker what to link
<RX14> in LLVM ir you specify external functions and you can tell use them
<RX14> the lib definitions in crystal translate into those external function definitions in LLVM
<FromGitter> <bew> Papierkorb, when I do `ldd /bin/cat` I get 3 lines, one is: `/lib64/ld-linux-x86-64.so.2` I thought it was responsible to find and load necessary dynamic libs
<FromGitter> <elorest> This is potentially useful. https://play.crystal-lang.org/#/r/29qm
<FromGitter> <bew> Papierkorb, it seems to be the first thing that load on program launch, then it load all dynamic libraries and finally it transfer control to the actual program
<FromGitter> <krypton97> how can I use the ENV in my app?
<FromGitter> <krypton97> I've tried as docs said but no success
<FromGitter> <johnjansen> how do you want to use it?
<FromGitter> <krypton97> passing a port for a server
<FromGitter> <krypton97> I've tried this
<FromGitter> <krypton97> const PORT = ENV["PORT"] || 3000
<FromGitter> <krypton97> and ENV["PORT"] |
<FromGitter> <krypton97> ||= 3000
<FromGitter> <johnjansen> `PORT = ENV["PORT_VAR_NAME"] || 3000`
<FromGitter> <bew> its `PORT = ENV["PORT"]? || 3000` the `?` will make the env lookup to return nil when it doesn't find PORT in the environement
<FromGitter> <johnjansen> haha
<FromGitter> <bew> that edit :)
<FromGitter> <johnjansen> i was busy doing it while you dropped your code
<FromGitter> <johnjansen> ;-)
<FromGitter> <krypton97> still got issus tbh
<FromGitter> <krypton97> but it's not a must for now
<FromGitter> <krypton97> :D
<FromGitter> <bew> what's the error?
<FromGitter> <krypton97> ty
<FromGitter> <krypton97> no overload matches
<FromGitter> <krypton97> weird
<FromGitter> <bew> can you show the full error?
<FromGitter> <johnjansen> BTW i wouldnt use “PORT” as a name … its better to include the owner as part of the name
<FromGitter> <johnjansen> i.e. “MY_WEB_SERVICE_PORT"
<FromGitter> <krypton97> ok good to know
<FromGitter> <elorest> in ruby I use `hash[“key”] || “some other value”` and `hash[“key”] ||= “some other value”` In crystal you have to do `hash[“key”]? || “some other value”` and `hash[“key”] ||= “some other value”` which seems a little inconsi
<FromGitter> <johnjansen> what im about to say has no relationship to my friend @elorest’s example above … ⏎ ⏎ im perpetually horrified by the things that become apparent about common ruby code, once you try to compile it in crystal … (the stuff that should “just work” but doesnt because of multiple unexpected return types etc) ⏎ ⏎ even if crystal was only useful for finding bad ruby, it would be awesome … i
<FromGitter> <elorest> Still it’s weird to me that `hash[“key”] ||= “some other value”` works in crystal but `hash[“key”] || “some other value”` doesn’t.
<FromGitter> <johnjansen> yep, i hear you
<Papierkorb> elorest, it's actually not inconsistent. All #[] in Crystal are expected to return something, or raise if nothing was found. #[]? returns something, or nil (question method, it asks if it's there). And #[]= sets it, it doesn't ask, it says "whatever there is already, x is now y"
<Papierkorb> that's no-weird-bugs by default, and no #fetch orgies either
<FromGitter> <elorest> <Papierkorb> But `hash[“key”] ||= “some other value”` is saying return the current value or set which seems inconsistent because `hash[“key”]` returns and exception if it doesn’t exist… so how does ||= work but || doesn’t?
<FromGitter> <elorest> This would make sense to me if I could also do this `hash[“key”]? ||= “some other value” `
<Papierkorb> heh I actually never needed that before, that I can understand
<FromGitter> <elorest> You’ve never needed to return a hash value or a default if it didn’t exist?
<FromGitter> <krypton97> what's the equivalent of sleep in crystal lang?
<FromGitter> <bew> `sleep`
<FromGitter> <elorest> `sleep`
<Papierkorb> elorest, that I needed, but not ||=
<FromGitter> <krypton97> I could've bet it will be sleep
<FromGitter> <krypton97> lol
<FromGitter> <elorest> Ok. I’ve been doing ruby since 05 and I use both all the time. I also see both used in crystal in multiple libraries including the stdlib. It’s just weird to me that they’re different… I understand it being different from ruby but it’s weird that it’s different from itself as well.
<FromGitter> <johnjansen> yes predicatbility is essential
<Papierkorb> those two behaving the same would make sense, yes
mooe has quit [Quit: Connection closed for inactivity]
<FromGitter> <elorest> There might be a good reason they don’t but it seems weird to me
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
chimkan has quit [Quit: chimkan]
Nouv has quit [Quit: Nouv]
bjz has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
hightower has joined #crystal-lang
bjz has joined #crystal-lang
bjz has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<FromGitter> <elorest> @bew Would it be useful to add something like this to the core similar to ruby. https://play.crystal-lang.org/#/r/29s3
<FromGitter> <johnjansen> haha … deflated children … lovely
<FromGitter> <elorest> Sorry. Open office and someone was listening to michael Jackson. Got stuck in my head.
<FromGitter> <elorest> It’s fine though. they get inflated again at the end.
<FromGitter> <johnjansen> just dont overinflate them, that would make a mess in the open office
<FromGitter> <elorest> Generally you should never inflate children.
<FromGitter> <zatherz> is there any method to make a hash out of an array based on a method in each object in the array?
<FromGitter> <zatherz> builtin method ofc
<FromGitter> <zatherz> like, `[<#Something @a=1>, <#Something @a=2>]` into `{1 => <#Something @a=1>, 2 => <#Something @a=2>}`
<FromGitter> <codenoid> hi,, how to compile my app to Mac OS app ?
<FromGitter> <codenoid> i'm in linux
<FromGitter> <johnjansen> @zathers you could use a reduce on the array
<FromGitter> <johnjansen> ```code paste, see link``` ⏎ ⏎ as a thought experiment [https://gitter.im/crystal-lang/crystal?at=59543c774bcd78af56574048]
<FromGitter> <codenoid> ```cc your_program.o -o your_program -lpcre -lrt -lm -lgc -lunwind```
<FromGitter> <codenoid> ```/usr/bin/ld: cannot find -lgc ⏎ /usr/bin/ld: cannot find -lunwind``` [https://gitter.im/crystal-lang/crystal?at=59543cdcbf7e6af22c843316]
<FromGitter> <codenoid> is lgc and lunwind avaible on linux apt-get ?
chimkan has joined #crystal-lang
bjz has joined #crystal-lang