unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: nalaginrut <nalaginrut@gmail.com>
To: Ian Price <ianprice90@googlemail.com>
Cc: guile-devel@gnu.org
Subject: Re: can't use variable in sxml-match?
Date: Fri, 20 May 2011 13:17:00 +0800	[thread overview]
Message-ID: <1305868620.1981.102.camel@Renee-desktop> (raw)
In-Reply-To: <m3pqneuitz.fsf@googlemail.com>

> 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---




  reply	other threads:[~2011-05-20  5:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-20  3:55 can't use variable in sxml-match? Ian Price
2011-05-20  5:17 ` nalaginrut [this message]
2011-05-31 22:01 ` Ludovic Courtès
2011-05-31 23:56   ` nalaginrut
  -- strict thread matches above, loose matches on Subject: below --
2011-05-20  1:06 nalaginrut
2011-05-20  2:26 ` nalaginrut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1305868620.1981.102.camel@Renee-desktop \
    --to=nalaginrut@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=ianprice90@googlemail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).