# Re: replacement for (let L2 (drop L1 2)....

```All of those problems are fun to explore... try writing different versions
of the selected solutions, iterative vs recursive, using just basic list
building block functions vs the wonderfully convenient functions that
picolisp provides, etc```
```
This particular one piqued my interest enough to try writing another
version of 'drop' that is recursive and just uses *car, cdr, cons*...

# -----------------------------------------------------------------
(de dropNN (Lst N I)
# (println Lst N I (% I N))
(cond
((= '() Lst) '() )
((gt0 (% I N)) (cons (car Lst) (dropNN (cdr Lst) N (inc I))))
(T (dropNN (cdr Lst) N (inc I))) ) )

(de *dropN *(Lst N)
(dropNN Lst N 1) )

: (dropN '(a b c d e f g h i j k) 2)
-> (a c e g i k)

# -----------------------------------------------------------------

Having written that, it is relatively easy to tinker out something similar
that 'picks' every Nth element...

# -----------------------------------------------------------------
(de pickNN (Lst N I)
# (println Lst N I (% I N))
(cond
((= '() Lst) '() )
((=0 (% I N)) (cons (car Lst) (pickNN (cdr Lst) N (inc I))) )
(T (pickNN (cdr Lst) N (inc I))) ) )

(de *pickN *(Lst N)
(getNN Lst N 1) )

: (pickN '(a b c d e f g h i j k) 2)
-> (b d f h j)

# -----------------------------------------------------------------

Lisp is, at least for me, one of the most fun languages to explore in this
way.

It may seem slow, but I believe the time I have spent playing with basic
lisp building blocks, and simple list manipulation problems like this one,
is time well spent. The insight gained carries over into so many other
problems and their solutions.

/Lindsay

On Mon, Feb 6, 2017 at 2:51 PM, dean <deangwillia...@gmail.com> wrote:

> Oh gosh...I missed that completely...Thanks Lindsay..That explains
> everything!
> I'm really pleased you told me that because drop looks like a really
> useful function.
> Best Regards
> Dean
>
> On 6 February 2017 at 22:27, Lindsay John Lawrence <
> lawrence.lindsayj...@gmail.com> wrote:
>
>> P16 (**) Drop every N’th element from a list.
>>
>> (de drop (Lst N)
>>   (make
>>     (for (I . X) Lst
>>       (unless (=0 (% I N))
>>       (link X) ) ) ) )
>>
>> : (drop ’(a b c d e f g h i k) 3)
>> -> (a b d e g h k)
>>
>> 'drop' is the function given as a solution to the problem.
>>
>> /Lindsay
>>
>>
>> On Mon, Feb 6, 2017 at 1:24 PM, dean <deangwillia...@gmail.com> wrote:
>>
>>> Hi Alex
>>>    : (filter prog2 (1 a 2 b 3 c) '(T NIL .))
>>>    -> (1 2 3)
>>>    : (filter prog2 (1 a 2 b 3 c) '(NIL T .))
>>>    -> (a b c)
>>>
>>> Yes the above is exactly what I'm after.
>>>
>>> I copied this drop example straight from ninety nine.
>>> ? P16 (**) Drop every N'th element from a list.
>>> : (drop '(a b c d e f g h i k) 3)
>>> !? (drop '(a b c d e f g h i k) 3)
>>> drop -- Undefined
>>>
>>> I'm not sure why I'm getting "undefined".
>>> I'm using the pil in my picolisp directory.... which looks like this...```