core-async

Ben Sless 2020-05-12T09:09:39.195500Z

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?

Ben Sless 2020-05-12T09:18:47.195700Z

nvm, figured it out:

2020-05-12T09:40:09.196500Z

is there a good example anywhere of how onto-chan! or onto-chan!! should be used with blocking things like reading from a file?

alexmiller 2020-05-12T12:34:44.198200Z

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

2020-05-12T13:03:21.199700Z

@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

2020-05-12T13:03:48.200400Z

so after the initial bit of reading, there isn't anything blocking until the end of all processing

alexmiller 2020-05-12T13:04:09.200800Z

well everytime you read from the file, that's potentially blocking

alexmiller 2020-05-12T13:06:14.201600Z

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)

alexmiller 2020-05-12T13:06:37.201900Z

but that's exactly what you're already doing

alexmiller 2020-05-12T13:07:16.202600Z

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

2020-05-12T13:08:33.203500Z

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)

alexmiller 2020-05-12T13:08:52.203700Z

yep

2020-05-12T13:09:52.204700Z

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?

alexmiller 2020-05-12T13:10:08.204900Z

sure

2020-05-12T13:10:12.205100Z

cool

2020-05-12T13:10:21.205700Z

that gives me a good pattern to follow then

2020-05-12T13:10:22.205900Z

šŸ™‚ thx

2020-05-12T19:32:15.208400Z

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!!