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

2017-02-07 Thread Alexander Burger
On Tue, Feb 07, 2017 at 06:44:43AM -0800, Lindsay John Lawrence wrote:
>((= '() Lst) '() )
> ..
> However when I (pp 'selectN) it wrote the line where I am trying to test
>((= 'NIL Lst) 'NIL)

Yes, the reader returs the symbol NIL when it sees ()



> Is that  correct? Shouldn't the pp output at least look something like
> this? (no ' on NIL)
> ((= NIL Lst) NIL)

'pp' just pretty-prints what is there. It does not modify the data in any way.


> It  is a bit of nuance regarding '() ,  NIL and  'NIL I will have to keep
> in mind.

OK :)

It is just that any symbol which evaluates to itself does not *need* to be
quoted. It does no harm to quote it, except for the penalty in terms of memory
and speed.

This is e.g. NIL or T, but also strings (transient symbols).

Numbers, BTW, are also evaluating to themselves, so it is not necessary to write
e.g. (+ '3 '4) though it is not wrong.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


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

2017-02-07 Thread Lindsay John Lawrence
I just noticed... my original source for the selectN function is this...

(de selectN (Lst P)
..
   ((= '() Lst) '() )
..

However when I (pp 'selectN) it wrote the line where I am trying to test
for an empty list as

(de selectN (Lst P)
..
   ((= 'NIL Lst) 'NIL)
..

Is that  correct? Shouldn't the pp output at least look something like
this? (no ' on NIL)

..
((= NIL Lst) NIL)
..

It  is a bit of nuance regarding '() ,  NIL and  'NIL I will have to keep
in mind.

/Lindsay


On Mon, Feb 6, 2017 at 11:13 PM, Alexander Burger 
wrote:

> On Tue, Feb 07, 2017 at 07:41:45AM +0100, Alexander Burger wrote:
> > (cond
> >((= 'NIL Lst) 'NIL)
>
> One important note: (= 'NIL Lst) is not a good idea.
> Better to use (not Lst).
>
> (= NIL Lst) would compare *names* if 'Lst' happened to be
> a symbol, so (= NIL "NIL") returns T.
>
> Better is (== NIL Lst), which checks for identity.
>
> Anyway, good that we have have 'not' ;)
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


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

2017-02-07 Thread Lindsay John Lawrence
Thanks!
I still trip over those nuances if I don't pay attention testing for
NIL or '(), or not, in lists and symbols.
/Lindsay

On Mon, Feb 6, 2017 at 11:13 PM, Alexander Burger 
wrote:

> On Tue, Feb 07, 2017 at 07:41:45AM +0100, Alexander Burger wrote:
> > (cond
> >((= 'NIL Lst) 'NIL)
>
> One important note: (= 'NIL Lst) is not a good idea.
> Better to use (not Lst).
>
> (= NIL Lst) would compare *names* if 'Lst' happened to be
> a symbol, so (= NIL "NIL") returns T.
>
> Better is (== NIL Lst), which checks for identity.
>
> Anyway, good that we have have 'not' ;)
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


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

2017-02-07 Thread Lindsay John Lawrence
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 
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
>


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

2017-02-07 Thread Alexander Burger
Hi Jon,

> I wasn’t aware of nor, nand, nond. Maybe there should have been a few more
> “See also” in the docs.

True! I've added some ...

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


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

2017-02-07 Thread dean
Wow...really pleased I asked. Those are great examples and I'm sure I'll
learn a lot from them. I've needed to process lists/trees most of
programming "life" and the languages I've used haven't exactly regarded
them as first class citizens and this has slowed me down quite a lot. I
don't have that problem now and despite my lack of familiarity and needing
to look a lot of stuff upthe results are extremely rewarding. Thank you
all for your help and advice.

Best Regards
Dean

On 7 February 2017 at 08:50, Jon Kleiser  wrote:

> Hi,
>
> I wasn’t aware of nor, nand, nond. Maybe there should have been a few more
> “See also” in the docs.
>
> /Jon
>
> > On 7. Feb, 2017, at 08:31, Alexander Burger  wrote:
> >
> > On Tue, Feb 07, 2017 at 08:13:06AM +0100, Alexander Burger wrote:
> >> Better to use (not Lst).
> >
> > One more note: I even try to avoid 'not' whenever possible, as it is an
> > additional function call overhead.
> >
> > It is often possible to use the complementary flow function,
> > like (ifn Lst ..) instead of (if (not Lst) ..).
> >
> >   if<->   ifn
> >   and   <->   nor
> >   or<->   nand
> >   when  <->   unless
> >   cond  <->   nond
> >   while <->   until
> >
> > ♪♫ Alex
> > --
>
>


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

2017-02-07 Thread Jon Kleiser
Hi,

I wasn’t aware of nor, nand, nond. Maybe there should have been a few more “See 
also” in the docs.

/Jon

> On 7. Feb, 2017, at 08:31, Alexander Burger  wrote:
> 
> On Tue, Feb 07, 2017 at 08:13:06AM +0100, Alexander Burger wrote:
>> Better to use (not Lst).
> 
> One more note: I even try to avoid 'not' whenever possible, as it is an
> additional function call overhead.
> 
> It is often possible to use the complementary flow function,
> like (ifn Lst ..) instead of (if (not Lst) ..).
> 
>   if<->   ifn
>   and   <->   nor
>   or<->   nand
>   when  <->   unless
>   cond  <->   nond
>   while <->   until
> 
> ♪♫ Alex
> -- 

PԔ � )mX�����zV�u�.n7�

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

2017-02-06 Thread Alexander Burger
On Tue, Feb 07, 2017 at 08:13:06AM +0100, Alexander Burger wrote:
> Better to use (not Lst).

One more note: I even try to avoid 'not' whenever possible, as it is an
additional function call overhead.

It is often possible to use the complementary flow function,
like (ifn Lst ..) instead of (if (not Lst) ..).

   if<->   ifn
   and   <->   nor
   or<->   nand
   when  <->   unless
   cond  <->   nond
   while <->   until

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


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

2017-02-06 Thread Alexander Burger
On Tue, Feb 07, 2017 at 07:41:45AM +0100, Alexander Burger wrote:
> (cond
>((= 'NIL Lst) 'NIL)

One important note: (= 'NIL Lst) is not a good idea.
Better to use (not Lst).

(= NIL Lst) would compare *names* if 'Lst' happened to be
a symbol, so (= NIL "NIL") returns T.

Better is (== NIL Lst), which checks for identity.

Anyway, good that we have have 'not' ;)

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


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

2017-02-06 Thread Alexander Burger
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


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

2017-02-06 Thread Lindsay John Lawrence
I couldn't resist tinkering with this a bit more.

# --
(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.

: (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (=0 (%
(inc I) 2
-> (a b c d e f g h i j k)
: (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (gt0 (%
(inc I) 2
-> (0 1 2 3 4 5 6 7 8 9 10)
: (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (sym?
V)))
-> (a b c d e f g h i j k)
: (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (num?
V)))
-> (0 1 2 3 4 5 6 7 8 9 10)

/Lindsay



On Mon, Feb 6, 2017 at 5:04 PM, Lindsay John Lawrence <
lawrence.lindsayj...@gmail.com> wrote:

>
> Once I started to get the hang of the basic building blocks, I started
> seeing patterns and ways to build on what I had written before
> e.g. To me, the next logical development of dropN, pickN is to allow
> providing a predicate function... effectively making it a general purpose
> list filter
>
> # -
> (de selectNN (Lst P I)
>   # (println Lst I)
>   (cond
> ((= '() Lst) '() )
> ((P (car Lst) I) (cons (car Lst) (selectNN (cdr Lst) P (inc I
> (T (selectNN (cdr Lst) P (inc I))) ) )
>
> (de selectN (Lst P)
>   (selectNN Lst P 1) )
>
> # -
> Compare selectN to dropN and pickN.
> Now you can write code like this
> : (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (sym?
> V)))
> -> (a b c d e f g h i j k)
> : (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (num?
> V)))
> -> (0 1 2 3 4 5 6 7 8 9 10)
> : (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (=0 (%
> (inc I) 2
> -> (a b c d e f g h i j k)
> : (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (gt0 (%
> (inc I) 2
> -> (0 1 2 3 4 5 6 7 8 9 10)
>
>
> Lego my Lisp :)
>
> /Lindsay
>
>
>
>
> On Mon, Feb 6, 2017 at 4:18 PM, Lindsay John Lawrence <
> lawrence.lindsayj...@gmail.com> wrote:
>
>> 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  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))

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

2017-02-06 Thread Lindsay John Lawrence
Once I started to get the hang of the basic building blocks, I started
seeing patterns and ways to build on what I had written before
e.g. To me, the next logical development of dropN, pickN is to allow
providing a predicate function... effectively making it a general purpose
list filter

# -
(de selectNN (Lst P I)
  # (println Lst I)
  (cond
((= '() Lst) '() )
((P (car Lst) I) (cons (car Lst) (selectNN (cdr Lst) P (inc I
(T (selectNN (cdr Lst) P (inc I))) ) )

(de selectN (Lst P)
  (selectNN Lst P 1) )

# -
Compare selectN to dropN and pickN.
Now you can write code like this
: (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (sym?
V)))
-> (a b c d e f g h i j k)
: (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (num?
V)))
-> (0 1 2 3 4 5 6 7 8 9 10)
: (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (=0 (%
(inc I) 2
-> (a b c d e f g h i j k)
: (selectN '(a 0 b 1 c 2 d 3 e 4 f 5 g 6 h 7 i 8 j 9 k 10) '((V I) (gt0 (%
(inc I) 2
-> (0 1 2 3 4 5 6 7 8 9 10)


Lego my Lisp :)

/Lindsay




On Mon, Feb 6, 2017 at 4:18 PM, Lindsay John Lawrence <
lawrence.lindsayj...@gmail.com> wrote:

> 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  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  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...
 exec ${0%/*}/bin/picolisp ${0%/*}/lib.l @ext.l "$@"
 i.e. not the one in /bin which contains /usr which I think ISN'T
 local and I think I compiled a local version.

 Irrespectivethank you very much for your solution.

 Best Regards Dean


 On 6 February 2017 at 15:24, Alexander Burger 
 wrote:

> On Mon, Feb 06, 2017 at 12:25:14PM +0100, Alexander Burger wrote:
> > > I'd like to split a list '(txt1 2 txt2 6
> > > into 2 lists
> > > '(txt1 txt2...
> > > and
> > > 

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

2017-02-06 Thread Lindsay John Lawrence
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  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  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...

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

2017-02-06 Thread dean
I just came back to say I just looked and didn't realise I had to click P16
to see that function
Thanks once again.
Just goes to show...however idiot-proof you make your system
someone will just invent a better idiot :)

On 6 February 2017 at 22:51, dean  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  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...

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

2017-02-06 Thread dean
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  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
>> exec ${0%/*}/bin/picolisp ${0%/*}/lib.l @ext.l "$@"
>> i.e. not the one in /bin which contains /usr which I think ISN'T
>> local and I think I compiled a local version.
>>
>> Irrespectivethank you very much for your solution.
>>
>> Best Regards Dean
>>
>>
>> On 6 February 2017 at 15:24, Alexander Burger 
>> wrote:
>>
>>> On Mon, Feb 06, 2017 at 12:25:14PM +0100, Alexander Burger wrote:
>>> > > I'd like to split a list '(txt1 2 txt2 6
>>> > > into 2 lists
>>> > > '(txt1 txt2...
>>> > > and
>>> > > '(2 6
>>> >
>>> > You could for example filter them:
>>> >
>>> >(let
>>> >   (Lst '(txt1 2 txt2 6)
>>> >  A (filter sym? Lst)
>>> >  B (filter num? Lst) )
>>> >   ... use A and B ...)
>>>
>>> It is not clear what you need.
>>>
>>>
>>> If, for example, you want every *second* element, there is a nice trick:
>>>
>>>: (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)
>>>
>>> Similarly, you can extract other sequences if you pass the right pattern
>>> of
>>> NIL's and T's.
>>>
>>> ♪♫ Alex
>>> --
>>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>>
>>
>>
>


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

2017-02-06 Thread Lindsay John Lawrence
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  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
> exec ${0%/*}/bin/picolisp ${0%/*}/lib.l @ext.l "$@"
> i.e. not the one in /bin which contains /usr which I think ISN'T local
> and I think I compiled a local version.
>
> Irrespectivethank you very much for your solution.
>
> Best Regards Dean
>
>
> On 6 February 2017 at 15:24, Alexander Burger  wrote:
>
>> On Mon, Feb 06, 2017 at 12:25:14PM +0100, Alexander Burger wrote:
>> > > I'd like to split a list '(txt1 2 txt2 6
>> > > into 2 lists
>> > > '(txt1 txt2...
>> > > and
>> > > '(2 6
>> >
>> > You could for example filter them:
>> >
>> >(let
>> >   (Lst '(txt1 2 txt2 6)
>> >  A (filter sym? Lst)
>> >  B (filter num? Lst) )
>> >   ... use A and B ...)
>>
>> It is not clear what you need.
>>
>>
>> If, for example, you want every *second* element, there is a nice trick:
>>
>>: (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)
>>
>> Similarly, you can extract other sequences if you pass the right pattern
>> of
>> NIL's and T's.
>>
>> ♪♫ Alex
>> --
>> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>>
>
>


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

2017-02-06 Thread dean
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
exec ${0%/*}/bin/picolisp ${0%/*}/lib.l @ext.l "$@"
i.e. not the one in /bin which contains /usr which I think ISN'T local
and I think I compiled a local version.

Irrespectivethank you very much for your solution.

Best Regards Dean


On 6 February 2017 at 15:24, Alexander Burger  wrote:

> On Mon, Feb 06, 2017 at 12:25:14PM +0100, Alexander Burger wrote:
> > > I'd like to split a list '(txt1 2 txt2 6
> > > into 2 lists
> > > '(txt1 txt2...
> > > and
> > > '(2 6
> >
> > You could for example filter them:
> >
> >(let
> >   (Lst '(txt1 2 txt2 6)
> >  A (filter sym? Lst)
> >  B (filter num? Lst) )
> >   ... use A and B ...)
>
> It is not clear what you need.
>
>
> If, for example, you want every *second* element, there is a nice trick:
>
>: (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)
>
> Similarly, you can extract other sequences if you pass the right pattern of
> NIL's and T's.
>
> ♪♫ Alex
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>


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

2017-02-06 Thread Alexander Burger
On Mon, Feb 06, 2017 at 12:25:14PM +0100, Alexander Burger wrote:
> > I'd like to split a list '(txt1 2 txt2 6
> > into 2 lists
> > '(txt1 txt2...
> > and
> > '(2 6
> 
> You could for example filter them:
> 
>(let
>   (Lst '(txt1 2 txt2 6)
>  A (filter sym? Lst)
>  B (filter num? Lst) )
>   ... use A and B ...)

It is not clear what you need.


If, for example, you want every *second* element, there is a nice trick:

   : (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)

Similarly, you can extract other sequences if you pass the right pattern of
NIL's and T's.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


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

2017-02-06 Thread Alexander Burger
Hi Dean,

> I'd like to split a list '(txt1 2 txt2 6
> into 2 lists
> '(txt1 txt2...
> and
> '(2 6

You could for example filter them:

   (let
  (Lst '(txt1 2 txt2 6)
 A (filter sym? Lst)
 B (filter num? Lst) )
  ... use A and B ...)



> I found drop (in ninety nine...) which looks ideal but it's apparently
> undefined in pil64.

What 'drop' do you mean? pil64 has all functions of pil32 btw.

♪♫ Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe


replacement for (let L2 (drop L1 2)....

2017-02-06 Thread dean
Hi
I'd like to split a list '(txt1 2 txt2 6
into 2 lists
'(txt1 txt2...
and
'(2 6

I found drop (in ninety nine...) which looks ideal but it's apparently
undefined in pil64.
I've looked for something similar but it's not jumping out :)
Any help much appreciated.