From: Charlie
Subject: keyword problems
Date: 
Message-ID: <as2iov$nmond$1@ID-155962.news.dfncis.de>
I wrote this function to get bytes out of an integer and possibly pad the
list but it's giving me a little trouble. The problem is that try as I might
I can't get it to pick up the min-list-length keyword and the byte-list arg
is not optional when I try to pass a min-list-length.

(defun list-bytes (number &optional byte-list
                                      &key (min-list-length 0))
      "Takes a number and gives a list of the 8-bit bytes it is comprised of
in largest first order. :min-list-length can be used to pad the beginning of
the list with zeros"
      (if (zerop number)
          (if (< (length byte-list) (print min-list-length))
              (do ((ret-list byte-list (cons 0 ret-list)))
                    ((>= (length ret-list) min-list-length)
                    ret-list))
         (print byte-list))
    (list-bytes (ash number -8)
      (cons (logand #XFF number) byte-list))))

CLISP says:

> (list-bytes #XFFAA11 '() :min-list-length 10)
0  <-- min-list-length arg
(255 170 17)
(255 170 17)

> (list-bytes #XFFAA11 :min-list-length 10)
*** - EVAL/APPLY: keyword arguments for LIST-BYTES should occur pairwise

I have tried naming both arguments but that gives the same error as above. I
have also tried not giving min-l-l an initial value in the defun; same
problem.
Please help this dumb newbie out!

Cheers
Charlie.

From: Paul F. Dietz
Subject: Re: keyword problems
Date: 
Message-ID: <XaKcnfhIQouyTHmgXTWc2Q@dls.net>
Charlie wrote:
> I wrote this function to get bytes out of an integer and possibly pad the
> list but it's giving me a little trouble. The problem is that try as I might
> I can't get it to pick up the min-list-length keyword and the byte-list arg
> is not optional when I try to pass a min-list-length.
> 
> (defun list-bytes (number &optional byte-list
>                                       &key (min-list-length 0))
>       "Takes a number and gives a list of the 8-bit bytes it is comprised of
> in largest first order. :min-list-length can be used to pad the beginning of
> the list with zeros"
>       (if (zerop number)
>           (if (< (length byte-list) (print min-list-length))
>               (do ((ret-list byte-list (cons 0 ret-list)))
>                     ((>= (length ret-list) min-list-length)
>                     ret-list))
>          (print byte-list))
>     (list-bytes (ash number -8)
>       (cons (logand #XFF number) byte-list))))


Do (trace list-bytes) and try it again, observing the results.
You'll see the problem (it's in your code.)

	Paul
From: Charlie
Subject: Re: keyword problems
Date: 
Message-ID: <as2k0v$nf6j6$1@ID-155962.news.dfncis.de>
Oops, so I'm dumb for example 1 but what about the fact that I can't use
:min-list-length without supplying the &optional byte-list. Is it possible
to do this or do I always need to supply 2x args?

(defun list-bytes (number &optional byte-list
                                      &key (min-list-length 0))

> (list-bytes #XFFAA11 :min-list-length 10)
*** - EVAL/APPLY: keyword arguments for LIST-BYTES should occur pairwise

Thank-you
<kicks self>
Charlie.
From: Pascal Costanza
Subject: Re: keyword problems
Date: 
Message-ID: <3DE4D4C2.9030203@web.de>
Charlie wrote:
> Oops, so I'm dumb for example 1 but what about the fact that I can't use
> :min-list-length without supplying the &optional byte-list. Is it possible
> to do this or do I always need to supply 2x args?
> 
> (defun list-bytes (number &optional byte-list
>                                       &key (min-list-length 0))

Yes, as Erik already pointed out, you always have to do this. If you 
want to have calls that pass min-list-length but not byte-list you have 
to change byte-list into a keyword with default value as well.

(defun list-bytes (number &key (byte-list '()) (min-list-length 0)))


Pascal

-- 
Pascal Costanza               University of Bonn
···············@web.de        Institute of Computer Science III
http://www.pascalcostanza.de  R�merstr. 164, D-53117 Bonn (Germany)
From: Charlie
Subject: Re: keyword problems
Date: 
Message-ID: <as2khl$njnlq$1@ID-155962.news.dfncis.de>
Thanks, I managed to send the question (again) and get the answer at the
same time!
Cheers
Charlie.
From: Erik Naggum
Subject: Re: keyword problems
Date: 
Message-ID: <3247395050163759@naggum.no>
* "Charlie" <········@zoom.co.uk>
| Please help this dumb newbie out!

  You have to specify all optional positional arguments before the keyword
  arguments can be processed.  Otherwise, the keyword itself (which is an
  actual argument) will /be/ the optional argument.

-- 
Erik Naggum, Oslo, Norway

Act from reason, and failure makes you rethink and study harder.
Act from faith, and failure makes you blame someone and push harder.
From: Charlie
Subject: Re: keyword problems
Date: 
Message-ID: <as2k8h$nlcsc$1@ID-155962.news.dfncis.de>
I now have:
(defun list-bytes (number &key
                                     (min-list-length 0)
                                     byte-list) ...)
Which works rather nicely.
Thank-you.


"Erik Naggum" <····@naggum.no> wrote in message
·····················@naggum.no...
> * "Charlie" <········@zoom.co.uk>
> | Please help this dumb newbie out!
>
>   You have to specify all optional positional arguments before the keyword
>   arguments can be processed.  Otherwise, the keyword itself (which is an
>   actual argument) will /be/ the optional argument.
>
> --
> Erik Naggum, Oslo, Norway
>
> Act from reason, and failure makes you rethink and study harder.
> Act from faith, and failure makes you blame someone and push harder.