Re: compiling XPath to Scheme source code
[email protected] Mon, 22 Nov 2004 21:47:16 -0800 (PST)
| Newsgroups | gmane.lisp.scheme.ssax-sxml |
|---|---|
| Message-ID | <[email protected]> |
Hello!
> I'm working on translating XPath expressions to Scheme
> source code which evaluates the XPath.
Isn't it like the specialization of the general sxpath function of the
type
sxpath:: SXPath -> SXML -> Nodelist
to the particular value of SXPath? Then we are talking about Partial
Evaluation (PE for short) -- which is a vast and developed area. I
wonder why Michael Sperber hasn't said anything: he wrote several
well-cited papers on this topic (as well as a partial evaluator for
the full Scheme, right Mike?). You can see the extensive bibliography
at
http://library.readscheme.org/page10.html
> ; Translate the xpath to a Scheme source code
> (define xpath-proc-src2 (xpath->scheme xpath-str2))
> ; A value of the variable "xpath-proc-src2" is:
> ; (node-join
> ; *root*
> ; (sxml:child (ntype?? 'AAA))
> ; (sxml:child (ntype?? 'CCC)))
> ;
> ; "eval" will fail on this expression because the variable
> ; "*root*" is not bound. So the new step appears.
> ; Bind variables.
> (define xpath-proc-src2b
> (sxlet ((*root* tree2)) xpath-proc-src2))
> ; A value of the variable "xpath-proc-src2b" is:
> ;
> ; (let ((*root* (lambda (dummy) tree2)))
> ; (node-join
> ; *root*
> ; (sxml:child (ntype?? 'AAA))
> ; (sxml:child (ntype?? 'CCC))))
So, xpath->scheme can generate open code (which has free variables),
and sxlet will generate code that captures those variables with
bindings. Hmm, sounds a bit risky. Dealing with open code is quite
error-prone and difficult. Perhaps we should consider the type of
sxpath to be
sxpath:: SXPath -> Root -> OtherVar -> SXML -> Nodelist
or
sxpath:: SXPath -> OtherVarDict -> SXML -> Nodelist
and specialize with respect to SXPath and OtherVarDict. So,
(xpath->scheme-no-dict xpath-str2)
will generate something like
(lambda (dict)
(node-join
(lookup-def '*root* dict)
(sxml:child (ntype?? 'AAA))
(sxml:child (ntype?? 'CCC))))
whereas
(xpath->scheme xpath-str2
'((*root* tree2))) ; statically known dict
will generate
(node-join
tree2
(sxml:child (ntype?? 'AAA))
(sxml:child (ntype?? 'CCC)))
Cheers,
Oleg
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/