freenode/#lisp - IRC Chatlog
Search
22:58:56
jcowan
Another question. If a lambda list specifies both &optional and &key, is it necessary to fill all optional arguments in the call before any keywords are detected, or is the presence of a keyword enough to trigger keyword processing?
23:01:16
no-defun-allowed
You can test with read-from-string, which takes two optional arguments then keyword arguments.
23:06:11
clothespin
i'm not talking about the heavy handed stuff like immutable datastructures and atoms and such
23:06:53
aeth
jcowan: (let ((l1 (list 1 2 3 :c 42)) (l2 (list 1 :c 42))) (flet ((test-optional-with-key (list) (destructuring-bind (foo &optional bar baz &key a b c) list (values foo bar baz a b c)))) (format t "~{~S ~}~%~{~S ~}~%" (multiple-value-list (test-optional-with-key l1)) (multiple-value-list (test-optional-with-key l2)))))
23:07:04
aeth
SBCL even gives a style warning there, although it exists in a few older functions in the standard
23:08:09
aeth
For those who don't want to run it, the first line is "1 2 3 NIL NIL 42 " and the second is "1 :C 42 NIL NIL NIL ", so when the optionals aren't filled in the keyword is treated as an argument. And yes, this has caused a bug in my code before.
23:10:07
aeth
And without destructuring bind: (let ((l1 (list 1 2 3 :c 42)) (l2 (list 1 :c 42))) (flet ((test-optional-with-key (foo &optional bar baz &key a b c) (values foo bar baz a b c))) (format t "~{~S ~}~%~{~S ~}~%" (multiple-value-list (multiple-value-call #'test-optional-with-key (values-list l1))) (multiple-value-list (multiple-value-call #'test-optional-with-key (values-list l2))))))
23:31:35
aeth
SBCL does have the most helpful compiler, it warns you about stuff like a special variable without earmuffs. CCL can catch some bugs that SBCL doesn't because it interprets the standard differently, though
23:32:59
aeth
jcowan: The default value of optionals and keywords are nil unless you specify one like &optional foo (bar 42) ; in this case foo is nil and bar is 42 if nothing is passed in
23:33:28
aeth
jcowan: In CL, there is no #<unspecified> or whatever a Scheme might use for stuff like that. Pretty much anywhere where there is a default value, it's nil, unless you explicitly use (values) or use an API that does
23:34:48
jcowan
So in fact you must specify all optional arguments, none can remain optional, if keyword arguments are to be processed as such.
23:35:34
aeth
jcowan: It does make sense from the perspective of &optional, which is to get to the later, you have to go through the earlier parts, even if it just means a bunch of ugly nils that were already the defaults
23:35:47
Bike
it would probably be even more complicated to try to interpret it another way, given the other parts of how keyword arguments (you can use non-keyword symbols, and pass keyword arguments not specified in the lambda list, plus you don't statically know the lambda list anyway)
23:36:31
jcowan
I'm beginning to grasp why Racket and Kawa treat keywords as syntax rather than Lisp objects.
23:37:05
Bike
yeah i kind of like how lisp works well enough, but it does have some really confusing parts
23:37:09
aeth
jcowan: Right, because if you see :foo :bar :baz :quux you don't know if you have 0, 2, or 4 keyword arguments.
23:37:33
jcowan
I think the moral is not to mix keywords, optional arguments, and rest arguments: pick one.
23:38:33
aeth
jcowan: &allow-other-keys is imo pretty much mandatory in higher order functions (at least ones that take in lambdas that use keywords) in Common Lisp because you can't pin a library to a version in Quicklisp, so if an API adds another keyword input, your version is now an error at whatever point it's funcalled.
23:41:47
aeth
There's some advantage to simple lambda list syntax, e.g. you can destructuring bind a plist tail with (... &key ... &allow-other-keys) to parse it... That's convenience you don't get for alists.
23:42:53
jcowan
whereas even if keywords were not self-evaluating, (foo 'a 32 'b 45) is perfectly readable and no more verbose than :a :b
8:05:37
decent-username
QUESTION: The following picture shows my current situation https://i.postimg.cc/Nf5QBFJ0/printing-2d-array.png
8:07:33
shka__
decent-username: like that https://github.com/sirherrbatka/cl-data-frames/blob/b8f1b32103d3cbcddeb0db3c13ce44156442ec28/src/api/functions.lisp#L32
8:34:09
Shinmera
Format has no way of tabular arrangement because you need to know the cell sizes ahead of time.
8:35:16
phadthai
FORMAT used to display columns of nicknames when entring an irc channel (indeed, size is calculated first): http://git.pulsar-zone.net/?p=mmondor.git;a=blob;f=mmsoftware/cl/test/irclog.lisp;hb=HEAD#l745: