* Re: can't use variable in sxml-match?
@ 2011-05-20 3:55 Ian Price
2011-05-20 5:17 ` nalaginrut
2011-05-31 22:01 ` Ludovic Courtès
0 siblings, 2 replies; 6+ messages in thread
From: Ian Price @ 2011-05-20 3:55 UTC (permalink / raw)
To: nalaginrut; +Cc: guile-devel
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: can't use variable in sxml-match?
2011-05-20 3:55 can't use variable in sxml-match? Ian Price
@ 2011-05-20 5:17 ` nalaginrut
2011-05-31 22:01 ` Ludovic Courtès
1 sibling, 0 replies; 6+ messages in thread
From: nalaginrut @ 2011-05-20 5:17 UTC (permalink / raw)
To: Ian Price; +Cc: guile-devel
> 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---
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: can't use variable in sxml-match?
2011-05-20 3:55 can't use variable in sxml-match? Ian Price
2011-05-20 5:17 ` nalaginrut
@ 2011-05-31 22:01 ` Ludovic Courtès
2011-05-31 23:56 ` nalaginrut
1 sibling, 1 reply; 6+ messages in thread
From: Ludovic Courtès @ 2011-05-31 22:01 UTC (permalink / raw)
To: guile-devel
Hello,
Ian Price <ianprice90@googlemail.com> skribas:
> Just a note to say that we found a solution to nalaginrut's problem on IRC.
Great. What was the problem?
Ludo'.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: can't use variable in sxml-match?
2011-05-31 22:01 ` Ludovic Courtès
@ 2011-05-31 23:56 ` nalaginrut
0 siblings, 0 replies; 6+ messages in thread
From: nalaginrut @ 2011-05-31 23:56 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-devel
> Hello,
>
> Ian Price <ianprice90@googlemail.com> skribas:
>
> > Just a note to say that we found a solution to nalaginrut's problem on IRC.
>
> Great. What was the problem?
>
> Ludo'.
>
>
well~let me repeat it in brief:
===============Begin===============
(lambda (my-pattern)
(sxml-match
cl
[(my-pattern
(@ (type ,tv)) ,cv)
...............
===============End===============
I want to use a variable to be the tag-symbol in sxml-match. But we
found it impossible in IRC discussion, because the sxml-match syntax
definition said this tag-symbol must be a already-known-symbol. So
there's some generalize problem. Ian thought a simple approach to solve
this without modify the sxml-match code.
--
GNU Powered it
GPL Protected it
GOD Blessed it
HFG - NalaGinrut
--hacker key--
v4sw7CUSMhw6ln6pr8OSFck4ma9u8MLSOFw3WDXGm7g/l8Li6e7t4TNGSb8AGORTDLMen6g6RASZOGCHPa28s1MIr4p-x hackerkey.com
---end key---
^ permalink raw reply [flat|nested] 6+ messages in thread
* can't use variable in sxml-match?
@ 2011-05-20 1:06 nalaginrut
2011-05-20 2:26 ` nalaginrut
0 siblings, 1 reply; 6+ messages in thread
From: nalaginrut @ 2011-05-20 1:06 UTC (permalink / raw)
To: guile-devel
hi guys!
I got a problem when I using sxml-match.
Let me describe it more briefly:
================Begin=================
(sxml-match
cl
[(http://www.w3.org/2005/Atom:content
(@ (type ,tv)) ,cv)
...do something...
[,otherwise #f])
===============End==================
As you see, I must write "content" with the namespace for some reason.
But I want a more generic solution ,or I must change source code when
namespace changes. Like:
===============Begin===============
(lambda (mypattern)
(sxml-match
cl
[(,my-pattern
(@ (type ,tv)) ,cv)
...............
===============End===============
I can't substitute 'http://www.w3.org/2005/Atom:content by a variable,
say ,mypattern. It spews a lot of error message.
Is it a bug or I missed something?
--
GNU Powered it
GPL Protected it
GOD Blessed it
HFG - NalaGinrut
--hacker key--
v4sw7CUSMhw6ln6pr8OSFck4ma9u8MLSOFw3WDXGm7g/l8Li6e7t4TNGSb8AGORTDLMen6g6RASZOGCHPa28s1MIr4p-x hackerkey.com
---end key---
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: can't use variable in sxml-match?
2011-05-20 1:06 nalaginrut
@ 2011-05-20 2:26 ` nalaginrut
0 siblings, 0 replies; 6+ messages in thread
From: nalaginrut @ 2011-05-20 2:26 UTC (permalink / raw)
To: guile-devel
Sorry, there's a typo caused huge misunderstand in IRC.
Let me fix my letter:
================Begin=================
(sxml-match
cl
[(http://www.w3.org/2005/Atom:content
(@ (type ,tv)) ,cv)
...do something...
[,otherwise #f])
===============End==================
As you see, I must write "content" with the namespace for some reason.
But I want a more generic solution ,or I must change source code when
namespace changes. Like:
===============Begin===============
(lambda (mypattern)
(sxml-match
cl
[(my-pattern
(@ (type ,tv)) ,cv)
...............
===============End===============
I can't substitute 'http://www.w3.org/2005/Atom:content by a variable,
say ,mypattern. It spews a lot of error message.
And the error message like these:
====================Begin===============
key sxml-match-error, throw_args (#f "bad pattern syntax (not an element
pattern)" (#(syntax-object sxml-match ((top) #(ribcage () () ())
#(ribcage #(s) #((top)) #("i344")) #(ribcage () () ()) #(ribcage #(msg
exp sub) #((top) (top) (top)) #("i339" "i340" "i341")) #(ribcage
#(sxml-match-syntax-error ellipsis? literal? keyword? extract-cata-fun
add-pat-var add-cata-def process-cata-exp process-cata-defs
cata-defs->pvar-lst process-output-action compile-element-pat
compile-end-element compile-attr-list compile-item-list
compile-dotted-pattern-list compile-item) #((top) (top) (top) (top)
(top) (top) (top) (top) (top) (top) (top) (top) (top) (top) (top) (top)
(top)) #("i302" "i303" "i304" "i305" "i306" "i307" "i308" "i309" "i310"
"i311" "i312" "i313" "i314" "i315" "i316" "i317" "i318")) #(ribcage ()
() ()) #(ribcage #(stx) #((top)) #("i301"))) (hygiene sxml match))
#(syntax-object (#(syntax-object compile-clause ((m266 top) #(ribcage ()
() ()) shift #(ribcage #(dummy exp cata-fun clause0 clause) #((m2252
top) (top) (top) (top) (top)) #("i2266" "i2267" "i2268" "i2269"
"i2270")) #(ribcage () () ()) #(ribcage #(x) #((m2252 top)) #("i2254")))
(hygiene sxml match)) #(syntax-object (((unquote-splicing (string-append
ns "content")) (@ (type (unquote tv))) (unquote cv)) (begin (if tv (set!
type tv)) (if cv (set! content cv)))) ((top) #(ribcage () () ())
#(ribcage () () ()) #(ribcage #(exp) #((m261 top)) #("i265")) #(ribcage
#(cfun) #((m261 top)) #("i262")) #(ribcage () () ()) #(ribcage () () ())
#(ribcage () () ()) #(ribcage #(content) #((top)) #("i259")) #(ribcage
() () ()) #(ribcage #(type) #((top)) #("i257")) #(ribcage () () ())
#(ribcage #(title) #((top)) #("i255")) #(ribcage () () ()) #(ribcage
#(author-name) #((top)) #("i253")) #(ribcage () () ()) #(ribcage #(feed)
#((top)) #("i251")) #(ribcage () () ()) #(ribcage () () ()) #(ribcage
#(sxml) #((top)) #("i249"))) (hygiene guile-user)) #(syntax-object exp
((m261 top) #(ribcage () () ()) #(ribcage () () ()) #(ribcage #(exp)
#((m261 top)) #("i265")) #(ribcage #(cfun) #((m261 top)) #("i262"))
#(ribcage () () ()) shift #(ribcage #(dummy val clause0 clause) #((m2277
top) (top) (top) (top)) #("i2282" "i2283" "i2284" "i2285")) #(ribcage ()
() ()) #(ribcage #(x) #((m2277 top)) #("i2279"))) (hygiene sxml match))
#(syntax-object cfun ((m261 top) #(ribcage () () ()) #(ribcage () () ())
#(ribcage #(exp) #((m261 top)) #("i265")) #(ribcage #(cfun) #((m261
top)) #("i262")) #(ribcage () () ()) shift #(ribcage #(dummy val clause0
clause) #((m2277 top) (top) (top) (top)) #("i2282" "i2283" "i2284"
"i2285")) #(ribcage () () ()) #(ribcage #(x) #((m2277 top)) #("i2279")))
(hygiene sxml match)) (#(syntax-object lambda ((m266 top) #(ribcage ()
() ()) shift #(ribcage #(dummy exp cata-fun clause0 clause) #((m2252
top) (top) (top) (top) (top)) #("i2266" "i2267" "i2268" "i2269"
"i2270")) #(ribcage () () ()) #(ribcage #(x) #((m2252 top)) #("i2254")))
(hygiene sxml match)) () (#(syntax-object call-with-values ((m266 top)
#(ribcage () () ()) shift #(ribcage #(dummy exp cata-fun clause0 clause)
#((m2252 top) (top) (top) (top) (top)) #("i2266" "i2267" "i2268" "i2269"
"i2270")) #(ribcage () () ()) #(ribcage #(x) #((m2252 top)) #("i2254")))
(hygiene sxml match)) (#(syntax-object lambda ((m266 top) #(ribcage ()
() ()) shift #(ribcage #(dummy exp cata-fun clause0 clause) #((m2252
top) (top) (top) (top) (top)) #("i2266" "i2267" "i2268" "i2269"
"i2270")) #(ribcage () () ()) #(ribcage #(x) #((m2252 top)) #("i2254")))
(hygiene sxml match)) () (#(syntax-object sxml-match1 ((m266 top)
#(ribcage () () ()) shift #(ribcage #(dummy exp cata-fun clause0 clause)
#((m2252 top) (top) (top) (top) (top)) #("i2266" "i2267" "i2268" "i2269"
"i2270")) #(ribcage () () ()) #(ribcage #(x) #((m2252 top)) #("i2254")))
(hygiene sxml match)) #(syntax-object exp ((m261 top) #(ribcage () ()
()) #(ribcage () () ()) #(ribcage #(exp) #((m261 top)) #("i265"))
#(ribcage #(cfun) #((m261 top)) #("i262")) #(ribcage () () ()) shift
#(ribcage #(dummy val clause0 clause) #((m2277 top) (top) (top) (top))
#("i2282" "i2283" "i2284" "i2285")) #(ribcage () () ()) #(ribcage #(x)
#((m2277 top)) #("i2279"))) (hygiene sxml match)) #(syntax-object cfun
((m261 top) #(ribcage () () ()) #(ribcage () () ()) #(ribcage #(exp)
#((m261 top)) #("i265")) #(ribcage #(cfun) #((m261 top)) #("i262"))
#(ribcage () () ()) shift #(ribcage #(dummy val clause0 clause) #((m2277
top) (top) (top) (top)) #("i2282" "i2283" "i2284" "i2285")) #(ribcage ()
() ()) #(ribcage #(x) #((m2277 top)) #("i2279"))) (hygiene sxml match))
#(syntax-object ((unquote otherwise) #f) ((top) #(ribcage () () ())
#(ribcage () () ()) #(ribcage #(exp) #((m261 top)) #("i265")) #(ribcage
#(cfun) #((m261 top)) #("i262")) #(ribcage () () ()) #(ribcage () () ())
#(ribcage () () ()) #(ribcage #(content) #((top)) #("i259")) #(ribcage
() () ()) #(ribcage #(type) #((top)) #("i257")) #(ribcage () () ())
#(ribcage #(title) #((top)) #("i255")) #(ribcage () () ()) #(ribcage
#(author-name) #((top)) #("i253")) #(ribcage () () ()) #(ribcage #(feed)
#((top)) #("i251")) #(ribcage () () ()) #(ribcage () () ()) #(ribcage
#(sxml) #((top)) #("i249"))) (hygiene guile-user)))) #(syntax-object
escape ((m266 top) #(ribcage () () ()) shift #(ribcage #(dummy exp
cata-fun clause0 clause) #((m2252 top) (top) (top) (top) (top))
#("i2266" "i2267" "i2268" "i2269" "i2270")) #(ribcage () () ())
#(ribcage #(x) #((m2252 top)) #("i2254"))) (hygiene sxml match)))))
((#f) shift #(ribcage () () ()) #(ribcage #(escape) #((m266 top))
#("i270")) #(ribcage () () ()) #(ribcage () () ()) #(ribcage () () ()))
(hygiene guile-user))) (#(syntax-object (unquote-splicing (string-append
ns "content")) ((#f top) shift #(ribcage () () ()) #(ribcage #(escape)
#((m266 top)) #("i270")) #(ribcage () () ()) #(ribcage () () ())
#(ribcage () () ()) #(ribcage () () ()) #(ribcage () () ()) #(ribcage
#(exp) #((m261 top)) #("i265")) #(ribcage #(cfun) #((m261 top))
#("i262")) #(ribcage () () ()) #(ribcage () () ()) #(ribcage () () ())
#(ribcage #(content) #((top)) #("i259")) #(ribcage () () ()) #(ribcage
#(type) #((top)) #("i257")) #(ribcage () () ()) #(ribcage #(title)
#((top)) #("i255")) #(ribcage () () ()) #(ribcage #(author-name)
#((top)) #("i253")) #(ribcage () () ()) #(ribcage #(feed) #((top))
#("i251")) #(ribcage () () ()) #(ribcage () () ()) #(ribcage #(sxml)
#((top)) #("i249"))) (hygiene guile-user)) #(syntax-object (@ (type
(unquote tv))) ((#f top) shift #(ribcage () () ()) #(ribcage #(escape)
#((m266 top)) #("i270")) #(ribcage () () ()) #(ribcage () () ())
#(ribcage () () ()) #(ribcage () () ()) #(ribcage () () ()) #(ribcage
#(exp) #((m261 top)) #("i265")) #(ribcage #(cfun) #((m261 top))
#("i262")) #(ribcage () () ()) #(ribcage () () ()) #(ribcage () () ())
#(ribcage #(content) #((top)) #("i259")) #(ribcage () () ()) #(ribcage
#(type) #((top)) #("i257")) #(ribcage () () ()) #(ribcage #(title)
#((top)) #("i255")) #(ribcage () () ()) #(ribcage #(author-name)
#((top)) #("i253")) #(ribcage () () ()) #(ribcage #(feed) #((top))
#("i251")) #(ribcage () () ()) #(ribcage () () ()) #(ribcage #(sxml)
#((top)) #("i249"))) (hygiene guile-user)) #(syntax-object (unquote cv)
((#f top) shift #(ribcage () () ()) #(ribcage #(escape) #((m266 top))
#("i270")) #(ribcage () () ()) #(ribcage () () ()) #(ribcage () () ())
#(ribcage () () ()) #(ribcage () () ()) #(ribcage #(exp) #((m261 top))
#("i265")) #(ribcage #(cfun) #((m261 top)) #("i262")) #(ribcage () ()
()) #(ribcage () () ()) #(ribcage () () ()) #(ribcage #(content)
#((top)) #("i259")) #(ribcage () () ()) #(ribcage #(type) #((top))
#("i257")) #(ribcage () () ()) #(ribcage #(title) #((top)) #("i255"))
#(ribcage () () ()) #(ribcage #(author-name) #((top)) #("i253"))
#(ribcage () () ()) #(ribcage #(feed) #((top)) #("i251")) #(ribcage ()
() ()) #(ribcage () () ()) #(ribcage #(sxml) #((top)) #("i249")))
(hygiene guile-user))))
====================End===================
--
GNU Powered it
GPL Protected it
GOD Blessed it
HFG - NalaGinrut
--hacker key--
v4sw7CUSMhw6ln6pr8OSFck4ma9u8MLSOFw3WDXGm7g/l8Li6e7t4TNGSb8AGORTDLMen6g6RASZOGCHPa28s1MIr4p-x hackerkey.com
---end key---
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-05-31 23:56 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-20 3:55 can't use variable in sxml-match? Ian Price
2011-05-20 5:17 ` nalaginrut
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
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).