I see, 'later' itself sets up *Run. Thanks Alex On Wed, Mar 15, 2017 at 1:21 AM, Alexander Burger <a...@software-lab.de> wrote:
> Hi Bruno, > > > Joh-Tob's question got me curious about parallel code in picolisp. I've > > studied the example of 'later' in the documentation and I have an idea of > > how it works, but I don't understand how 'wait' works inside of it. > > I understand *what* it does, it makes sure that the child processes > finish > > before returning the value for the whole expression. > > Right. > > > But I don't understand > > *how* it works because, in the form of 'wait' that is used, *Run should > be > > executed each time the prg returns false. Yet *Run is not set to any > value > > in the code. > > In fact, *Run' is set, because 'later' installs a 'task' listening at the > pipe > to the child process: > > ... > (task (pipe (pr (prog . "@Prg"))) > ... > > > > Here's the code for reference: > > : (prog1 > > (mapcan '((N) (later (cons) (* N N))) (1 2 3 4)) > > (wait NIL (full @)) ) > > -> (1 4 9 16) > > > > I would also appreciate if someone could check if my idea of what is > going > > on in the code is correct: > > > > First, mapcan is executed. For each element in (1 2 3 4) a child process > is > > started, and the result of each operation is stored in a cons pair: > '(NIL). > > Every cons pair is concatenated into a list, which looks like '(NIL NIL > NIL > > NIL) in this case. Note that the list is built *before* any of the child > > processes is completed, and since concatenation is destructive the result > > will be stored in the appropriate position in this list whenever the > child > > process is finished. (wait NIL (full @)) checks that all these processes > > are done before ending the prog1. > > Yes, this is absolutely correct. > > ♪♫ Alex > -- > UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe >