Re: [ssax-sxml] SXPath: high-level API modernization
Brought to you by:
oleg
From: Kirill L. <lis...@ac...> - 2003-07-31 22:57:29
|
Hello! On Tue, 29 Jul 2003, David Allouche wrote: > I am not sure this contribution is going to be relevant, but I had a > similar issue in my work. That is handling dynamic environment in > performant and referentially-transparent way. Thank you very mach for very interesting message! I consider utilization of your "with-environment" in STX engine for parameterization of template functions, but it looks like most peoples consider explicit parameter passing as more clear for SXPath. It's a bit simpler and more concise also, so I think that's the way to go for high-level API of SXPath, which has to be as friendly for XML people as possible. Thus I think that your "environment" has to be passed explicitly to every location function. I really like your idea of convenience macro for access to environment variable. As we are moving to R5RS macros now, I think that we'll employ something like: (define-syntax env-ref (syntax-rules () ((env-ref env key) (cond ((assq (quote key) env) => cdr) (else (cerr "Unbound key " key " in environment:" env)))))) > It is "safer" performance-wise to use hash-tables (actually texmacs > adaptative hash-tables) for variable look-up, but it may be > preferrable in some context to use alists, or trees, to provide true > referential transparence (thread safety). In context of SXML we mostly have just a few vars in environment. I think that for the sake of simplicity and portability we can use assq here. On 29 Jul 2003, Joerg F. Wittenberger wrote: > Experience shows that you usually need not even a dozen XSLT variables > and reference them a few times. The penealty of a assoc seems > bearable. I do agree with Joerg, and my own experience shows that this holds for most (any?) XPath/SXPath applications... > (define (environment-ref* env key) > (let ((h (ahash-get-handle env key))) > (if h (cdr h) > ;; WARNING: guile-1.3.4 requires %S instead of ~S > (texmacs-error "Unbound key in environment:" key)))) > BTW: neither %S nor ~S here... BTW#2: Please drop a look at sxml-tools.scm I believe that you can reuse something in TexMacs convert/tools/sxml.scm ... Thank you a lot for your feedback and ideas! Best regards, Kirill. |