newLISP Fan Club

Forum => Anything else we might add? => Topic started by: cormullion on February 15, 2008, 09:51:40 AM

Title: More set-ref-all and match questions
Post by: cormullion on February 15, 2008, 09:51:40 AM
I'm still struggling to master match and set-ref-all.


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

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


Is this sort of search possible?
Title:
Post by: Lutz on February 18, 2008, 07:58:02 AM
Your match expression


'(* ("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:


'("b" *)

and that would produce:


(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
Title:
Post by: cormullion on February 18, 2008, 09:54:17 AM
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!