From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.emacs.devel Subject: Re: Keyword args Date: Mon, 13 Dec 2010 21:00:47 +0100 Message-ID: References: <87mxojwu15.fsf@uwakimon.sk.tsukuba.ac.jp> <87k4jnweng.fsf@uwakimon.sk.tsukuba.ac.jp> <87d3pdwt1x.fsf@uwakimon.sk.tsukuba.ac.jp> <87bp4x37ey.fsf@lola.goethe.zz> <874oapwnon.fsf@uwakimon.sk.tsukuba.ac.jp> <4D01D9D8.5040400@gmail.com> <4D0580A6.7090307@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1292270214 17171 80.91.229.12 (13 Dec 2010 19:56:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 13 Dec 2010 19:56:54 +0000 (UTC) Cc: Helmut Eller , emacs-devel@gnu.org To: Daniel Colascione Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Dec 13 20:56:50 2010 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PSEVt-0005lC-Sk for ged-emacs-devel@m.gmane.org; Mon, 13 Dec 2010 20:56:50 +0100 Original-Received: from localhost ([127.0.0.1]:52797 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PSEVt-0006nf-50 for ged-emacs-devel@m.gmane.org; Mon, 13 Dec 2010 14:56:49 -0500 Original-Received: from [140.186.70.92] (port=45018 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PSEVi-0006lL-P3 for emacs-devel@gnu.org; Mon, 13 Dec 2010 14:56:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PSEVc-000726-JY for emacs-devel@gnu.org; Mon, 13 Dec 2010 14:56:38 -0500 Original-Received: from a-pb-sasl-sd.pobox.com ([64.74.157.62]:50431 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PSEVc-00071n-Gr for emacs-devel@gnu.org; Mon, 13 Dec 2010 14:56:32 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 2983C3EE9; Mon, 13 Dec 2010 14:56:57 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=iX9rb+0loWHO7ax/oASQC9om5zY=; b=iI0M2N 86jUBaEDxT5/Fcgo4V6t1khXZi/nvNdGbg1hMshxZNuLTtAf4Ae4Mvx/VkCsrLVU wK4Skj5zq4Ap8BKws/QuOzWRavVY0kZdP0gvBgtVHFu+xLMs5atZr9dwE85EXeSS VIOOZOvBLpbEFHLmfiBbpbrNdncmgP1UvhjHY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=HpcYugAKBVj2RI8LF3LcQYHXcvQCLjDp 69ezQjCUPBxKdwcwyVrnszV4/2NASweDXlyobKA3KjdDxH7SPBPZA5ECJeaQcXBe leiECa5fk831qtAgFMSSFDtaHk8+5xGnWPwNQe8aNRUMBT4Pvf5mh8YRyy7JsoYp cXLkD6oUc3U= Original-Received: from a-pb-sasl-sd.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 053E13EE7; Mon, 13 Dec 2010 14:56:55 -0500 (EST) Original-Received: from unquote.localdomain (unknown [90.164.198.39]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id E33303EE5; Mon, 13 Dec 2010 14:56:51 -0500 (EST) In-Reply-To: <4D0580A6.7090307@gmail.com> (Daniel Colascione's message of "Sun, 12 Dec 2010 18:10:46 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-Pobox-Relay-ID: 22AEAF12-06F3-11E0-A1D1-C4BE9B774584-02397024!a-pb-sasl-sd.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:133655 Archived-At: On Mon 13 Dec 2010 03:10, Daniel Colascione writes: > 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. FWIW, Guile supports keyword arguments natively. IMO the proper way to do things is to keep a uniform calling convention, and allow procedures to parse arguments themselves, with low-level support. scheme@(guile-user)> (lambda* (#:key (foo 42)) foo) $1 = # scheme@(guile-user)> ,disassemble $1 Disassembly of #: Here we have some instructions that aren't disassembled quite as perspicaciously as one might like, but they take the args on the stack, and shuffle the non-positional args up: 0 (assert-nargs-ge 0 0) 3 (bind-optionals/shuffle 0 0 0 0 0 1) And here we bind keywords. This says "fetch the keywords from the constant table at index 1, and scan the non-positional args for one keyword, disallowing other keywords. 10 (bind-kwargs 0 1 0 1 0) It's somewhat complicated code, but it's a const only borne by keyword arguments. Here we have the code that initializes `foo' if it's not given: 16 (reserve-locals 0 1) 19 (local-bound? 0) 21 (br-if :L111) ;; -> 29 25 (make-int8 42) ;; 42 27 (local-set 0) ;; `foo' And finally (!) the main body: 29 (local-ref 0) ;; `foo' 31 (return) Some tests: > (define (fib n) (if (< n 2) 1 (+ (fib (- n 1)) (fib (- n 2))))) > ,time (fib 35) $1 = 14930352 clock utime stime cutime cstime gctime 2.99 2.99 0.01 0.00 0.00 0.00 > (define* (fibk #:key (n 0)) (if (< n 2) 1 (+ (fibk #:n (- n 1)) (fibk #:n (- n 2))))) > ,time (fibk 35) :5:6: warning: possibly wrong number of arguments to `fibk' While executing meta-command: ERROR: Odd length of keyword argument list > ,time (fibk #:n 35) $2 = 14930352 clock utime stime cutime cstime gctime 5.01 4.99 0.00 0.00 0.00 0.00 FWIW on this machine a byte-compiled elisp (fib 35) on emacs takes about 6 seconds. I wrote more about this sort of thing here: http://wingolog.org/archives/2009/11/07/case-lambda-in-guile http://wingolog.org/archives/2009/11/08/optionals-keywords-oh-my Our elisp support uses this native infrastructure for keywords and optionals, but there obviously are some differences regarding implementation of dynamic scope. Lexical binding is a lot cheaper, for Guile, but we hope to get dynamic binding cheap too. Anyway, I would like to discourage complicated implementations in "user-space" for keyword arguments. They should be a core language feature, for all the reasons I gave in my first article. Happy hacking, Andy -- http://wingolog.org/