I'm trying to translate the examples from https://www.cs.cmu.edu/~crary/819-f09/Hoare78.pdf to core.async. its been smooth sailing until I tried translating factorial (4.2)
;; [fac( i: 1..limit)::
;; * [n:integer;fac(i - 1)?n ->
;; [n = 0 -> fac(i - 1)!1
;; || n > 0 -> fac(i + 1)!n- 1;
;; r:integer;fac(i + 1)?r;fac(i - i)!(n * r)
;; ]
;; ]
;; || fac(0)::USER
;; ]
Anyone has an idea about how to translate & use it?nvm, figured it out:
is there a good example anywhere of how onto-chan! or onto-chan!! should be used with blocking things like reading from a file?
Iām not sure either is actually the best option if reading from a file, but you could use onto-chan!! if you had a lazy-seq that was reading line by line
@alexmiller what I've been doing atm is reading from a file line by line and then just putting the lines on the channel and doing that in a thread. Most of my core.async stuff is reading files, scrubbing them, and then sending them through different pipelines to produce lots of different results
so after the initial bit of reading, there isn't anything blocking until the end of all processing
well everytime you read from the file, that's potentially blocking
so if you were doing that in a lazy seq, you could use onto-chan!! (which will use a thread to read from the lazy seq and push into the channel)
but that's exactly what you're already doing
the important thing is that you should not use onto-chan or onto-chan! for this b/c they use a go loop and you're doing potentially blocking io
ok, that fits with my understanding. When doing blocking things, do the blocking thing with a thread, or using a separate blocking happy threadpool (like pipeline-blocking)
yep
is it a reasonable thing to pass a seq or vec of filenames to pipeline blocking to take advantage of parallel processing offered by pipeline-blocking?
sure
cool
that gives me a good pattern to follow then
š thx
Posted an issue last week about some worker threads that I had doing a recur inside of an alt!!
, they were having an issue after a few days.
Turns out I'm just a dummy and I had an if statement where the worker was only recurring in the else branch. My workers were dying because I just messed up the code, fortunately had nothing to do with core async or alt!!