From: An[z]elmus
Subject: [Newbie] passing keyword argument
Date: 
Message-ID: <4916t3tuntghmn9mger6v6fa13n8m6l8uq@4ax.com>
I am currently using LispWorks Personal Edition with  LW-ADD-ONS on
Windows 2000.
LispWorks does not accept the following function call:

CL-USER 1 > (search '(0 1) '(1 2 3 4) :key nil)

It is true that there is no need to call the function in that way, but
I realized that it doesn't work while I was writing the function
below:

;;serch all occurcences of sequence1 in sequence2
;;returns a list of positions
;;it doesn't work with LW if you don't supply a :key argument 
;;but it seems to work normally with Allegro, Sbcl, CLisp

(defun search-all04 (seq01 seq02 &key key (start2 0))
  (let ((from start2))
    (do ((pos from (setf from  (+ pos (length seq01))))
         (positions '() (setf positions (cons pos positions))))
        ((null (setf pos (search seq01 seq02 :start2 from :key key)))
         (reverse positions)))))

I have written e a workaround using a supplied-p variable. 

From: Carl Taylor
Subject: Re: [Newbie] passing keyword argument
Date: 
Message-ID: <ndGAj.728176$kj1.591598@bgtnsc04-news.ops.worldnet.att.net>
An[z]elmus wrote:
> I am currently using LispWorks Personal Edition with  LW-ADD-ONS on
> Windows 2000.
> LispWorks does not accept the following function call:
>
> CL-USER 1 > (search '(0 1) '(1 2 3 4) :key nil)
>
> It is true that there is no need to call the function in that way, but
> I realized that it doesn't work while I was writing the function
> below:
>
> ;;serch all occurcences of sequence1 in sequence2
> ;;returns a list of positions
> ;;it doesn't work with LW if you don't supply a :key argument
> ;;but it seems to work normally with Allegro, Sbcl, CLisp


Are you perhaps confusing the :key and :test keyword arguments. The :test 
argument with the appropriate equal function will accomplish what you're trying 
to do.  When attempting to find equality of sequences EQUAL or EQUALP will be 
needed.

Here's a LOOP version of an index constructor.

(defun make-index-list (obj seq &key (test #'eql))
   (loop for p = (position obj seq :test test :start (if p (1+ p) 0))
           while p
           collect p))

(compile *)

CL-USER 18 >
(make-index-list
     '(0 1)
     '(a (6 2 z) (0 1) (1 2 3 4) (q w e r t y) (0 1) (foo) bar)
     :test #'equal)

(2 5)

Carl Taylor
From: An[z]elmus
Subject: Re: [Newbie] passing keyword argument
Date: 
Message-ID: <og67t31s1uncgevesh0a23oh0tav1v17tg@4ax.com>
On Sun, 09 Mar 2008 00:31:15 GMT, "Carl Taylor" <··········@att.net>
wrote:
>>[...]
>Are you perhaps confusing the :key and :test keyword arguments. The :test 
>argument with the appropriate equal function will accomplish what you're trying 
>to do.  When attempting to find equality of sequences EQUAL or EQUALP will be 
>needed.

You example of an index constructor is clear and your doubt is more
than legitimate because I was not clear enough. But that was not
exactly what I had in mind.
The starting point was an example I found in the CLHS for the Function
SEARCH. Here it is:

(search '(0 1) '(2 4 6 1 3 5) :key #'oddp) =>  2

It took me some times to understand the "meaning" of the expression an
how it works. Basically I think it means: find the first occorrunce in
sequence 2 where the first element is pair and the second is odd.
Then I thougth that something like that could have been usefull in my
"library" of strings/sequences manipulation functions.

For example:
CL-USER 8 > (defparameter *consonants* "bcdfglmnpqrstvz")
*CONSONANTS*

CL-USER 9 > (defun consonantp (s)
              (not (null (find s *consonants*))))
CONSONANTP

CL-USER 10 > (search-all04 "bb" "andante" :key #'consonantp)
(1 4)

That is it returns a list of all (starting) indexes in sequence 2 of
cluster of two consonants.




 
From: Carl Taylor
Subject: Re: [Newbie] passing keyword argument
Date: 
Message-ID: <m8UAj.293000$MJ6.17838@bgtnsc05-news.ops.worldnet.att.net>
"An[z]elmus" <·······@somewhere.org> wrote in message 
·······································@4ax.com...
> On Sun, 09 Mar 2008 00:31:15 GMT, "Carl Taylor" <··········@att.net>
> wrote:
>>>[...]
>>Are you perhaps confusing the :key and :test keyword arguments. The :test
>>argument with the appropriate equal function will accomplish what you're 
>>trying
>>to do.  When attempting to find equality of sequences EQUAL or EQUALP will be
>>needed.
>
> You example of an index constructor is clear and your doubt is more
> than legitimate because I was not clear enough. But that was not
> exactly what I had in mind.
> The starting point was an example I found in the CLHS for the Function
> SEARCH. Here it is:
>
> (search '(0 1) '(2 4 6 1 3 5) :key #'oddp) =>  2


OK. Back to your original post then. You wrote:

"LispWorks does not accept the following function call:

CL-USER 1 > (search '(0 1) '(1 2 3 4) :key nil)

It is true that there is no need to call the function in that way, but
I realized that it doesn't work while I was writing the function
below:"

Rather than :key nil you can write :key #'identity.  IDENTITY is a function that 
simply echos its argument doing nothing else. NIL of course is not a function, 
and the :key argument typically requires a designator for a function.

clt
From: Carl Taylor
Subject: Re: [Newbie] passing keyword argument
Date: 
Message-ID: <ZdUAj.293013$MJ6.63555@bgtnsc05-news.ops.worldnet.att.net>
"Carl Taylor" <··········@att.net> wrote in message 
···························@bgtnsc05-news.ops.worldnet.att.net...
>

[...]

> Rather than :key nil you can write :key #'identity.  IDENTITY is a function 
> that simply echos its argument doing nothing else. NIL of course is not a 
> function, and the :key argument typically requires a designator for a 
> function.

Or maybe you want the NULL function.

CL-USER 16 > (search '(0 1) '(1 2 3 4) :key #'null)
0

CL-USER 17 > (search '(0 1) '(1 2 3 4) :key #'identity)
NIL

clt 
From: Edi Weitz
Subject: Re: [Newbie] passing keyword argument
Date: 
Message-ID: <u4pbfam38.fsf@agharta.de>
On Sun, 09 Mar 2008 16:21:38 GMT, "Carl Taylor" <··········@att.net> wrote:

> NIL of course is not a function, and the :key argument typically
> requires a designator for a function.

The standard specifically allows NIL here (see CLHS dictionary entry
for SEARCH), so this is a bug in LispWorks which will likely be fixed
in an upcoming release.  If someone reports it, that is.  Just talking
about it on c.l.l might not be the best step towards this goal.

Edi.

-- 

European Common Lisp Meeting, Amsterdam, April 19/20, 2008

  http://weitz.de/eclm2008/

Real email: (replace (subseq ·········@agharta.de" 5) "edi")
From: An[z]elmus
Subject: Re: [Newbie] passing keyword argument
Date: 
Message-ID: <dg78t3paikie61d336s6aae00jsviacq1p@4ax.com>
On Sun, 09 Mar 2008 17:39:07 +0100, Edi Weitz <········@agharta.de>
wrote:
>The standard specifically allows NIL here (see CLHS dictionary entry
>for SEARCH), so this is a bug in LispWorks which will likely be fixed
>in an upcoming release.  If someone reports it, that is.

I reported it to LispWorks feedback. 
From: An[z]elmus
Subject: Re: [Newbie] passing keyword argument
Date: 
Message-ID: <qs48t3ttlfl4b330citbjmppge7cdjnenm@4ax.com>
On Sun, 09 Mar 2008 16:21:38 GMT, "Carl Taylor" <··········@att.net>
wrote:
>"LispWorks does not accept the following function call:
>
>CL-USER 1 > (search '(0 1) '(1 2 3 4) :key nil)
>
>It is true that there is no need to call the function in that way, but
>I realized that it doesn't work while I was writing the function
>below:"
>
>Rather than :key nil you can write :key #'identity.  IDENTITY is a function that 
>simply echos its argument doing nothing else. NIL of course is not a function, 
>and the :key argument typically requires a designator for a function.

Understood and function definition updated, thank you.