Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10733 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86177 invoked by uid 1010); 23 Jun 2004 18:26:06 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 86113 invoked from network); 23 Jun 2004 18:26:06 -0000 Received: from unknown (HELO spawn.leetspeak.org) (217.28.101.185) by pb1.pair.com with SMTP; 23 Jun 2004 18:26:06 -0000 Received: (qmail 5848 invoked from network); 23 Jun 2004 20:27:06 +0200 Received: from pd9e55b88.dip.t-dialin.net (HELO ?192.168.1.11?) (cm@217.229.91.136) by molly.zwonet.de with AES256-SHA encrypted SMTP; 23 Jun 2004 20:27:06 +0200 Message-ID: <40D9CB3C.7020006@leetspeak.org> Date: Wed, 23 Jun 2004 20:26:04 +0200 User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Bert Slagter CC: internals@lists.php.net References: <20040623150429.E62456@hyperion-data.net> <20040623163305.73484.qmail@pb1.pair.com> In-Reply-To: <20040623163305.73484.qmail@pb1.pair.com> X-Enigmail-Version: 0.84.1.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: keyword arguments? From: cm@leetspeak.org (Michael Walter) Bert Slagter wrote: > Even after reading your message twice, I can't think of an example where > this would be useful. Obviously, I don't understand your intention. The original poster wants to add syntax for keyword arguments. Keyword arguments can be found in quite some languages (Python, Common Lisp, ...), they allow you to bind a parameter by name instead of by position (similar to using an array vs. a hash). > Could you give an example of a construction that is made possible by > this feature (and thus would otherwise be impossible)? Surely we aren't dealing with Turing completeness here, are we? Consider the following constructor: class Window: def __init__(title, x=USE_DEFAULT, y=USE_DEFAULT, width=USE_DEFAULT, height=USE_DEFAULT, parent=None): pass And contrast: window = Window(title='Hello World', width=640, height=480) with: window = Window('Hello World', USE_DEFAULT, USE_DEFEAULT, 640, 480) Cheers, Michael > > Bert > > Daniel Crookston wrote: > >> It looks like the last time this was discussed was October of 2003, over >> the course of about five emails. I don't see anything in the archives >> about it since then. Here's what I'd like to suggest. >> >> some_function($a, 'B', :check TRUE) >> >> function some_function($first, $second, :check $key1 = FALSE, :foo $key2) >> { >> if ($key1) { >> lala; >> } elseif ($key2 > 0) { >> blabla; >> } >> } >> >> Sticking a : in front of the variable name, either in the calling code or >> the function declaration, makes it a keyword argument. Keyword arguments >> are always optional, and [could|should] default to something handy like >> FALSE or 0. (Maybe make their defaults settable in php.ini?) >> >> I would implement this myself, but even after reading George >> Schlossnagle's fantastic book, I'm still not wizardly enough to do >> so. If >> someone could point me in the right direction, though... >> >> Thanks for listening, >> Daniel > >