Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:5255 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15513 invoked by uid 1010); 5 Nov 2003 18:08:01 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 15436 invoked from network); 5 Nov 2003 18:08:00 -0000 Received: from unknown (HELO smtpzilla5.xs4all.nl) (194.109.127.141) by pb1.pair.com with SMTP; 5 Nov 2003 18:08:00 -0000 Received: from duron.xs4all.nl (a213-84-38-246.adsl.xs4all.nl [213.84.38.246]) by smtpzilla5.xs4all.nl (8.12.9/8.12.9) with ESMTP id hA5I7tEi071148 for ; Wed, 5 Nov 2003 19:07:59 +0100 (CET) Message-ID: <5.1.0.14.0.20031105190706.037c5150@localhost> X-Sender: ganswijk@pop.xs4all.nl@localhost X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Wed, 05 Nov 2003 19:07:13 +0100 To: internals@lists.php.net Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Subject: Re: [PHP-DEV] Proposal: Array syntax From: ganswijk@xs4all.nl (Jaap van Ganswijk) At 2003-11-05 09:59 +0100, Michael Walter wrote: >Very cool. > >How about supporting .. syntax, btw. as in [1..3] or ["a".."z"]? Might no be the worth, just thinking out loud ;) I'm also in favor of a shorter notation for array() and list(). In fact this also helps to ease the problem I have with 'foreach ($A as $I=>$d)', because it would then be possible to write: while ([$i,$d]=each($A)). It's still not as short as I'd like it to be: 'while ($i=>$d in $A)', but it's already a lot better. I'd also like to see ranges supported and propose to add notations for inclusive and non-inclusive ranges as: 1..3 inclusive at both ends so equal to 1,2,3 1.<3 non inclusive at the end so equal to 1,2 1>.3 non inclusive at the beginning so equal to 2,3 1><3 non inclusive at both ends so equal to 2 Of course generally only the first two variations are being used. (Please note that this syntax conflicts slightly with the syntax of floating point numbers and compares. Perhaps it's solvable by scanning '..', '.<', '>.' and '><' as tokens first and not allowing ranges with floating point numbers anyway.) By the way, Python has three 'group' notations: [] for a list {} for a dictionary () for a tuple Very confusing (and one of the reasons I prefer PHP over Python ;-), and I agree with Rasmus that at least here the symbols no longer make clear what is being meant, but I think that just [] for the values in an array is very intuitive because the same symbols are being used to add the index of an array. (But {} from the set notion in mathematics would be fine too, I think). By the way, don't forget to allow a comma at the end of a list: 1,2,3, This especially makes sense when the elements are listed each on a seperate line: 1, 2, 3, Greetings, Jaap >Christian Schneider wrote: >>I propose to add an alternative (backward compatible) short array creation syntax: >>$a = [ 1, 2, 3 ]; and $a = [ 'a' => 42, 'b' => "foo" ]; >>It can also be used in function calls: >>img(['src' => "logo.gif", 'alt' => "Logo"]); >>Reason behind this change: Arrays are used a lot and should therefore have as little syntactic overhead as possible. And I think the short syntax is also easier to read and write. >>A patch for the parser is trivial and is attached for Zend2. >>Note: I checked the newsgroup archive but couldn't find a discussion about this. After not hearing back about my proposed enhancement to debug_backtrace() and the dangling comma for function call parameters being rejected I wonder if I'm using the right mailing list for this :-) >>- Chris >> >>------------------------------------------------------------------------ >>Index: Zend/zend_language_parser.y >>=================================================================== >>RCS file: /repository/ZendEngine2/zend_language_parser.y,v >>retrieving revision 1.127 >>diff -u -r1.127 zend_language_parser.y >>--- Zend/zend_language_parser.y 19 Oct 2003 08:38:48 -0000 1.127 >>+++ Zend/zend_language_parser.y 4 Nov 2003 23:32:12 -0000 >>@@ -581,6 +581,7 @@ >> | '@' { zend_do_begin_silence(&$1 TSRMLS_CC); } expr { zend_do_end_silence(&$1 TSRMLS_CC); $$ = $3; } >> | scalar { $$ = $1; } >> | T_ARRAY '(' array_pair_list ')' { $$ = $3; } >>+ | '[' array_pair_list ']' { $$ = $2; } >> | '`' encaps_list '`' { zend_do_shell_exec(&$$, &$2 TSRMLS_CC); } >> | T_PRINT expr { zend_do_print(&$$, &$2 TSRMLS_CC); } >> ; > >-- >PHP Internals - PHP Runtime Development Mailing List >To unsubscribe, visit: http://www.php.net/unsub.php