On Tue, 08 Nov 2011 21:47:04 +0100
Thorsten <quintf...@googlemail.com> wrote:

> José Romero <jose.cyb...@gmail.com>
> writes:
> > 'text also uses @ http://software-lab.de/doc/refT.html#text
> > It's also useful to note that in short-circuit evaluation style
> > functions like 'and, @ always holds the result of the previously
> > evaluated argument, as you can see in this typical PicoLisp line:
> >
> >   (and and (@ (min @ 5) (prinl @) (gt0 (dec @)) .))
> >
> > ;)
> ok, I added these two cases to the table (see below).
> Could you give a little 'walk-through' for the example line, its not
> that obvious (to me) how this works (but it does) ;)
> min, prinl, gt0 and dec are obvious.
> the double 'and and' and the '.' at the and are a bit strange. Where
> does the initial @=5 come from - because @ is initially T and T is
> greater than everything else?
> cheers

Pretty silly and badly written explanation of what goes on there:

 I'm eval. I see a list, look inside, i see a symbol called 'and. i
 look at it's val. It's a number, thus a function pointer, i call it
 with the rest of the list unevaluated.

 I'm doAnd, i look at the list i was passed, i see a symbol called 'and,
 i evaluate it, a number came out, it's not NIL, so i shove it in @ and
 look at the next cadr. It's a list, i evaluate it, has a symbol called
 @ in it's car, that symbol resolves to a number, a pointer to doAnd, i 
 call it with the rest of the list unchanged.

 I'm doAnd, i look at the list i was passed, the first argument,
 evaluating it results in a function call that returns 5, it's not nil,
 so i shove it to @ and go on. The next element is another list, a call
 to prinl happens, it returned 5, it's not nil, so i shove it to @ and
 go on. Look at the next element, a call to (gt0 (dec @)), returns 4,
 that is not nil, so i shove the 4 in @ and go on. Looking at the next
 cadr i see @ again (but i don't realize, because i don't know wether a
 list is circular or not), it evaluates to 4, so i shove it to @ keep
 going. I see (min @ 5) again.........
 ... 3
 ... 2
 ... 1
 ... (gt0 (dec @)) returns NIL here, so i stop evaluating and return NIL

 Back in the first doAnd, i see the previous call returned NIL, so i
 stop evaluating right there and return NIL.

Then I realized that it could be written with only one 'and using
the right syntax (and losing part of it's rube-goldberg appeal):

  (and 5 . ((prinl @) (gt0 (dec @)) .))

Cheers :3
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to