<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!
<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
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]
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());
<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>
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
<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
<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 ecb1766 Ary Borenszweig: Use Deque for concurrency (scheduler, channels, readers, writers), and use `shift` instead of `pop`....
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
<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
<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>
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
<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]
<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.