More set-ref-all and match questions

For the Compleat Fan
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

More set-ref-all and match questions

Post by cormullion »

I'm still struggling to master match and set-ref-all.

Code: Select all

(set 'lst '(
 ("a" "1")
 ("b" "2")
 ("c" "3")
))

(set-ref-all (lst '(* ("b" *) *)) (println $0) match)
Is this sort of search possible?

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Your match expression

Code: Select all

'(* ("b" *) *)
would match the whole list, but set-ref-all (and all other ref's) try to find a match starting on each element of lst and then recursing into it. What you probably want as a match expression is:

Code: Select all

'("b" *)
and that would produce:

Code: Select all

(set 'lst '( 
 ("a" "1") 
 ("b" "2") 
 ("c" "3") 
 ("b" 1 2 3)
)) 

(set-ref-all (lst '("b" *)) (println $0) match)
("b" "2")
("b" 1 (2) 3)

; or

(set-ref-all (lst '("b" ?)) (println $0) match)
("b" "2")

(set-ref-all (lst '(*(?)*)) (println $0) match)
("b" 1 (2) 3)
... etc.

Lutz

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

Ah, thanks. I think I"m getting confused by the meaning of '*' in match and regex... '*' matches nothing, but I thought that otherwise it would match only at the beginning. Will study it some more until I get it!

Locked