asterite changed the topic of #crystal-lang to: #crystal-lang The Crystal programming language | http://crystal-lang.org | Crystal 0.6.1 | Paste > 3 lines of text to https://gist.github.com | GH: https://github.com/manastech/crystal - Docs: http://crystal-lang.org/docs/ - API: http://crystal-lang.org/api/ - Logs: http://irclog.whitequark.org/crystal-lang
<jhass> . is the operator to call methods/functions, :: is the operator to access nested constants
<wanderer> jhass: e.g. there is LibC.mkdir and I need to write a wrapper for it, so that my function is called with the command `LibC.mkdir`, this is not possible?
<jhass> no, I don't think you can override bindings
<jhass> there's only a single call in stdlib to it
<jhass> just overwrite the method calling it
<wanderer> however, I need multiple wrappers for binded functions, so overwriting the calls everywhere is cumbersome
havenn has joined #crystal-lang
havenn has quit [Remote host closed the connection]
havenwood has quit []
wanderer has quit [Quit: Page closed]
havenwood has joined #crystal-lang
ponga has quit [Quit: Leaving...]
ponga has joined #crystal-lang
weskinner_mac has joined #crystal-lang
weskinner_mac has quit [Quit: weskinner_mac]
ismaelga has quit [Remote host closed the connection]
bcardiff has joined #crystal-lang
ponga has quit [Quit: Leaving...]
ponga has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]
ismaelga has joined #crystal-lang
ismaelga has quit [Ping timeout: 264 seconds]
<ponga> hi all
<ponga> why am i so busy these days
<ponga> ;(
havenwood has quit [Remote host closed the connection]
Ven has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ven has joined #crystal-lang
leafybasil has quit [Remote host closed the connection]
ismaelga has joined #crystal-lang
ismaelga has quit [Remote host closed the connection]
leafybasil has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
waj has joined #crystal-lang
Ven has joined #crystal-lang
waj has quit [Quit: Leaving.]
wanderer has joined #crystal-lang
waj has joined #crystal-lang
ismaelga has joined #crystal-lang
bcardiff has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ismaelga has quit [Remote host closed the connection]
Ven has joined #crystal-lang
ismaelga has joined #crystal-lang
ismael has joined #crystal-lang
ismael is now known as Guest65259
Guest65259 has quit [Remote host closed the connection]
ismaelga has quit [Ping timeout: 265 seconds]
asterite has joined #crystal-lang
ismaelga has joined #crystal-lang
havenwood has joined #crystal-lang
asterite has quit [Ping timeout: 246 seconds]
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<jhass> waj: what's the state currently? Is Socket still a normal socket? Does IO.select still work?
asterite has joined #crystal-lang
<asterite> jhass: Socket is just a socket, but in non-block mode. I think IO.select is broken, but I'm not sure
<asterite> Or… it should be done in another way
<jhass> interesting non-block mode
<jhass> IO.select seems to return a readable io and then gets on it blocks
<asterite> Well, its set in non-block, and the OS might tell you EAGAIN, and in that case we ask the scheduler to continue working
<wanderer> asterite: hey, is there a way to write functions in libs? def is not allowed, I need wrappers for calls like LibC.mkdir and such
<asterite> wanderer: Ah, I read something about what you said yesterday, but I don't understand well what you want to do
<asterite> Why you need to redefine LibC.mkdir in the first place?
<wanderer> asterite: because it's not the same on every OS, e.g. on windows it only has one parameter and so a solution would be to have a wrapper that accepts two, but ignores the second and calls the actual mkdir, that accepts only one
<wanderer> asterite: this way the calling code doesn't need to be modified
<asterite> mkdir in Windows is different?
<wanderer> asterite: or like, when mkdir doesn't exist at all and I'd want to implement it myself but leave the calling code as is
waj has quit [Quit: Leaving.]
<asterite> I think I'd use `ifdef` for now, inside the Dir.mkdir
<wanderer> asterite: what exactly do you mean?
<asterite> It's just one place, and it's better if the whole logic is there and we don't go changing definitions
<wanderer> asterite: it's a general problem, though
<asterite> ifdef windows; … ; else … ; end
<wanderer> asterite: windows doesn't have opendir, readdir, etc. an easy way would be to emulate these functions by having a wrapper for them, the crystal runtime code would stay the same
<wanderer> asterite: but when compiling for windows there would exist extra functions providing the missing opendir, readdir, ... functionality
<wanderer> asterite: another way would be to have ifdefs everywhere in Dir.mkdir in Dir.open, in Dir.each, etc., it wouldn't be as clean, though
<asterite> So you'd have the wrappers do the same as their C equivalent?
<asterite> I'm checking Ruby's source code, they use opendir, always, even for windows
<jhass> what if we introduce module LibCWrappers; end; and call through that in stdlib instead?
<asterite> Ah, no, sorry, you are right
<asterite> #define opendir(p) rb_w32_uopendir(p)
<wanderer> asterite: they have wrappers
<wanderer> asterite: under windows you can simply use FindFirstFile, you'd need to rewrite your whole code, though, with wrappers you don't need rewriting it, just some extra functions
<asterite> I see
<wanderer> asterite: also I wouldn't call them "C equivalent", well, those functions are written in C, they don't belong to C, though, but to POSIX
<wanderer> asterite: if the crystal runtime would only call standard C functions, porting to windows would be no problem, however, it has lots of calls to POSIX functions that don't exist in windows
<asterite> What if we allow function bodies in libs?
<asterite> I think in the case of dir we can have these wrappers, but in the general case the code will be very different
weskinner_work has joined #crystal-lang
<wanderer> asterite: well, the first thing I tried was "ifdef linux fun mkdir(...)... elsif windows def mkdir... end end", but `def` isn't recognized
<asterite> Yes, because only funs can go there
<asterite> What if you could do: lib LibC; fun opendir(…); your windows implementation; end
<wanderer> asterite: the second thing I tried was "lib LibC ... end def LibC.mkdir ... end" which kinda crashes the compiler with the msg "Bug: ...."
<asterite> wanderer: yes, I just fixed that (by giving an error message)
<asterite> (didn't push yet)
<wanderer> asterite: what would be the difference to `def`?
waj has joined #crystal-lang
waj has quit [Client Quit]
<asterite> def can ommit argument types, and can ommit return type. For fun you must put them, and also their mangling is kept the same
<wanderer> asterite: got to go, can we continue this talk somewhen later?
<asterite> wanderer: of course!
<asterite> I think for this it's better if you open a github issue, we can organize the ideas better there
<jhass> do we really need a language feature for this?
<jhass> why not proxy through a regular module
<wanderer> asterite: see you this evening or maybe later
<wanderer> bye jhass
wanderer has quit [Quit: Page closed]
<asterite> jhass: I think we can proxy through a regular module too
<jhass> ifdef linux; require "./libcwrappers/linux"; elsifdef windows; require "./libcwrappers/windows"; end; and so on
<jhass> and then in stdlib LibCWrappers.mkdir
<jhass> or something like that
<jhass> the name is shitty but you get the idea
<asterite> Yes
<asterite> I'm not sure we need to add more things to the language just for this
<jhass> yeah, why add a language feature if plain old OOP does just fine
<asterite> but it would be very easy to allow funs inside libs with a body
<jhass> still, IMO that's just another thing to learn which could avoided with very little overhead
<asterite> but I'm not sure it will be very used outside some random windows functions… but I have no idea about what the windows API looks like
<jhass> anyway, just fyi git head seems to break the way my bot reads from a socket
<jhass> .gets blocks indefinitely after a while
<asterite> I'll tell waj and we'll try to debug it
<asterite> You can try to stop using threads and using spawn and channels instead… at least to try the new things and give us feedback :-D
<jhass> for that I would need to have a clue about them though :P
<asterite> Oh, it's not that hard
<asterite> You can learn about goroutines and channels, it's the same
<jhass> aaand segfault!
<jhass> maybe llvm 3.6 is not that bug free yet :P
<jhass> specs passed thoguh!
<asterite> Really? Ugh...
<jhass> maybe I'm just dumb
<jhass> but debug info is gone.. so *shrug*
<jhass> ah, I'm just dumb
<jhass> stack overflow again
<asterite> Nah, we should make stack overflows say "stack overflow", it always takes some time for me to figure that out
<jhass> yeah
<jhass> I wonder if you can just trap some signal?
asterite1 has joined #crystal-lang
asterite has quit [Read error: Connection reset by peer]
DeBot has quit [Quit: Crystal]
DeBot has joined #crystal-lang
eli-se has joined #crystal-lang
waj has joined #crystal-lang
eli-se has quit [Quit: Leaving...]
eli-se has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]
bcardiff has joined #crystal-lang
<eli-se> hi there
weskinner_work has quit [Ping timeout: 246 seconds]
ismaelga has quit [Remote host closed the connection]
weskinner_work has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]
bcardiff has joined #crystal-lang
ponga has quit [Remote host closed the connection]
<asterite1> hi eli-se
ponga has joined #crystal-lang
ismaelga has joined #crystal-lang
eli-se has quit [Remote host closed the connection]
bcardiff has quit [Quit: Leaving.]
leafybasil has quit [Remote host closed the connection]
asterite has joined #crystal-lang
asterite1 has quit [Ping timeout: 244 seconds]
bcardiff has joined #crystal-lang
bcardiff has quit [Client Quit]
eli-se has joined #crystal-lang
waj1 has joined #crystal-lang
waj has quit [Ping timeout: 272 seconds]
wanderer has joined #crystal-lang
asterite1 has joined #crystal-lang
asterite has quit [Ping timeout: 255 seconds]
bcardiff has joined #crystal-lang
<wanderer> asterite1: hi again. like x86 stdcall, it's not windows thing, however, it's more of a general problem
<asterite1> But we can already solve what you need without changes to the language
<asterite1> the stdcall was impossible to do without a change
<asterite1> Like jhass said, we can have a module LibCWrappers and do LibCWrappers.mkdir
<asterite1> But I think just doing an ifdef on the sitecall for mkdir is just the same, and maybe cleaner
<asterite1> because it's just 3 lines of code vs many others
<wanderer> asterite1: yeah, but the crystal runtime contains many posix calls that are not present on other platforms
<wanderer> asterite1: all these calls would need an ifdef
<asterite1> Can you do it without an ifdef?
<asterite1> My point is, you will still need an ifdef saying "if I'm on windows I define this function like this"
<asterite1> Also, if you don't invoke a fun, crystal won't bother generating code for it, so unused posix functions won't bother
bcardiff has quit [Ping timeout: 256 seconds]
asterite1 has quit [Quit: Leaving.]
bcardiff has joined #crystal-lang
bcardiff has quit [Quit: Leaving.]
<wanderer> asterite: what exactly did you mean with "But I think just doing an ifdef on the sitecall for mkdir is just the same, and maybe cleaner"?
<wanderer> asterite: on windows mkdir could look like this: lib LibC; ifdef windows; fun _mkdir(a); def mkdir(a, b); _mkdir(a); end; end; end;
<wanderer> asterite: you still import windows' mkdir like you would on linux, but you have a wrapper for it that ignores the second parameter for posix
<wanderer> asterite: as for opendir: lib LibC; ifdef darwin || linux; fun opendir(name : UInt8*) : Dir*; elsif windows; fun FindFirstFile(...); def opendir(name : UInt8*) : Dir*; here comes code that uses FindFirstFile; end; end; end; on linux and mac this would import opendir, on windows opendir would be a normal function, the runtime doesn't need to be modified and still calls LibC.opendir
weskinner_work has quit [Ping timeout: 256 seconds]
eli-se has quit [Quit: Leaving...]
leafybasil has joined #crystal-lang
asterite has joined #crystal-lang
asterite_ has joined #crystal-lang
<asterite_> wanderer: when you say "runtime", what do you mean?
<wanderer> asterite_: with runtime I mean for example the regular Dir class
<asterite_> There's no "runtime" in Crystal except for the GC
<wanderer> asterite_: I simply mean the code itself
<wanderer> asterite_: when porting to other OSes there are two places for ifdef`s, 1. in the bindings like my example above or 2. in the code (that's what I meant with runtime) itself
<jhass> wanderer: stdlib is what we call it ;)
<jhass> or standard library
<wanderer> jhass: I called it runtime because of the CRT (C RunTime)
<asterite_> wanderer: what I mean is you can do something like this: https://gist.github.com/asterite/7876faa5716c25d861db
asterite has quit [Ping timeout: 256 seconds]
<asterite_> You can also put an ifdef surrounding the declaration of find_first_file
asterite has joined #crystal-lang
<wanderer> asterite: so either the `lib LibC; end` needs def`s so it can contains wrappers and such or all the ifdef`s go into the code, like `class Dir; def initialize(@path); ifdef linux || darwin; @dir = LibC.opendir(@path) ... elsif windows; .... ; end; end;`, which is the most simple solution but might bloat the code and make it hard to read
<asterite_> What you propose is something like this, I guess? https://gist.github.com/asterite/2a8e0deebefb788dda2b
<asterite_> One way or another, there's going to be an ifdef. It can be in Dir, or it can be in LibC
<asterite_> Another alternative, which is what jhass suggested, is this
bcardiff has joined #crystal-lang
<asterite_> Sorry, I'll fix somethin
<asterite_> There
<asterite_> That is, using a delegate module
<asterite_> If you compare the line lengths, you will see the solution I propose is the shortest. Not that line count matters, but I think it's the most direct, without indirections
<wanderer> asterite_: yes, I know there will be an ifdef, of course, and yes, those are the two ways I meant, however, it's not always as easy as in your example like simply substituting a call, that's why having the ifdef in the code would bloat it and transfering it into the `lib LibC; end` might help keeping things readable
asterite1 has joined #crystal-lang
asterite has quit [Ping timeout: 264 seconds]
<asterite_> I wouldn't worry much about that. Ruby's code, for example, is full of ifdef
<asterite_> but these standard library types are done once, and maybe corrected or fixed once in a while, they don't change much, and people usually don't read their source code because they work
<jhass> asterite_: wanderer a third version https://gist.github.com/jhass/1c9c483627b5aa845697
waj1 has quit [Quit: Leaving.]
asterite1 has quit [Remote host closed the connection]
<wanderer> asterite_: as a start I'll try the most straight-forwarded solution and have ifdef`s in the code and see if it works out smoothly
<wanderer> asterite_: however, this implies having kinda like two codebases which possibly means two places of error sources and two places of code to maintain
<wanderer> like in your first snippet
<asterite_> It's full of `version(Windows)` and others
<asterite_> Having two different versions because of the ifdef will inevitably make us have to test both versions, but we have specs covering that, so we just need to run them on windows
<wanderer> asterite_: how should the ifdef`s actually look? like `ifdef darwin || linux; elsif windows; end;`? always including all possible OSes in every ifdef is good for conformity rather than `ifdef windows; else; end`
<wanderer> I'd say
<wanderer> because there is code that looks like `ifdef darwin; else; end`, I would rewrite it as `ifdef darwin; elsif linux; end` to be more precise
<wanderer> this would exclude everything else, though
<asterite_> Yes, that would be more correct, but I think back then we didn't think about windows
<wanderer> but adding a new OS kind of includes reviewing the whole stdlib, though
<asterite_> Yes... but specs help :)
<wanderer> asterite_: yes, I just meant having really explicit ifdefs would require later additions when adding an OS, even if it's no different than an already added one, because then it would not fall into the else of the ifdef
<asterite_> Ah! I see... yes, it gives you an iterative process you can review
<wanderer> asterite_: however, for overall sanity I'd rather include specific elsif for an ifdef and add to that elsif
<wanderer> also, libpcre is always linked because of the `LibPCRE.pcre_malloc = ->GC.malloc(UInt32)`, even if not exactly required, isn't it?
leafybasil has quit [Ping timeout: 245 seconds]
leafybasil has joined #crystal-lang
<asterite_> Yes
<asterite_> because a regex is also part of the language, because it has an associated syntax
<wanderer> asterite_: is there a function converting a string to utf16 yet?
asterite_ has quit [Ping timeout: 246 seconds]
<crystal-gh> [crystal] asterite pushed 1 new commit to master: http://git.io/hZGy
<crystal-gh> crystal/master 84e2824 Ary Borenszweig: Error when trying to define def for lib
asterite has joined #crystal-lang
<asterite> wanderer: not yet. We still need encoding support (other than utf-8)
<asterite> !hangman
<jhass> !enable Hangman
<DeBot> jhass: Enabled Hangman.
<jhass> DeBot: !hangman
<DeBot> _______ [] 0/12
<jhass> DeBot: e
<DeBot> _E_____ [] 0/12
<jhass> hf :P
<asterite> DeBot: a
<DeBot> _EA____ [] 0/12
<asterite> DeBot: f
<DeBot> _EA____ [F] 1/12
<asterite> DeBot: l
<DeBot> LEA____ [F] 1/12
<asterite> DeBot: d
<DeBot> LEAD___ [F] 1/12
<wanderer> DeBot: b
<DeBot> LEAD___ [FB] 2/12
<asterite> DeBot: i
<DeBot> LEADI__ [FB] 2/12
<asterite> DeBot: n
<DeBot> LEADIN_ [FB] 2/12
<asterite> DeBot: g
<DeBot> LEADING [FB] 2/12 You won!
<asterite> Yay!
<asterite> Fun :)
<asterite> jhass: did you port it from your ruby version, or is it from scratch?
<jhass> from scratch
<asterite> I wonder how you make sure these work, I don't see tests ;-)
<jhass> well, you just tested it!
<jhass> yolo code for now really :P
<jhass> I hate speccing network apps
<asterite> Ah, yes... even with stubs/mocks, it's so tedious...
<wanderer> I had written some funcs for C regarding conversion of utf-8 here: https://github.com/abcbishop/utf.c/blob/master/utf.c