jhass changed the topic of #crystal-lang to: The Crystal programming language | http://crystal-lang.org | Crystal 0.13.0 | Fund Crystals 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
<onec> I assume that makes it a 50/50 chance? If so, the p and q values will change in future generations, but I have not implemented that yet
<jokke> use range with .each
<jokke> no you don't even need that
<jokke> use n.times
<jokke> ah i see
<jokke> yes, then sample is the wrong way to go
sp4rrow has joined #crystal-lang
<onec> Ok, I'll start working on rewriting it. Thanks for the help jokke!
pawnbox has joined #crystal-lang
<jokke> :) no problem
Philpax has joined #crystal-lang
<jokke> if this really needs to be fast and $gametes is very large you might want to consider a binary tree instead of an array
<jokke> oh ok n is very smalll
<jokke> yoy can use underscore btw to separate thousands
<jokke> like this: 9_001 (it's over nine thousand)
pawnbox has quit [Ping timeout: 244 seconds]
<jokke> cool that you're using crystal for genetics ;)
<onec> jokke: So I have not yet gotten to rewrite it, but I just added in a quick change to implement multiple generations. https://gist.github.com/justinpchang/1b25d318ebed0c9ac4a2 If you run it, the output is this: http://pastebin.com/iuDC7KWj
<onec> If you look between the "hello" and "goodbye" debug messages, it does float division like it should when creating the second generation, but when creating the third generation, it does integer division ( 6/10 = 0).
<onec> The corresponding line in the code is 70-74
Gasher has quit [Quit: Leaving]
<onec> Is there any way to make sure that float division rules are followed? Or explicitly specify types?
<jokke> onec: sure. just use .to_f on one of the variables
<onec> Nevermind, I got it! When I reset values in 78-83, I set them as 0, so I guess it was assumed an int. yeah I just put _f64 after the 0s and its fixed
<jokke> onec: btw, if you're interested in comparing performance of binary tree vs array with sort!
<jokke> be sure to compile with --release
<crystal-gh> [crystal] asterite pushed 3 new commits to master: https://git.io/vau3i
<crystal-gh> crystal/master fc70098 Ary Borenszweig: Fixed `Object#getter?` macro, it was declaring type as nilable
<crystal-gh> crystal/master d55c58c Ary Borenszweig: Added `OpenSSL::SSL::Socket#sync_close` and use it in HTTP::Client, HTTP::Server and HTTP::WebSocket
<crystal-gh> crystal/master 2aacd05 Ary Borenszweig: Added `sync_close` to `Zlib::Deflate` and `Zlib::Inflate`
<jokke> asterite: you there?
<onec> jokke: Ah ok. I'll be sure to use binary trees when I rewrite it.
<jokke> that's not even self-balancing
<jokke> so you might get even better results with self balancing trees
pawnbox has joined #crystal-lang
Philpax_ has joined #crystal-lang
pawnbox has quit [Ping timeout: 248 seconds]
Philpax has quit [Ping timeout: 252 seconds]
<travis-ci> crystal-lang/crystal#2aacd05 (master - Added `sync_close` to `Zlib::Deflate` and `Zlib::Inflate`): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/116272620
Philpax_ has quit [Ping timeout: 260 seconds]
Philpax_ has joined #crystal-lang
sp4rrow_ has joined #crystal-lang
sp4rrow has quit [Read error: Connection reset by peer]
<onec> jokke: This speed is amazing. Completely unoptimized: 3000 generations with 500 individuals per generation in about 1.2 seconds
sp4rrow_ has quit [Read error: Connection reset by peer]
pawnbox has joined #crystal-lang
sp4rrow has joined #crystal-lang
<jokke> :)
pawnbox has quit [Ping timeout: 244 seconds]
sp4rrow has quit [Read error: Connection reset by peer]
A124 has quit [Quit: '']
sp4rrow has joined #crystal-lang
A124 has joined #crystal-lang
sp4rrow_ has joined #crystal-lang
sp4rrow_ has quit [Client Quit]
sp4rrow has quit [Ping timeout: 248 seconds]
jnylen has quit [Ping timeout: 260 seconds]
marcosdsanchez has quit [Ping timeout: 246 seconds]
marcosdsanchez has joined #crystal-lang
<onec> jokke: How would I use the 16 random bytes that Base64.decode(SecureRandom.base64) returns to generate a random float between 0.0..1.0?
Philpax_ has quit [Ping timeout: 260 seconds]
mambocab has joined #crystal-lang
pawnbox has joined #crystal-lang
Philpax has joined #crystal-lang
pawnbox has quit [Ping timeout: 246 seconds]
<onec> would `SecureRandom.random_bytes(1).at(0)/255_f64` work?
<mambocab> is this expected behavior for `spec`'s `should` on empty containers, or is this a bug? couldn't find any reports on github, but I may not have the right search strings: https://gist.github.com/mambocab/29653d1764e0e83bd836
Philpax has quit [Read error: Connection reset by peer]
kulelu88 has joined #crystal-lang
Philpax has joined #crystal-lang
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 260 seconds]
mgarciaisaia has joined #crystal-lang
Philpax has quit [Ping timeout: 260 seconds]
<asterite> mambocab: yes, two arrays are the same if they have the same size and their values are equal in each position, so that is trivially true for two empty arrays
kulelu88 has quit [Quit: Leaving]
<mambocab> so, to be clear, array equality doesn't depend on the compared array's types? I'm totally new, so just trying to make sense of things
<asterite> mambocab: exactly, it only depends on the array sizes and the actual values in the array
<mambocab> perfect, much appreciated
<asterite> But, for example, [1] == [1.0], because 1 == 1.0, even though 1 is Int32 and 1.0 is Float64
<mambocab> oh, huh, ok
Philpax has joined #crystal-lang
<mambocab> so, i take it type enforcement in comparisons is totally up to the methods implementing those comparisons
<mambocab> I think I see
mgarciaisaia has left #crystal-lang [#crystal-lang]
jokke has quit [Ping timeout: 264 seconds]
jokke has joined #crystal-lang
greengriminal has joined #crystal-lang
greengriminal has quit [Client Quit]
Philpax has quit [Ping timeout: 260 seconds]
<crystal-gh> [crystal] jessedoyle closed pull request #1705: Implement ruby-style method visibility (master...visibility-syntax) https://git.io/vauX4
marcosdsanchez has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<rkeene> BlaXpirit, I'm particularly interested in stuff like fork() and wait()
mgarciaisaia has joined #crystal-lang
pawnbox has quit [Ping timeout: 240 seconds]
vagmi has joined #crystal-lang
jnylen has joined #crystal-lang
stef__ has joined #crystal-lang
zodiak has quit [Ping timeout: 240 seconds]
pawnbox has joined #crystal-lang
greengriminal has joined #crystal-lang
pawnbox has quit [Ping timeout: 250 seconds]
bjz has joined #crystal-lang
vagmi has quit [Quit: vagmi]
vagmi has joined #crystal-lang
bjz has quit [Ping timeout: 248 seconds]
pawnbox has joined #crystal-lang
pawnbox has quit [Ping timeout: 248 seconds]
bjz has joined #crystal-lang
vagmi has quit [Read error: Connection reset by peer]
vagmi has joined #crystal-lang
<rkeene> Why do I get the type Nil inside an "if" where it can never be Nil ?
<rkeene> if (channel); blahDoesNotAcceptNil(channel); end says: argument 'channel' of 'LibSSH#channel_write' must be LibSSH::Channel, not (LibSSH::Channel | Nil:Class)
pawnbox has joined #crystal-lang
Philpax has joined #crystal-lang
bjz_ has joined #crystal-lang
bjz has quit [Ping timeout: 260 seconds]
<rkeene> I really can't see why this is failing
<rvchangue> You tried to pass a union type to a function that expects a LibSSH::Channel. If you are sure that channel is not Nil, try blahDoesNotAcceptNil(channel.not_nil!)
<mambocab> rvchangue: shouldn't leading with `if channel` do that?
<rkeene> Right, it CAN'T be Nil
<rvchangue> Ah. I don't think the compiler is smart enough to do that yet
onec has quit []
<rkeene> argument 'channel' of 'LibSSH#channel_write' must be LibSSH::Channel, not (LibSSH::Channel | Nil:Class) LibSSH.channel_write(channel.not_nil!, "% ".to_unsafe() as Pointer(Void), "% ".bytesize());
<rkeene> It still fails with not_nil!
<rkeene> I don't know how I can make this compile
<rkeene> Any ideas ?
<mambocab> wait, did I see if channel \n exit \n end <use channel> ? a similar control flow isn't compiling for me, looks like the non-null inference only works inside the conditional block itself. looks like you already tried that based on your earlier comment though
<rkeene> if !channel; exit; end
<mambocab> right
tomchapi_ has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
<rkeene> if !channel; exit; end; if channel; use(channel); end still fails thinking channel can be Nil
<rkeene> And channel.not_nil! thinks it can be Nil as well
mgarciaisaia has quit [Quit: Leaving.]
<rkeene> If I explicitly check that it's a LibSSH::Channel then it works
<mambocab> good find. weird
<rkeene> But only if I do it near the use
<rkeene> Or rather, around the use
<mambocab> if I understand correctly, it has to be a local variable and you have to use it in the guarded block
<rkeene> The documentation says this should work :-(
<mambocab> i guess in the `exit` case you might be able to redefine `exit`? haven't tried that, but maybe that's the case they're guarding against
<rkeene> Well, even if I "break" from the loop...
vagmi has quit [Quit: vagmi]
<mambocab> sure
emmanueloga has quit []
emmanueloga has joined #crystal-lang
rok has joined #crystal-lang
vagmi has joined #crystal-lang
greengriminal has quit [Quit: Leaving]
trapped has joined #crystal-lang
matp has quit [Ping timeout: 250 seconds]
alsm has joined #crystal-lang
Dreamer3_ has quit [Quit: Leaving...]
<crystal-gh> [crystal] ysbaddaden opened pull request #2309: Fix: LibC.mmap and off_t definitions (master...fix-mmap-declaration-for-musl-libc) https://git.io/vazkq
matp has joined #crystal-lang
vagmi has quit [Quit: vagmi]
vagmi has joined #crystal-lang
vagmi has quit [Quit: vagmi]
vagmi has joined #crystal-lang
vagmi has quit [Quit: vagmi]
triangles has joined #crystal-lang
vagmi has joined #crystal-lang
Gasher has joined #crystal-lang
rok has quit [Quit: rok]
vagmi has quit [Quit: vagmi]
vagmi has joined #crystal-lang
vagmi has quit [Quit: vagmi]
vagmi has joined #crystal-lang
vagmi_ has joined #crystal-lang
vagmi has quit [Ping timeout: 240 seconds]
vagmi_ is now known as vagmi
Dreamer3 has quit [Ping timeout: 260 seconds]
matp has quit [Ping timeout: 250 seconds]
<asterite> rkeene: the docs doesn't say anything about "!", you must use `unless x`
Dreamer3 has joined #crystal-lang
Dreamer3 has quit [Max SendQ exceeded]
vagmi has quit [Quit: vagmi]
Dreamer3 has joined #crystal-lang
matp has joined #crystal-lang
Philpax has quit [Ping timeout: 244 seconds]
luislavena has joined #crystal-lang
rok has joined #crystal-lang
<crystal-gh> [crystal] asterite pushed 2 new commits to master: https://git.io/vazpC
<crystal-gh> crystal/master d1cd3cb Julien Portalier: Fix: LibC.mmap last arg is a off_t not ssize_t (and off_t is always 64bits on musl-libs)
<crystal-gh> crystal/master 95dd4d9 Ary Borenszweig: Merge pull request #2309 from ysbaddaden/fix-mmap-declaration-for-musl-libc...
<travis-ci> crystal-lang/crystal#95dd4d9 (master - Merge pull request #2309 from ysbaddaden/fix-mmap-declaration-for-musl-libc): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/116374696
mgarciaisaia has joined #crystal-lang
crystal-lang477 has joined #crystal-lang
mgarciaisaia has left #crystal-lang [#crystal-lang]
crystal-lang477 has quit [Ping timeout: 252 seconds]
marcosdsanchez has joined #crystal-lang
marcosdsanchez has quit [Client Quit]
marcosdsanchez has joined #crystal-lang
marcosdsanchez has quit [Quit: Lost terminal]
marcosdsanchez has joined #crystal-lang
pawnbox has quit [Remote host closed the connection]
pawnbox has joined #crystal-lang
<rkeene> asterite, But they say break should affect it
<rkeene> asterite; while true; if !x; break; end; use(x); end; should mean use(X) can't be Nil
mgarciaisaia has joined #crystal-lang
mgarciaisaia has left #crystal-lang [#crystal-lang]
<asterite> rkeene: if you do `unless x; break; end`, does it work
<asterite> ?
<rkeene> asterite, No
<asterite> rkeene: please share a code that I can execute and I'll try to see the problem
<rkeene> I can send you what I'm working on now if you want, making a smaller case seesm to be difficult
<rkeene> makeitso-enterprise.cr: https://chiselapp.com/user/rkeene/repository/makeitso/artifact/0711762d697125d5 libs/ssh/ssh.cr: https://chiselapp.com/user/rkeene/repository/makeitso/artifact/de17bce2fbaeda6f those two files.. you can remove interp = Tcl::Interp.new() and then the resulting reference to "interp"
<rkeene> If you remove the if channel.is_a?(SSH::LibSSH::Channel)/end pair and then add: unless channel; break; end to the top of the loop it fails to compile
rok has quit [Quit: rok]
<asterite> rkeene: I don't understand, this works: https://play.crystal-lang.org/#/r/ubg
<asterite> If you change you `if !x` to `unless x`, it should work. I can't copy and past all of that and try it out, you'll have to reduce the code a lot more
<rkeene> It would take a lot of work to reduce it, but clearly it SHOULD work
<asterite> I also don't know why channel also has the type Nil:Class there
<asterite> I mean, Nil
<asterite> (the class)
<rkeene> There's no way it can
<asterite> rkeene: what I need is a single file I can copy and paste to reproduce the problem. Otherwise give me a git repo that I can checkout and try. I'll loose a lot of time if I have to figure out how to put all the pieces together. Please? :-)
<asterite> The file can be as long as you wish
<rkeene> I can just concat those two files I sent you
pawnbox_ has joined #crystal-lang
pawnbox has quit [Ping timeout: 268 seconds]
<rkeene> Does that help ?
<rkeene> Where is "spawn" documented ?
<donpdonp> rkeene: i asked that yesterday and apparently there arent any
<rkeene> Hmm, what does "spawn" do and how do I use it ?
tamole has joined #crystal-lang
tomchapin has joined #crystal-lang
<rkeene> Should I just give up on Crystal for now until it's more mature ?
<donpdonp> look at the existing libs, many things are currently possible. http://awesome-crystal.com/
<rkeene> But how many of those actually work ?
<donpdonp> my guess is all of them.
<rkeene> Given that there are bugs in Crystal itself I find that HIGHLY unlikely
<donpdonp> well they're there to try and find out.
<rkeene> None of them do anything I'm interested in at this time
<asterite> I'm currently writing a guide on concurrency, I guess at the end of the day I'll have it ready
<donpdonp> asterite++
<rkeene> The thing I'm doing now is just building an SSH server that talks to Tcl
<asterite> rkeene: you have `channel = Nil` in your code
<asterite> if I change it to `channel = nil`, it works
<asterite> That's why I told you there was a Nil type in channel :-)
<asterite> (phew, at first I thought there might be a bug with the type flow inference)
<rkeene> That makes me feel better
<rkeene> Also, "exit" doesn't cause type exclusion
<BlaXpirit> rkeene, ok, everything is in order
<jokke> asterite: !
<jokke> asterite: i don't know if you get highlights from irc, so here i go again :) I'm writing my thesis largely about a backend for a json-api i wrote in crystal. Would be great if you could point me to some documents or other resources i could cite in my thesis.
<jokke> maybe some statistics or performance analysis you guys did at manastec
<crystal-gh> [crystal] asterite pushed 2 new commits to master: https://git.io/vagdr
<crystal-gh> crystal/master 52fde8d Ary Borenszweig: Added `Deque#delete(obj)`
<crystal-gh> crystal/master ecb1766 Ary Borenszweig: Use Deque for concurrency (scheduler, channels, readers, writers), and use `shift` instead of `pop`....
tamole has quit [Quit: bye]
mgarciaisaia1 has joined #crystal-lang
alsm has quit [Ping timeout: 244 seconds]
<travis-ci> crystal-lang/crystal#ecb1766 (master - Use Deque for concurrency (scheduler, channels, readers, writers), and use `shift` instead of `pop`.): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/116430165
triangles has quit [Quit: Leaving]
mgarciaisaia1 has left #crystal-lang [#crystal-lang]
<rkeene> I'm trying to write a callback to C that wraps a Proc in a pointer
riceandbeans has joined #crystal-lang
<riceandbeans> wasn't sure if this project was still alive or not
<rkeene> The Proc being passed in is not a closure, but referencing the Proc in the wrapper function makes that a closure -- I have a Void* I can use to pass pointers around, so I stuffed the proc as a pointer into that and now I'm not sure how to get it out
<rkeene> block = Proc(LibTcl::Interp, Array(String), LibTcl::ClientData -> LibTcl::ReturnValue).new(clientData as Pointer(Proc(LibTcl::Interp, Array(String), LibTcl::ClientData -> LibTcl::ReturnValue))); did not work
<rkeene> Ah, getting there
<rkeene> I was using too much syntax for once :-D
luislavena has quit [Ping timeout: 248 seconds]
<rkeene> Hmm, it compiled using Box, but it still thinks it is a closure
<asterite> Oh, didn't see the last line
<riceandbeans> Box?
<riceandbeans> like box.com?
Ven has joined #crystal-lang
<rkeene> So do fibers create OS threads in Crystal (unlike most other languages) -- or, how do you create threads/processes for concurrency ?
<donpdonp> rkeene: i believe the current answer is 'you dont'
<rkeene> :-/ Not very useful for a server that may block for hours and days
<rkeene> asterite, Right, I was reading that
<donpdonp> asterite: awesome!!
<rkeene> asterite, You really shouldn't say a fiber is similar to an OS thread -- they're not really similar (I've been doing fibers for ~20 years now, starting with setjmp/longjmp-based implementations and using protothreads as well)
<donpdonp> i agree, different wording would be better.
<rkeene> I guess you do qualify it with "in a way"... but they really lack similarities other than you may have state associated with one
<asterite> rkeene: well, it's a unit of execution
<asterite> but yes, I guess I could change that. But if I don't say "it's in a way similar to thread", I don't know what other maybe familiar concept to associate so the reader has at least an idea of what it's similar to
<rkeene> Somewhat related, the Tcl threading extension model is awesome at this -- you operate by sending messages to other thread's event loops (either syncronously or asyncrounously)
<asterite> in any case, it's just a first write up, there's a lot to be improved
<rkeene> I would definitely say it's a threading model, but it's not much like OS threads
<crystal-gh> [crystal] asterite closed pull request #2113: Explaining concurrency (gh-pages...explaining-concurrency) https://git.io/va2G2
<rkeene> http://rkeene.org/projects/info/wiki/14 is what I wrote on it
<crystal-gh> [crystal] asterite closed pull request #2306: Allows passing flags to disable linking of openssl and zlib (master...feature/without) https://git.io/va4ED
Ven_ has joined #crystal-lang
Ven has quit [Ping timeout: 246 seconds]
Ven_ has quit [Client Quit]
<rkeene> Ah, self was causing it to be a closure
luislavena has joined #crystal-lang
Ven has joined #crystal-lang
Ven has quit [Client Quit]
<rkeene> I guess I can work around Crystal's lack of threads with Tcl's threads
<travis-ci> crystal-lang/crystal#0b7742c (master - Merge pull request #2306 from crystal-lang/feature/without): The build passed. https://travis-ci.org/crystal-lang/crystal/builds/116454919
<RX14> rkeene, why do you need threads?
<rkeene> RX14, I'm writing an SSH server that users will execute commands on
<RX14> so it spawns shells
<RX14> and moves the TTY data through a socket
<RX14> why does that need threads?
<rkeene> It doesn't spawn anything or create a TTY
<rkeene> It directly executes the commands as part of the process
<RX14> ok
<RX14> but still why does it need threads?
riceandbeans has left #crystal-lang [#crystal-lang]
<rkeene> Bceause the commands it executes may be long-running
<RX14> computationally hard?
<rkeene> They are free-form commands from the user, so they could be anything
<RX14> just fork() for each session like SSHd does
<rkeene> I presume Crystal will break if I do that, which is why it lacks a fork() call ?
<RX14> iirc it has fork
<RX14> yep
<RX14> fork's a thing
<rkeene> Ah, how does that work on Windows ?
<RX14> crystal doesn't work on windows
<RX14> at all
<rkeene> Oh... Well, that's unfortunate
<RX14> yes, yes it is
<rkeene> I'll move this over to Go I guess
<crystal-gh> [crystal] luislavena opened pull request #2310: Sync output sent to STDERR similar to STDOUT (master...sync-stderr) https://git.io/va2ui
<luislavena> asterite: tried -D without_openssl -D without_zlib (on local working copy) and still got .build/crystal linked to libz :-P
<rkeene> Primitive starting point for a Tcl interface with Crystal: https://chiselapp.com/user/rkeene/repository/makeitso/artifact/f79b09f943c4ce5a (I like Tcl because I can statically link it and have no external dependencies at all) and one done on an deprecated libssh API (that I didn't know was deprecated since their docs suck): https://chiselapp.com/user/rkeene/repository/makeitso/artifact/56a3afee54b38e86 (most of the import was autogenerated)
<asterite> luislavena: Ah, yes. I think zlib is required by llvm, so `without_zlib` doesn't seem to be very useful (well, yes if you aren't using llvm, but for our case in the compiler it's useless)
<asterite> In any case, with those flags I was able to build a compiler that includes an embedded http server in it
<asterite> I mean, make omnibus be happy about that :-)
marcosdsanchez has quit [Read error: Connection reset by peer]
<luislavena> asterite: excellent
marcosdsanchez has joined #crystal-lang
pawnbox_ has quit [Remote host closed the connection]
Ven has joined #crystal-lang
pawnbox has joined #crystal-lang
Ven has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
pawnbox has quit [Ping timeout: 260 seconds]
ragmaanir has joined #crystal-lang
perks has joined #crystal-lang
greengriminal has joined #crystal-lang
pawnbox has joined #crystal-lang
<ragmaanir> can i use threads in crystal? are they stable? because im getting some errors in my example.
<ragmaanir> should the example work?
pawnbox has quit [Ping timeout: 248 seconds]
<RX14> ragmaanir, no, threads don't really work in crystal
<RX14> not with IO anyway
<RX14> you should use fibers
<ragmaanir> ok, thanks. i was unsure wether there was something i missed.
<RX14> fibers are somewhat better than threads
<rkeene> Fibers are better at threads at some things while threads are better than fibers at most things where concurrency is needed
<ragmaanir> but fibers are single-threaded, if i understand correctly. you have to inset jumps between them in your code. cant do that in my situation i think. im starting external programs.
<RX14> ragmaanir, not really
<RX14> because all IO operations rescedule the fiber
<RX14> and sleep too
<RX14> rkeene, work is being done on making fibers multicore
<rkeene> Well, it's correct that fibers are cooperative multithreading (where OS threads are preemptive multithreading) so you can only yield control of the thread of execution in specific places
<ragmaanir> i see. k, i will give it a try. otherwise ill just run the script with ruby.
<ragmaanir> thanks for the info :-)
<RX14> for most workloads, you'll be doing IO, so fibers work great
Philpax has joined #crystal-lang
<rkeene> As an example of where this is false I wrote a program in C that uses Fibers (via protothreads) and OS Threads (via pthreads) to do something extremely I/O bound, the pthreads version was significantly better in every way.
<ragmaanir> well: i want to start multiple processes simultaneous by calling my cystal script, and it should kill those spawned processes when the script is terminated (kinda like foreman).
<RX14> ragmaanir, you shouldn't really even need threads or fibers for that
<RX14> just use a non-blocking spawn call
<ragmaanir> since i dont have much experience with linux processes/threads and their quirks, my idea was to use two threads in my script to spawn the processes
<rkeene> http://www.rkeene.org/viewer/tmp/mirrorget.c.htm is the protothreads version, trivially adapted to pthreads (the version of which I cannot find)
<ragmaanir> RX14: ok. ill try. when i spawn the processes, do i have access to the process id of the spawned processes?
<RX14> yes
<ragmaanir> i remember i had trouble doing that in ruby
<ragmaanir> ok. ill just hack away then. thank you :)
<RX14> Process.run is what you want
<RX14> it will return a process object with a pid
<RX14> like
<RX14> p = Process.run("command")
<RX14> p.pid
<ragmaanir> ok, thanks. i gonna ask if im stuck
<RX14> actually
<RX14> i'm wrong
<RX14> you want Process.new()
<RX14> Process.run waits for it to finish
<ragmaanir> oh, i see
luis_lavena has joined #crystal-lang
luis_lavena has quit [Read error: Connection reset by peer]
<RX14> if you use output: nil, error: nil in process.new, it will actomatically copy the child stdout/err to the parent stdout/err
<RX14> >> Process.new("yes", output: nil, error: nil)
<DeBot> RX14: # => #<Process:0x8503fa0 @wait_count=0, @channel=nil, @input=nil, @output=#<IO::FileDescriptor:0x84ffe10 @edge_triggerable=false, @flush_on_newline=false, @sync=false, @closed=false, @read_timed_out=false, @write_timed_out=false, @fd=8, @in_buffer_rem=[], @out_count=0, @read_timeout=nil, @write_timeout=nil, @readers=[], @writers=[], @read_event=nil ... - https://carc.in/#/r/ubs
<RX14> >> Process.new("yes", output: nil, error: nil); sleep 5
<DeBot> RX14: # => nil - https://carc.in/#/r/ubt
<RX14> oh
<RX14> it's true
<RX14> not nil
<RX14> >> Process.new("yes", output: true, error: true); sleep 1
<BlaXpirit> RX14, what's that supposed to do?
<RX14> well judging by the lack of DeBot response, print many many many lines of "yes"
<RX14> actually
<RX14> just y
<BlaXpirit> >> Process.new("crystal", output: true, error: true); sleep 1
<RX14> >> Process.new("echo 'hi'", output: true, error: true); sleep 1
<RX14> i bet process is locked down
<BlaXpirit> >> puts "DeBot pls"
<RX14> oops
<RX14> did i break it?
<BlaXpirit> carc.in is down too
<BlaXpirit> jhass !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
<RX14> kekekeke
<RX14> i think i broke carc.in
<RX14> no
<RX14> it's up fopr me
<BlaXpirit> oh really?
<RX14> well
<RX14> not working
<RX14> http 500
<BlaXpirit> i suppose "down" isn't really the word
<RX14> i broke it lol
<BlaXpirit> but doesnt change things much
<RX14> .help
<RX14> ?help
<DeBot> RX14: Nothing known about help.
<RX14> oh
<RX14> well
<RX14> its carc not debot anyway
marcosdsanchez has quit [Read error: Connection reset by peer]
marcosdsanchez has joined #crystal-lang
slash_nick is now known as slash_mode
<BlaXpirit> worst thing is, it might be eating the resources of jhass's computer
<BlaXpirit> like 100% cpu and storing that stream of 'y' in memory
<RX14> yup
<RX14> "oops"
<RX14> should have sandboxed better
<ragmaanir> lol, im sorry for indirectly causing that by asking that question ^^
<RX14> well
<RX14> it's mainly my fault
<RX14> but yes
<RX14> spawning with output: true redirects process output to parent output
<RX14> same for error: true
<ragmaanir> thats exactly what i want i think. IIRC that was the thing i tried to achieve in ruby and struggled with it until i used threads.
<RX14> well crystal isn't really ruby
<RX14> just heavily inspired
<RX14> it's not aiming for compatibility
<RX14> which means the stdlib is pretty clean
<ragmaanir> i know. i have been working with crystal for a while now. i am moving all my private ruby projects to crystal because i like the language better.
<ragmaanir> i also like the static typing and macros.
<RX14> yup
<RX14> crystal is the langauge I would most want to start a project in these days
<RX14> I do need to recreate jade/slim in crystal though
<ragmaanir> me too. i was programming a bit in scala, but java compatibility comes with a big load of old libraries and deprecated apis, also the scala standard library is a huge mess IMO.
<ragmaanir> im going for a single page app with mithril.js and typescript.
<RX14> i'm sure in 10 years crystals' stdlib will be a huge mess
<RX14> or crystal will be dead
<RX14> but I hope the former
<ragmaanir> im not so sure about that. i think the crystal stdlib is quite clean and does not need so many additions (ruby has been around for years and its standard library is also quite clean compared to eg. java).
<RX14> well
<RX14> ruby's stdlib is still pretty messy tbh
greengriminal has quit [Ping timeout: 250 seconds]
greengriminal has joined #crystal-lang
pawnbox has joined #crystal-lang
Philpax has quit [Ping timeout: 244 seconds]
pawnbox has quit [Ping timeout: 244 seconds]
luislavena has quit [Quit: Leaving]
benner_ has quit [Read error: Connection reset by peer]
benner has joined #crystal-lang
emancu has joined #crystal-lang
rvchangue has quit [Ping timeout: 248 seconds]
DylanJ has quit [Ping timeout: 276 seconds]
badeball has quit [Ping timeout: 277 seconds]
badeball has joined #crystal-lang
jamie_ has joined #crystal-lang
rvchangue has joined #crystal-lang
grindhold_ has joined #crystal-lang
jamie_ca has quit [Ping timeout: 260 seconds]
grindhold has quit [Ping timeout: 260 seconds]
jamie_ is now known as jamie_ca
DylanJ has joined #crystal-lang
<ragmaanir> RX14: mh, it doesnt seem to work with Process.new :-/ Gist: https://gist.github.com/Ragmaanir/c36a68183aab22bd3cfb
<ragmaanir> when i ps aux | grep for the pid it does not return any results. also, "tests" is not printed.
<ragmaanir> event when i add pr.wait, the program exits immediately.
<RX14> hmmn
greengriminal has quit [Quit: Leaving]
<ragmaanir> i also tried to explicitly pass STDOUT and STDERR, no change
<ragmaanir> crystal v0.13.0 btw, just to make sure
<RX14> that's weird
<RX14> but i'm seeing that too
DylanJ has quit [Read error: Connection timed out]
<BlaXpirit> RX14, what are you trying to do?
<BlaXpirit> uhh RX14
<BlaXpirit> uhh ragmaanir
DylanJ has joined #crystal-lang
<RX14> what?
<RX14> even Process.run doesn't work for me
<ragmaanir> trying to start two processes from one script that then shows the output of the two processes. and when i terminate the script both processes should terminate.
<BlaXpirit> what do you mean, doesn't work?
<ragmaanir> kinda like foreman
<RX14> BlaXpirit, `Process.run("sleep 5")` exists immediately
<BlaXpirit> that's probably because there is no file "/usr/bin/sleep 5"
<ragmaanir> ups, good point i think
<BlaXpirit> Process.run("sleep", ["5"]) works, anyway
<RX14> ohh
<RX14> shell is false by fefault
<RX14> :/
<RX14> yup
<RX14> crystal eval 'Process.new("sleep 5", shell: true, output: true, error: true).wait'
<RX14> works
<ragmaanir> yeah, for me too. thanks!
<RX14> I was looking through the source, and saw the shell stuff without realising it was in "if shell"
<BlaXpirit> dont use shell
<RX14> BlaXpirit, you mean, don't use shell unless you need it
<BlaXpirit> yeah and you don't ever need it
<BlaXpirit> at least if the language/stdlib is adequate :|
<RX14> what do you mean?
<RX14> sometimes you want to evaluate stuff in a shell
<RX14> rare
<RX14> but
<RX14> useful
<emancu> @here is there a way to not include the Spec::ObjectExtensions into every Object?
<emancu> or a way to remove those methods
<BlaXpirit> emancu, probably not
<BlaXpirit> this is such a trashy testing framework
<BlaXpirit> even if you use power_assert you still can't get rid of this pollution
<emancu> I'm creating a super small test framework as protest/cutest on ruby
<BlaXpirit> bleh power_assert is all the testing anyone can need
<RX14> yeah
<emancu> @BlaXpirit i never read about it
<emancu> checking the github repo
<BlaXpirit> the language has such power but people opt for this DSL trash
<RX14> groovy's assert was a real eye opener for me
<RX14> and power_assert is literally a port
<ragmaanir> i also use power_assert, love it
<BlaXpirit> here's what I wrote before I found out it's all been done in power_assert http://blaxpirit.com/blog/17/detailed-assert-macro-for-crystal.html
<RX14> well
<RX14> power_assert is one part of the puzzle solved: assertions
<RX14> but a whole framework is a different story
<RX14> spock for groovy is a very, very nice framework
<RX14> I would love to port it to crystal
<BlaXpirit> RX14, well you can still use the builtin framework, just with power_assert instead of .should
<RX14> yeah
<RX14> i know
<RX14> but it doesn't have the features of spock
<RX14> the data-based tests are amazing
<RX14> def "maximum of two numbers"(int a, int b, int c) {
<RX14> expect:
<RX14> Math.max(a, b) == c
<RX14> a | b | c
<RX14> where:
<RX14> 1 | 3 | 3
<RX14> 7 | 4 | 4
<RX14> 0 | 0 | 0
<RX14> }
<BlaXpirit> :o
<RX14> yeah
<RX14> spock is beatutiful
<RX14> when:
<RX14> stack.push(elem)
<RX14>
<RX14> then:
<RX14> !stack.empty
<RX14> stack.peek() == elem
<RX14> stack.size() == 1
<RX14> I can imagine macros being able to translate all that nicely into groovy
<RX14> s/groovy/crystal
<BlaXpirit> this last one is indeed doable
<RX14> you should be able to override | operator
<ragmaanir> is there multiline macro support in crystal? or do you have to use blocks?
<RX14> or, really
<RX14> just unpick it all with a macro
<BlaXpirit> RX14, well... there would be problems with operator precedence
<RX14> not if you unpick it all with a macro :P
<BlaXpirit> like you could split the expression by bitwise or
<BlaXpirit> RX14, but you can't really
<RX14> well
<RX14> if we had proper AST access...
<BlaXpirit> maybe with a vrey complex transformation
<RX14> well
<RX14> can't you just convert the block to a string
<RX14> and parse it manually
<BlaXpirit> probably not
<BlaXpirit> because compile time code is very limited and undocumented
<BlaXpirit> which really leaves you wondering
<RX14> well
<BlaXpirit> llvm is bound to have an interpreter
<RX14> I bet you could
<BlaXpirit> just allow arbitrary code at compile time, it's gonna be so good
Philpax has joined #crystal-lang
<ragmaanir> you can convert a block to string in a macro
<ragmaanir> just tried it
<BlaXpirit> ok but you can't do anything with it
<ragmaanir> hm, ok, that might be true
<RX14> BlaXpirit, you can do it
<RX14> it works
<RX14> i just tested it
<BlaXpirit> what works...
<RX14> using a macro for the table notation
<ragmaanir> i can e.g. split the string by newlines
<BlaXpirit> and get an ArrayLiteral
<BlaXpirit> yay..
<ragmaanir> and i can convert one entry in the array literal to code and pass that code to a different macro
<RX14> macro unpick(&block)
<RX14> {% for expr in block.body.expressions %}
<RX14> {% puts expr %}
<RX14> {% end %}
<RX14> end
<RX14> that gets you the rows
<ragmaanir> thats even better
<BlaXpirit> but you can't do actual programming, that's the problem
<ragmaanir> what do you mean with "actual programming"?
<RX14> BlaXpirit, that's not true
<BlaXpirit> you can't add two arrays
<ragmaanir> oh, and while we are discussing macros: do you know if there is a way to flatten nested tuples at compile time via macro?
<RX14> BlaXpirit, as a last resort, you can use an external program to handle the codegen
<BlaXpirit> ragmaanir, maybe recursively
<BlaXpirit> but probably not
<BlaXpirit> well if you can figure out how to merge 2 tuples, then probably yes
<RX14> BlaXpirit, if I didn't have too much work to do already I would make this happen
<ragmaanir> macro adda(a,b)
<ragmaanir> nested([{{*a}}, {{*b}}])
<ragmaanir> end
<ragmaanir> macro nested(arr)
<ragmaanir> puts typeof({{arr}})
<ragmaanir> puts {{arr}}
<ragmaanir> end
<ragmaanir> adda([1,2], ["a", :b])
<BlaXpirit> wow
<ragmaanir> is that what you want? or did i misunderstand you?
<RX14> macros aren't as limited as you think they are
<BlaXpirit> ragmaanir, that is impressive
<ragmaanir> glad i could contribute :D
<BlaXpirit> RX14, but more limited than you think
<RX14> yeah probably
<RX14> i'm sure it's turing complete
<RX14> and not the worst tarpit i've ever been in
<ragmaanir> since you can write recursive macros and there are if/else, it should be turing complete
<RX14> if power_assert can be written in macros
<RX14> then a table parser can
trapped has quit [Read error: Connection reset by peer]
Philpax has quit [Ping timeout: 252 seconds]
<BlaXpirit> what's really killing me is that I can't get an actual Array in a macro, and things like these
<BlaXpirit> and, of course any normal code
<BlaXpirit> that's written outside of macros
<BlaXpirit> if I write def f(x) why shouldn't I be able to call it from macros?
<BlaXpirit> just interpret that function
<RX14> just use macro f(x)
<RX14> and macroscrit
<BlaXpirit> but that defeats the point, I can't use classes there and any of the libraries
tomchapin has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
Gasher^ has joined #crystal-lang
<RX14> huh
<RX14> well umm
Gasher has quit [Ping timeout: 248 seconds]
<BlaXpirit> (please ping me if you have interesting findings)
<RX14> BlaXpirit, https://aww.moe/e0zy68.txt
<RX14> then feed that into an external codegen
<RX14> simple
<BlaXpirit> that's no fun
<BlaXpirit> well actually it is a lot of fun but not very reliable
<RX14> well umm
<RX14> we can reuse parts of the crystal compiler
<RX14> like the tokeniser
perks has quit [Ping timeout: 240 seconds]
pawnbox has joined #crystal-lang