Thanks Alex!

recur/recurse... I hadn't noticed those functions in the picolisp function
library until now. Very useful.

/Lindsay


On Mon, Feb 6, 2017 at 10:41 PM, Alexander Burger <a...@software-lab.de>
wrote:

> Hi Lindsay,
>
> > I couldn't resist tinkering with this a bit more.
>
> Many thanks for this and all the previous examples!
>
> > # ------------------------------------------------------
> > (de selectN (Lst P)
> >    (let selectNN
> >       '((Lst P I)
> >          (cond
> >             ((= 'NIL Lst) 'NIL)
> >             ((P (car Lst) I)
> >                (cons
> >                   (car Lst)
> >                   (selectNN (cdr Lst) P (inc I)) ) )
> >             (T (selectNN (cdr Lst) P (inc I))) ) )
> >       (selectNN Lst P 1) ) )
> > # ------------------------------------------------------
> >
> > Same code, I just realized Picolisp (= code data) allows me to move the
> > recursing function inside the initializing one.
> > The results are the same, but now the recursing function is effectively
> > private.
>
>
> As a further simplification, you could use recur/recurse:
>
>    (de selectN (Lst P)
>       (let I 1
>          (recur (Lst P I)
>             (cond
>                ((= 'NIL Lst) 'NIL)
>                ((P (car Lst) I)
>                   (cons
>                      (car Lst)
>                      (recurse (cdr Lst) P (inc I)) ) )
>                (T (recurse (cdr Lst) P (inc I))) ) ) ) )
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>

Reply via email to