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:[email protected]?subject=Unsubscribe