guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can't use variable in sxml-match?


From: nalaginrut
Subject: Re: can't use variable in sxml-match?
Date: Fri, 20 May 2011 13:17:00 +0800

> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]