From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Per Abrahamsen Newsgroups: gmane.emacs.devel Subject: Re: Creating recursive customization types / widgets Date: Mon, 01 Dec 2003 14:27:27 +0100 Organization: The Church of Emacs Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1070306040 6843 80.91.224.253 (1 Dec 2003 19:14:00 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 1 Dec 2003 19:14:00 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Mon Dec 01 20:13:55 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AQtUZ-0000Qj-00 for ; Mon, 01 Dec 2003 20:13:55 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1AQtUZ-0003bq-00 for ; Mon, 01 Dec 2003 20:13:55 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AQuEK-0000CD-7x for emacs-devel@quimby.gnus.org; Mon, 01 Dec 2003 15:01:12 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AQpUd-0007Me-E0 for emacs-devel@gnu.org; Mon, 01 Dec 2003 09:57:43 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AQp2k-0003mY-EX for emacs-devel@gnu.org; Mon, 01 Dec 2003 09:29:25 -0500 Original-Received: from [130.225.40.227] (helo=sheridan.dina.kvl.dk) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AQp2j-0003mN-Dw; Mon, 01 Dec 2003 09:28:53 -0500 Original-Received: by sheridan.dina.kvl.dk (Postfix, from userid 304) id 9DF0913CE9; Mon, 1 Dec 2003 14:27:27 +0100 (CET) Original-To: rms@gnu.org X-Face: +kRV2]2q}lixHkE{U)mY#+6]{AH=yN~S9@IFiOa@X6?GM|8MBp/ In-Reply-To: (Richard Stallman's message of "Sun, 30 Nov 2003 20:45:10 -0500") User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:18249 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:18249 Richard Stallman writes: > (define-widget 'child 'default > "Base widget for recursive datastructures. > > You need to set :type to the widget type for the datastructure you > want to define, and set :match to a function that matches the > datastructure. If the datastructure is not recursive, you don't have > to set :match." > > It looks like a good feature, but I can't really understand > that doc string, so it needs to be somewhat clearer. Most widget doc strings are much worse, but that's no excuse. Is the following understandable? (define-widget 'child 'default "Base widget for recursive datastructures. The `child' widget will, when instantiated, contain a single inferior widget, of the widget type specified by the :type parameter. The value of the `child' widget is the same as the value of the inferior widget. When deriving a new widget from the 'child' widget, the :type parameter is allowed to refer to the widget currently being defined, thus allowing recursive datastructures to be described. The :type parameter takes the same arguments as the defcustom parameter with the same name. Background: Most composite widgets, i.e. widgets containing other widgets, does not allow recursion. That is, when you define a new widget type, none of the inferior widgets may be of the same type you are currently defining. In Lisp, however, it is custom to define datastructures in terms of themselves. A list, for example, is defined as either nil, or a cons cell whose cdr itself is a lisp. The obvious way to translate this into a widget type would be (define-widget 'my-list 'choice \"A list of sexps.\" :tag \"Sexp list\" :args '((const nil) (cons :value (nil) sexp my-list))) Here we attempt to define my-list as a choice of either the constant nil, or a cons-cell containing a sexp and my-lisp. This will not work because the `choice' widget does not allow recursion. Using the `child' widget you can overcome this problem, as in this example: (define-widget 'sexp-list 'child \"A list of sexps.\" :tag \"Sexp list\" :type '(choice (const nil) (cons :value (nil) sexp sexp-list)))" :format "%{%t%}: %v"