1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 03:40:34 +02:00

doc: Replace square brackets with round brackets.

* doc/ref/sxml-match.texi: Replace all square brackets with round
brackets in order to be consistent with the rest of the documentation.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Arun Isaac 2020-03-24 01:45:32 +05:30 committed by Ludovic Courtès
parent 5f60eb6bb5
commit b9a09f1ec3

View file

@ -30,9 +30,9 @@ illustration, transforming a music album catalog language into HTML.
@lisp @lisp
(define (album->html x) (define (album->html x)
(sxml-match x (sxml-match x
[(album (@@ (title ,t)) (catalog (num ,n) (fmt ,f)) ...) ((album (@@ (title ,t)) (catalog (num ,n) (fmt ,f)) ...)
`(ul (li ,t) `(ul (li ,t)
(li (b ,n) (i ,f)) ...)])) (li (b ,n) (i ,f)) ...))))
@end lisp @end lisp
Three macros are provided: @code{sxml-match}, @code{sxml-match-let}, and Three macros are provided: @code{sxml-match}, @code{sxml-match-let}, and
@ -138,8 +138,8 @@ The example below illustrates the pattern matching of an XML element:
@lisp @lisp
(sxml-match '(e (@@ (i 1)) 3 4 5) (sxml-match '(e (@@ (i 1)) 3 4 5)
[(e (@@ (i ,d)) ,a ,b ,c) (list d a b c)] ((e (@@ (i ,d)) ,a ,b ,c) (list d a b c))
[,otherwise #f]) (,otherwise #f))
@end lisp @end lisp
Each clause in @code{sxml-match} contains two parts: a pattern and one or more Each clause in @code{sxml-match} contains two parts: a pattern and one or more
@ -165,8 +165,8 @@ where nested ellipses are used to match the children of repeated instances of an
(define x '(d (a 1 2 3) (a 4 5) (a 6 7 8) (a 9 10))) (define x '(d (a 1 2 3) (a 4 5) (a 6 7 8) (a 9 10)))
(sxml-match x (sxml-match x
[(d (a ,b ...) ...) ((d (a ,b ...) ...)
(list (list b ...) ...)]) (list (list b ...) ...)))
@end lisp @end lisp
The above expression returns a value of @code{((1 2 3) (4 5) (6 7 8) (9 10))}. The above expression returns a value of @code{((1 2 3) (4 5) (6 7 8) (9 10))}.
@ -179,8 +179,8 @@ in the example below.
@lisp @lisp
(sxml-match '(e 3 4 5 6 7) (sxml-match '(e 3 4 5 6 7)
[(e ,i ... 6 7) `("start" ,(list 'wrap i) ... "end")] ((e ,i ... 6 7) `("start" ,(list 'wrap i) ... "end"))
[,otherwise #f]) (,otherwise #f))
@end lisp @end lisp
The general pattern is that @code{`(something ,i ...)} is rewritten as The general pattern is that @code{`(something ,i ...)} is rewritten as
@ -193,8 +193,8 @@ identifier list. The example below illustrates matching a nodeset.
@lisp @lisp
(sxml-match '("i" "j" "k" "l" "m") (sxml-match '("i" "j" "k" "l" "m")
[(list ,a ,b ,c ,d ,e) ((list ,a ,b ,c ,d ,e)
`((p ,a) (p ,b) (p ,c) (p ,d) (p ,e))]) `((p ,a) (p ,b) (p ,c) (p ,d) (p ,e))))
@end lisp @end lisp
This example wraps each nodeset item in an HTML paragraph element. This example This example wraps each nodeset item in an HTML paragraph element. This example
@ -202,8 +202,8 @@ can be rewritten and simplified through using ellipsis:
@lisp @lisp
(sxml-match '("i" "j" "k" "l" "m") (sxml-match '("i" "j" "k" "l" "m")
[(list ,i ...) ((list ,i ...)
`((p ,i) ...)]) `((p ,i) ...)))
@end lisp @end lisp
This version will match nodesets of any length, and wrap each item in the This version will match nodesets of any length, and wrap each item in the
@ -218,8 +218,8 @@ This is illustrated in the example below:
@lisp @lisp
(sxml-match '(e 3 (f 4 5 6) 7) (sxml-match '(e 3 (f 4 5 6) 7)
[(e ,a (f . ,y) ,d) ((e ,a (f . ,y) ,d)
(list a y d)]) (list a y d)))
@end lisp @end lisp
The above expression returns @code{(3 (4 5 6) 7)}. The above expression returns @code{(3 (4 5 6) 7)}.
@ -233,8 +233,8 @@ illustrated in the example below:
@lisp @lisp
(sxml-match '(a (@@ (z 1) (y 2) (x 3)) 4 5 6) (sxml-match '(a (@@ (z 1) (y 2) (x 3)) 4 5 6)
[(a (@@ (y ,www) . ,qqq) ,t ,u ,v) ((a (@@ (y ,www) . ,qqq) ,t ,u ,v)
(list www qqq t u v)]) (list www qqq t u v)))
@end lisp @end lisp
The above expression matches the attribute @code{y} and binds a list of the The above expression matches the attribute @code{y} and binds a list of the
@ -245,8 +245,8 @@ This type of pattern also allows the binding of all attributes:
@lisp @lisp
(sxml-match '(a (@@ (z 1) (y 2) (x 3))) (sxml-match '(a (@@ (z 1) (y 2) (x 3)))
[(a (@@ . ,qqq)) ((a (@@ . ,qqq))
qqq]) qqq))
@end lisp @end lisp
@unnumberedsubsec Default Values in Attribute Patterns @unnumberedsubsec Default Values in Attribute Patterns
@ -257,7 +257,7 @@ the following example:
@lisp @lisp
(sxml-match '(e 3 4 5) (sxml-match '(e 3 4 5)
[(e (@@ (z (,d 1))) ,a ,b ,c) (list d a b c)]) ((e (@@ (z (,d 1))) ,a ,b ,c) (list d a b c)))
@end lisp @end lisp
The value @code{1} is used when the attribute @code{z} is absent from the The value @code{1} is used when the attribute @code{z} is absent from the
@ -289,35 +289,35 @@ basic arithmetic operations, which are represented by the XML elements
(define simple-eval (define simple-eval
(lambda (x) (lambda (x)
(sxml-match x (sxml-match x
[,i (guard (integer? i)) i] (,i (guard (integer? i)) i)
[(plus ,x ,y) (+ (simple-eval x) (simple-eval y))] ((plus ,x ,y) (+ (simple-eval x) (simple-eval y)))
[(times ,x ,y) (* (simple-eval x) (simple-eval y))] ((times ,x ,y) (* (simple-eval x) (simple-eval y)))
[(minus ,x ,y) (- (simple-eval x) (simple-eval y))] ((minus ,x ,y) (- (simple-eval x) (simple-eval y)))
[(div ,x ,y) (/ (simple-eval x) (simple-eval y))] ((div ,x ,y) (/ (simple-eval x) (simple-eval y)))
[,otherwise (error "simple-eval: invalid expression" x)]))) (,otherwise (error "simple-eval: invalid expression" x)))))
@end lisp @end lisp
Using the catamorphism feature of @code{sxml-match}, a more concise version of Using the catamorphism feature of @code{sxml-match}, a more concise version of
@code{simple-eval} can be written. The pattern @code{,[x]} recursively invokes @code{simple-eval} can be written. The pattern @code{,(x)} recursively invokes
the pattern matcher on the value bound in this position. the pattern matcher on the value bound in this position.
@lisp @lisp
(define simple-eval (define simple-eval
(lambda (x) (lambda (x)
(sxml-match x (sxml-match x
[,i (guard (integer? i)) i] (,i (guard (integer? i)) i)
[(plus ,[x] ,[y]) (+ x y)] ((plus ,(x) ,(y)) (+ x y))
[(times ,[x] ,[y]) (* x y)] ((times ,(x) ,(y)) (* x y))
[(minus ,[x] ,[y]) (- x y)] ((minus ,(x) ,(y)) (- x y))
[(div ,[x] ,[y]) (/ x y)] ((div ,(x) ,(y)) (/ x y))
[,otherwise (error "simple-eval: invalid expression" x)]))) (,otherwise (error "simple-eval: invalid expression" x)))))
@end lisp @end lisp
@unnumberedsubsec Named-Catamorphisms @unnumberedsubsec Named-Catamorphisms
It is also possible to explicitly name the operator in the ``cata'' position. It is also possible to explicitly name the operator in the ``cata'' position.
Where @code{,[id*]} recurs to the top of the current @code{sxml-match}, Where @code{,(id*)} recurs to the top of the current @code{sxml-match},
@code{,[cata -> id*]} recurs to @code{cata}. @code{cata} must evaluate to a @code{,(cata -> id*)} recurs to @code{cata}. @code{cata} must evaluate to a
procedure which takes one argument, and returns as many values as there are procedure which takes one argument, and returns as many values as there are
identifiers following @code{->}. identifiers following @code{->}.
@ -329,29 +329,29 @@ transformation that formats a ``TV Guide'' into HTML.
(define (tv-guide->html g) (define (tv-guide->html g)
(define (cast-list cl) (define (cast-list cl)
(sxml-match cl (sxml-match cl
[(CastList (CastMember (Character (Name ,ch)) (Actor (Name ,a))) ...) ((CastList (CastMember (Character (Name ,ch)) (Actor (Name ,a))) ...)
`(div (ul (li ,ch ": " ,a) ...))])) `(div (ul (li ,ch ": " ,a) ...)))))
(define (prog p) (define (prog p)
(sxml-match p (sxml-match p
[(Program (Start ,start-time) (Duration ,dur) (Series ,series-title) ((Program (Start ,start-time) (Duration ,dur) (Series ,series-title)
(Description ,desc ...)) (Description ,desc ...))
`(div (p ,start-time `(div (p ,start-time
(br) ,series-title (br) ,series-title
(br) ,desc ...))] (br) ,desc ...)))
[(Program (Start ,start-time) (Duration ,dur) (Series ,series-title) ((Program (Start ,start-time) (Duration ,dur) (Series ,series-title)
(Description ,desc ...) (Description ,desc ...)
,[cast-list -> cl]) ,(cast-list -> cl))
`(div (p ,start-time `(div (p ,start-time
(br) ,series-title (br) ,series-title
(br) ,desc ...) (br) ,desc ...)
,cl)])) ,cl))))
(sxml-match g (sxml-match g
[(TVGuide (@@ (start ,start-date) ((TVGuide (@@ (start ,start-date)
(end ,end-date)) (end ,end-date))
(Channel (Name ,nm) ,[prog -> p] ...) ...) (Channel (Name ,nm) ,(prog -> p) ...) ...)
`(html (head (title "TV Guide")) `(html (head (title "TV Guide"))
(body (h1 "TV Guide") (body (h1 "TV Guide")
(div (h2 ,nm) ,p ...) ...))])) (div (h2 ,nm) ,p ...) ...)))))
@end lisp @end lisp
@unnumberedsubsec @code{sxml-match-let} and @code{sxml-match-let*} @unnumberedsubsec @code{sxml-match-let} and @code{sxml-match-let*}
@ -365,7 +365,7 @@ an XML pattern in the binding position, rather than a simple variable.
For example, the expression below: For example, the expression below:
@lisp @lisp
(sxml-match-let ([(a ,i ,j) '(a 1 2)]) (sxml-match-let (((a ,i ,j) '(a 1 2)))
(+ i j)) (+ i j))
@end lisp @end lisp