unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniel Colascione <dan.colascione@gmail.com>
To: Helmut Eller <eller.helmut@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Keyword args
Date: Sun, 12 Dec 2010 18:10:46 -0800	[thread overview]
Message-ID: <4D0580A6.7090307@gmail.com> (raw)
In-Reply-To: <m27hfi1025.fsf_-_@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3712 bytes --]

On 12/10/10 12:53 AM, Helmut Eller wrote:
> * Daniel Colascione [2010-12-10 07:42] writes:
> 
>> On 12/7/10 8:30 AM, Stephen J. Turnbull wrote:
>>> David Kastrup writes:
>>>
>>>  > I don't think anybody minds the features.
>>>
>>> IIRC rms has recently declared his dislike for CL-style keyword
>>> arguments.  I suppose that's part of the "syntactic complexity" you
>>> mention, but MON KEY OTOH points out cases where he'd like to use
>>> them.  So there are some fundamental disagreements here.
>>
>> I'd just like to add my support for keyword arguments. Functions like
>> write-region are both horrible and brittle because their parameters are
>> both numerous and overloaded; specific functionality can be more simply
>> expressed with using keyword arguments. 
> 
> You always have the option to make a macro with keyword arguments which
> expands to a call to the "raw" function.

How many forwarder macros do you need to sufficiently cover the problem
space? Combinatorial explosion is a problem when the set of possible
inputs is large.

> The only disadvantage of this approach is that macros can't be used with
> higher order functions, ala mapcar.  But keyword arguments a rarely
> useful in that case.

You're mostly right, though it's not impossible to imagine a situation
in which it's useful to APPLY a keyword-argument-parsing function.

>> Precedent can be seen in play-sound, defcustom, and elsewhere.
> 
> For a bad example see make-network-process.  That takes keyword
> arguments but the keyword parsing is done in C and it doesn't do a good
> job.  It doesn't detect invalid keywords; doesn't detect conflicting
> keys; some keys are documented to be ignored when some other keys are
> supplied.  It's very difficult to use.  Correct keyword parsing in C is
> difficult so I would vote against it.

Clearly, the solution is more uniform keyword argument parsing; either
library functions in C could be provided, or make-network-process could
be made a Lisp keyword-parsing front-end for some horrible
%make-network-process that implements the functionality.

Still, most functions aren't written in C, and keyword parsing is easier
in Lisp.

> Also note that defcustom is a macro and play-sound takes a plist.  The
> plist idiom is IMO superior to keywords.  In particular passing
> arguments along gets easier.  E.g.
> 
> (defun foo (x y plist) 
>   (bar x y) 
>   (baz plist))
> 
> is IMO more readable than:
> 
> (defun* foo (x y &key key1 key2 key3)    
>   (bar x y) 
>   (baz :key1 key1 :key2 key2 :key3 key3))
> 
> or the rather silly
> 
> (defun* foo (x y &rest plist &key key1 key2 key3)
>   (bar x y) 
>   (apply #'baz plist))

The apply example isn't that bad in my book, and most of the time, you
don't need to forward an arbitrary subset of keyword parameters to
another function anyway.

> 
> Since we have destructuring-bind parsing plists is not very hard.

Sure, but putting them in the lambda-list is even easier for most cases,
especially when there aren't that many arguments. It's also easier to
document functions written with &key than it is to document equivalent
functions that do ad-hoc parsing.

> 
>> The performance arguments opposing
>> keyword arguments don't seem to be supported by benchmarks, and in any
>> case, most functions, especially ones with rich functionality, aren't on
>> the fast path.
> 
> The sequence functions find, position, assoc*, member* etc. are on the
> fast path.  Ironically those are the functions where keyword args are
> very useful because the meaning is relatively consistent.

Compiler macros can eliminate the pain in this case.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

  reply	other threads:[~2010-12-13  2:10 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-05 23:55 Return MON KEY
2010-12-06  1:48 ` Return Stephen J. Turnbull
2010-12-06  5:50   ` Return MON KEY
2010-12-06  7:20     ` Return Stephen J. Turnbull
2010-12-06  9:00       ` Return David Kastrup
2010-12-06 19:11         ` Return Stefan Monnier
2010-12-06 19:09       ` Return Stefan Monnier
2010-12-06 19:19         ` Return Chong Yidong
2010-12-06 20:27           ` Return Stefan Monnier
2010-12-07  4:47         ` Return Miles Bader
2010-12-07  9:17           ` Return David Kastrup
2010-12-07 17:10             ` Return Stefan Monnier
2010-12-07 22:15               ` Return David Kastrup
2010-12-08 15:50             ` Return Fren Zeee
2010-12-09 22:38             ` Return Stefan Monnier
2010-12-10  1:41               ` Return Stephen J. Turnbull
2010-12-10  3:44                 ` Return Stefan Monnier
2010-12-10  8:28                   ` Return Stephen J. Turnbull
2010-12-23  5:39                     ` Return Fren Zeee
2010-12-07 12:44         ` Return Stephen J. Turnbull
2010-12-07 14:38           ` Return David Kastrup
2010-12-07 16:14             ` Return Stephen J. Turnbull
2010-12-07 17:11               ` Return tomas
2010-12-07  2:42       ` Return MON KEY
2010-12-07 14:34         ` Return Stephen J. Turnbull
2010-12-07 15:54           ` Return David Kastrup
2010-12-07 16:30             ` Return Stephen J. Turnbull
2010-12-08 13:42               ` Return Richard Stallman
2010-12-10  7:42               ` Return Daniel Colascione
2010-12-10  8:53                 ` Keyword args (was: Return) Helmut Eller
2010-12-13  2:10                   ` Daniel Colascione [this message]
2010-12-13  8:30                     ` Keyword args Helmut Eller
2010-12-13 20:00                     ` Andy Wingo
2010-12-14  5:03                       ` Miles Bader
2010-12-14  7:43                         ` Helmut Eller
2010-12-07 22:55           ` Return MON KEY
2010-12-08  7:28             ` Return Stephen J. Turnbull
2010-12-08 18:11               ` Return MON KEY
2010-12-09  8:37                 ` Return Stephen J. Turnbull
2010-12-07 23:21         ` Return Samuel Bronson
2010-12-08  8:06           ` Return Stephen J. Turnbull
2010-12-08 20:51             ` Return Samuel Bronson
  -- strict thread matches above, loose matches on Subject: below --
2010-12-12  4:49 Keyword args (was: Return) MON KEY
2010-12-12  8:34 ` Keyword args Helmut Eller
2010-12-12 17:01 MON KEY

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D0580A6.7090307@gmail.com \
    --to=dan.colascione@gmail.com \
    --cc=eller.helmut@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).