From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: nalaginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: can't use variable in sxml-match? Date: Fri, 20 May 2011 13:17:00 +0800 Organization: HFG Message-ID: <1305868620.1981.102.camel@Renee-desktop> References: Reply-To: NalaGinrut@gmail.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1305868648 15340 80.91.229.12 (20 May 2011 05:17:28 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 20 May 2011 05:17:28 +0000 (UTC) Cc: guile-devel@gnu.org To: Ian Price Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri May 20 07:17:24 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QNI5S-0007gu-HI for guile-devel@m.gmane.org; Fri, 20 May 2011 07:17:22 +0200 Original-Received: from localhost ([::1]:32863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNI5R-0001Ui-Rb for guile-devel@m.gmane.org; Fri, 20 May 2011 01:17:21 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:52802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNI5P-0001Ud-Bf for guile-devel@gnu.org; Fri, 20 May 2011 01:17:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QNI5O-0005Qh-9T for guile-devel@gnu.org; Fri, 20 May 2011 01:17:19 -0400 Original-Received: from mail-iy0-f169.google.com ([209.85.210.169]:36853) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNI5O-0005Qb-1u for guile-devel@gnu.org; Fri, 20 May 2011 01:17:18 -0400 Original-Received: by iyh42 with SMTP id 42so3556636iyh.0 for ; Thu, 19 May 2011 22:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:subject:from:reply-to:to:cc:in-reply-to :references:content-type:organization:date:message-id:mime-version :x-mailer:content-transfer-encoding; bh=QKg1k96P0ixqQ4cER5xJk3K0kKILggh1dnYg196xSeE=; b=G9dUoWbtbqGXDX3xhv3Pq/w0KcI9ceOftpzSn3Slzq+80LA1lVbgKZVRJCRhKp/JqU KBKHgD3NEVw2KCJXk2ciXaJohWL7l3GopmVGkjs8H/IM15SZ38fmhkxDJw0irAjJa7Vy 9TrHVTBZLIjd9zB8XMbRde3VwsUeUcMw4mIWI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:reply-to:to:cc:in-reply-to:references:content-type :organization:date:message-id:mime-version:x-mailer :content-transfer-encoding; b=Qz8syrBiBTFT4mqow2xGYutmK+bt0iCD2vByduLSBjXTBC4zjHb+JazMexfxtbnBFO /8RvWgIxns6i6ZQcEZE7TGl3/7dRKEYTktFM+KCrRelorLM7usYr3EZxac/XUqlvba0P PVDnwimEqMA/eB7wj/2++oZIlZ3afWaxgbWRI= Original-Received: by 10.42.97.5 with SMTP id l5mr4288415icn.504.1305868636087; Thu, 19 May 2011 22:17:16 -0700 (PDT) Original-Received: from [192.168.100.100] ([183.15.158.157]) by mx.google.com with ESMTPS id 14sm1392870ibc.42.2011.05.19.22.17.10 (version=SSLv3 cipher=OTHER); Thu, 19 May 2011 22:17:15 -0700 (PDT) In-Reply-To: X-Mailer: Evolution 2.28.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.210.169 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:12508 Archived-At: > Hi guilers, > > Just a note to say that we found a solution to nalaginrut's problem on IRC. > > (lambda (mypattern) > ;; Instead of testing the head of the pattern in the sxml-match, I > ;; have moved it out to here. > (let* ((new-tag (if (equal? mypattern (car cl)) > 'success > 'fail)) > ;; replace the head with 'success or 'fail depending on a match > (new-expr (cons new-tag (cdr cl)))) > (sxml-match new-expr > ;; here we test against the new head > [(success (@ (type ,tv)) ,cv) ...] > [,otherwise #f]))) > > Another suggestion was to use syntax-rules to create the match pattern > at expand time. If anyone else has a better solution, feel free to pipe > up. :) > > Ian I should remind the fact that the tag-symbol must be already decided in this sxml-match implementation according to the grammar syntax of it. We can't pass a variable to substitute it. It causes some generalization problem for somebody. And the code of this implementation maybe hard to hack (think about 1000 lines macro). We considered some easier way to deal with relative problems. And I tried the syntax-rules solution, it works, but something worth to notice: (define-syntax mypattern (syntax-rules () ((_ ll tag) (sxml-match ll [(tag (@ (i ,d)) ,a ,b ,c) (list d a b c)] [,otherwise #f])))) (define cl '(asdfasdf (@ (i 1)) 3 4 5)) ;; call it (mypattern cl asdfasdf) ==>(1 3 4 5) ----------------------------------------- But I think it's a fake solution. Because I can't use any var/exp to substitute the tag in mypattern too. I need this: (mypattern cl (string->symbol "asdfasdf")) or (define mytag 'asdfsadf) (mypattern cl mytag) -->this will use mytag as the tag-symbol. Actually, this syntax-rules is the same as sxml-match. I expect some guys who familiar with macro explaining it to me. :-) The other solution is to "modify the code on the fly", then eval it. But finally I realized that sxml-match is macro, not suitable for eval. Any new suggestions will be welcome. :-) -- GNU Powered it GPL Protected it GOD Blessed it HFG - NalaGinrut --hacker key-- v4sw7CUSMhw6ln6pr8OSFck4ma9u8MLSOFw3WDXGm7g/l8Li6e7t4TNGSb8AGORTDLMen6g6RASZOGCHPa28s1MIr4p-x hackerkey.com ---end key---