Hi Alex,
Thanks for the detailed reply. Pl. see my reply inline..
Srini
----- Original Message -----
> From: Alexander Burger <[email protected]>
> To: [email protected]
> Sent: Monday, July 28, 2014 2:21:53 PM
> > I am trying to understand this example from the reference:
> > (prog1 # Parallel background calculation of square numbers
> > (mapcan '((N) (later (cons) (* N N))) (1 2 3 4))
> > (wait NIL (full @)) )
> Could you please explain how it works, because it has many
> interrelated pieces: cons,mapcan, wait that I thought I understood
> individually but still I do not understand the example.
...
> 'later' accepts a 'var' (i.e. a symbol or a list cell), and returns that
> var. As a side effect, it takes a program (a 'prg' which is a list of
> expressions), runs that in a child process, and stores the result of
> that 'prog' in the 'var' at some later point when the child process is
> done.
Somehow, this made it clear for me, although when I read the reference now, it
essentially said the same thing more concisely.
> This is done with the 'mapcan' and 'cons' above. Remember that (cons) is
> just a shortcut of (cons NIL NIL), and that 'mapcan' concatenates the
> returned results. Thus, the above call without 'later' gives:
> : (mapcan '((N) (cons NIL NIL)) (1 2 3 4))
> -> (NIL NIL NIL NIL)
This was useful as I did not realize (though it is so clear now) that
(cons) = (cons NIL) = (cons NIL NIL)
i.e produces a single cell with NIL in CAR and in CDR.
> However, if we have
> (mapcan '((N) (later (cons) (* N N))) (1 2 3 4))
> Then as a side effect each call to 'later' receives its private, newly
> 'cons'ed list cell - i.e. a 'var' - which it duefully retunrs to
> 'mapcan' to be concatenated to the full list.
Yes, understand now...
> > Another confusing thing is the "@" How does one find which of the
> > previous functions updated the @, and which did not. I know that control
> This is documented in "http://software-lab.de/doc/ref.html". Exclusively
> the (flow) functions listed there will modify '@'.
> There's also a nice article by Thorsten: The many uses of @ in PicoLisp
> http://picolisp.com/wiki/?atmark
I read both of these references before, but am struggling to apply. From the
first one:
Functions with controlling expressions are case, casq, prog1, prog2,
and the bodies of *Run tasks.
Functions with conditional expressions are and, cond, do, for, if, if2,
ifn, loop, nand, nond, nor, not, or, state, unless, until, when and while.
So probably @ is updated by the function "later" ("body of run tasks"). Another
possibility is
that prog1 that updates the @ with NIL NIL NIL NIL (the result of the first
"expression"), but this is not likely, I think, as the @ would only be updated
by it after the wait completes as well.
> ♪♫ Alex
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe
--
UNSUBSCRIBE: mailto:[email protected]?subject=Unsubscribe