Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:26616 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82723 invoked by uid 1010); 15 Nov 2006 19:55:39 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 82697 invoked from network); 15 Nov 2006 19:55:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Nov 2006 19:55:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=helly@php.net; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=helly@php.net; sender-id=unknown Received-SPF: error (pb1.pair.com: domain php.net from 81.169.182.136 cause and error) X-PHP-List-Original-Sender: helly@php.net X-Host-Fingerprint: 81.169.182.136 ajaxatwork.net Linux 2.4/2.6 Received: from [81.169.182.136] ([81.169.182.136:42563] helo=strato.aixcept.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A0/63-53553-9907B554 for ; Wed, 15 Nov 2006 14:55:06 -0500 Received: from [192.168.1.3] (dslb-084-063-069-039.pools.arcor-ip.net [84.63.69.39]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by strato.aixcept.de (Postfix) with ESMTP id B2D14610289; Wed, 15 Nov 2006 20:55:02 +0100 (CET) Date: Wed, 15 Nov 2006 20:56:08 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1583529945.20061115205608@marcus-boerger.de> To: Mathias Bank Cc: internals@lists.php.net In-Reply-To: <40.51.21305.3294B554@pb1.pair.com> References: <40.51.21305.3294B554@pb1.pair.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Feature-Request - Macros From: helly@php.net (Marcus Boerger) Hello Mathias, we would need a lexer/parser that support changing rules. That would mean changing bothtools. Eventhough that might happen if there are other reasons to do so,the toolswe change todo not necessarily support whatyou woule need. Based on our current experience re2c and lemon would be a big step forward as they also allow unicode handling. However i doubt that you can easily allow changing rules in lemon. Another solution would be to have your functionality as a stream operation. That is an extension could rewrite the incoming script while it is being compiled. I have however no idea if and how that could be achieved. best regards marcus Wednesday, November 15, 2006, 6:06:42 PM, you wrote: > Mathias Bank schrieb: >> Hallo, >> >> you know, that there was often a discussion about a "ifsetor" function. >> I want to generalize this discussion. If you know LISP, there is a >> fantastic macro function which allows you to generate own syntax (not a >> c macro function, which is really bad). It would be fantastic, if php >> could implement such a macro function. One example (for ifsetor): you >> could define >> >> macro ifsetor($param1, $param2) { >> return "if (isset($param1)) return $param1; else return $param2; >> } >> >> use: $test = ifsetor($_GET["blubb"],null); >> >> All you have to do is to not execute the parameters given in the macro >> parameter list. Instead, you have to evaluate the return statement and >> then to execute this statement. >> >> In this way, all discussions about ifsetor (or anything like this) could >> be avoided. >> >> The macro function could even be extended to allow new blocks, but then >> we have to extend the syntax to allow reference to the body. In this >> way, I always extend the syntax of the parameter data: only variables >> would be matched. >> >> macro foreachkey($array as $key, :body $body) { >> return "foreach ($array as $key=>$__dev0) { >> $body >> }"; >> } >> >> know, you can call >> $secondArray = array(); >> foreachkey($myArray as $myKey) { >> $secondArray[] = $myKey; >> } >> >> this would be extended to >> foreach ($myArray as $myKey=>$__dev0) { >> $secondArray[] = $myKey; >> } >> >> and this code will be executed. >> >> As you see, with this macro functions, it could be achieved any >> individual syntax. It would be a pleasure, if php could support it. It >> could shorten a lot of code. >> >> Mathias > I have recieved a few mails which have shown, that some people > misunderstood my idea. It seems, that most of you know c/c++ macros. But > I don't want to implement these macro functionality, because this > functionality is really poor. Have a look at the macro functionality of > lisp: > http://www.gigamonkeys.com/book/macros-standard-control-constructs.html > and http://www.gigamonkeys.com/book/macros-defining-your-own.html. > There, it is described, what macros in lisp can do. You will see, that > such macros cannot be compared with c/c++ macros. But it would be a > pleasure for php, if such macros would be possible. You should really > read it, I couldn't believe it until I have realized it at my own. > PHP is a really great language and the syntax is much better than the > syntax of lisp. But the macros are one big pleasure in lisp. And don't > mistake lisp macros for c macros. They are much more powerful. > Mathias Best regards, Marcus