scm: Avoid xpath's shadowing of filter.

* module/sxml/xpath.scm (xpath:filter): Rename from filter.  Fixes
  shadowing of core filter.
This commit is contained in:
Jan Nieuwenhuizen 2017-01-03 22:18:22 +01:00
parent 5e988b4ebf
commit cd44770258

View file

@ -101,7 +101,7 @@
(define-module (sxml xpath) (define-module (sxml xpath)
#:use-module (ice-9 pretty-print) #:use-module (ice-9 pretty-print)
#:export (nodeset? node-typeof? node-eq? node-equal? node-pos #:export (nodeset? node-typeof? node-eq? node-equal? node-pos
filter take-until take-after map-union node-reverse xpath:filter take-until take-after map-union node-reverse
node-trace select-kids node-self node-join node-reduce node-trace select-kids node-self node-join node-reduce
node-or node-closure node-parent node-or node-closure node-parent
sxpath)) sxpath))
@ -181,11 +181,11 @@
(or (positive? n) (error "yikes!")) (or (positive? n) (error "yikes!"))
((node-pos (1- n)) (cdr nodeset)))))) ((node-pos (1- n)) (cdr nodeset))))))
; filter:: Converter -> Converter ; xpath:filter:: Converter -> Converter
; A filter applicator, which introduces a filtering context. The argument ; A xpath:filter applicator, which introduces a xpath:filtering context. The argument
; converter is considered a predicate, with either #f or nil result meaning ; converter is considered a predicate, with either #f or nil result meaning
; failure. ; failure.
(define (filter pred?) (define (xpath:filter pred?)
(lambda (lst) ; a nodeset or a node (will be converted to a singleton nset) (lambda (lst) ; a nodeset or a node (will be converted to a singleton nset)
(let loop ((lst (if (nodeset? lst) lst (list lst))) (res '())) (let loop ((lst (if (nodeset? lst) lst (list lst))) (res '()))
(if (null? lst) (if (null? lst)
@ -202,12 +202,12 @@
; each element of the nodeset, until the predicate yields anything but #f or ; each element of the nodeset, until the predicate yields anything but #f or
; nil. Return the elements of the input nodeset that have been processed ; nil. Return the elements of the input nodeset that have been processed
; till that moment (that is, which fail the predicate). ; till that moment (that is, which fail the predicate).
; take-until is a variation of the filter above: take-until passes ; take-until is a variation of the xpath:filter above: take-until passes
; elements of an ordered input set till (but not including) the first ; elements of an ordered input set till (but not including) the first
; element that satisfies the predicate. ; element that satisfies the predicate.
; The nodeset returned by ((take-until (not pred)) nset) is a subset -- ; The nodeset returned by ((take-until (not pred)) nset) is a subset --
; to be more precise, a prefix -- of the nodeset returned by ; to be more precise, a prefix -- of the nodeset returned by
; ((filter pred) nset) ; ((xpath:filter pred) nset)
(define (take-until pred?) (define (take-until pred?)
(lambda (lst) ; a nodeset or a node (will be converted to a singleton nset) (lambda (lst) ; a nodeset or a node (will be converted to a singleton nset)
@ -290,7 +290,7 @@
; such patterns that together implement XPath location path ; such patterns that together implement XPath location path
; specification. As it turns out, all these combinators can be built ; specification. As it turns out, all these combinators can be built
; from a small number of basic blocks: regular functional composition, ; from a small number of basic blocks: regular functional composition,
; map-union and filter applicators, and the nodeset union. ; map-union and xpath:filter applicators, and the nodeset union.
@ -310,7 +310,7 @@
((null? node) node) ((null? node) node)
((not (pair? node)) '()) ; No children ((not (pair? node)) '()) ; No children
((symbol? (car node)) ((symbol? (car node))
((filter test-pred?) (cdr node))) ; it's a single node ((xpath:filter test-pred?) (cdr node))) ; it's a single node
(else (map-union (select-kids test-pred?) node))))) (else (map-union (select-kids test-pred?) node)))))
@ -319,7 +319,7 @@
; Similar to select-kids but apply to the Node itself rather ; Similar to select-kids but apply to the Node itself rather
; than to its children. The resulting Nodeset will contain either one ; than to its children. The resulting Nodeset will contain either one
; component, or will be empty (if the Node failed the Pred). ; component, or will be empty (if the Node failed the Pred).
(define node-self filter) (define node-self xpath:filter)
; node-join:: [LocPath] -> Node|Nodeset -> Nodeset, or ; node-join:: [LocPath] -> Node|Nodeset -> Nodeset, or
@ -447,7 +447,7 @@
; (sxpath1 '(path reducer ...)) -> ; (sxpath1 '(path reducer ...)) ->
; (node-reduce (sxpath path) (sxpathr reducer) ...) ; (node-reduce (sxpath path) (sxpathr reducer) ...)
; (sxpathr number) -> (node-pos number) ; (sxpathr number) -> (node-pos number)
; (sxpathr path-filter) -> (filter (sxpath path-filter)) ; (sxpathr path-xpath:filter) -> (xpath:filter (sxpath path-xpath:filter))
(define (sxpath path) (define (sxpath path)
(lambda (nodeset) (lambda (nodeset)
@ -484,7 +484,7 @@
(reducer ((node-pos (car reducing-path)) nodeset) (reducer ((node-pos (car reducing-path)) nodeset)
(cdr reducing-path))) (cdr reducing-path)))
(else (else
(reducer ((filter (sxpath (car reducing-path))) nodeset) (reducer ((xpath:filter (sxpath (car reducing-path))) nodeset)
(cdr reducing-path)))))) (cdr reducing-path))))))
(else (else
(error "Invalid path step: " (car path))))))) (error "Invalid path step: " (car path)))))))