libera/#commonlisp - IRC Chatlog
Search
12:03:53
younder
(defun string-join (&rest strings &key (sep " ")) ...) as this (string-join "the" "fat" "cat" "shat" "on" "the" "mat") gives the error "odd number of &KEY arguments". Why?
12:05:54
beach
Because every parameter is a &KEY parameter (and there is only one of them) so there must be an even number of arguments.
12:10:47
beach
Your definition means a function that takes only keyword arguments (so there must be an even number of arguments), and whatever arguments you pass are going to end up in the STRINGS &REST parameter.
12:10:49
specbot
Specifiers for keyword parameters: http://www.lispworks.com/reference/HyperSpec/Body/03_dad.htm
12:11:09
_death
"In this case the remaining arguments are used for both purposes; that is, all remaining arguments are made into a list for the rest parameter, and are also processed for the &key parameters."
12:12:41
_death
in your case, either remove &rest specifier and just pass a list of strings and possible key arguments (the sane option), or leave &rest and remove &key and do your own keyword-like processing in the function (the stareyed teenage lisper option)
12:14:44
beach
_death: How would removing the &REST parameter make it possible to pass a list of strings?
12:25:07
_death
beach: (just a small note, lambda-list keywords are specifiers.. I could've been more specific)
12:30:36
_death
ok, I'm wrong again :).. "Each element of a lambda list is either a parameter specifier or a lambda list keyword.", so the specifier would be the symbol STRINGS.. now I need to internalize this terminological update ;)
13:43:34
younder
I think I finally got the rationale after reading https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node64.html
13:45:41
jcowan
I'm done here, at least for the present. I'll still be available on #scheme (or so I expect) and #lisp (or so I expect).
15:11:28
edgar-rft
younder: Practical Common Lisp has a whole chapter about &optional, &rest, and &key parameters and what happens if you mix them with examples -> https://gigamonkeys.com/book/functions
17:41:22
shka
where i am making a mistake? https://gist.github.com/sirherrbatka/1987d66741d19656e8ed67670d7602f9
17:46:37
mrvdb
hi commonlisp! The line https://github.com/antifuchs/idna/blob/develop/decode.lisp#L16 causes a compile failure (I am on a ppc64 machine, using GUIX, sbcl 2.4.0) Is this implementation dependent? I'm assuming, given the age of that code, it has compiled successfully.
18:03:19
mrvdb
yeah, i understand the cause of the error, i'm just surprised it wont compile given the age of the code and usage in other packages.
18:06:57
shka
this could be just (map 'string (lambda (case-flag output) (if case-flag (char-code (char-upcase (code-char output)))))) output) case-flags output)