I've started using match and have run into a problem. I want to store the items used for the search in variables and then use these in the match invocation. In the code snippet below, I would have expected both printlns to show the same results. I'm sure that this is something simple, but I'm not seeing it.
(set 'a 1)
(set 'b 2)
(set 'c '(0 1 3 2 4))
(println (match '( * 1 * 2 *) c))
(println (match '( * a * b *) c))
(exit)
Help with match
Looks like a quoting issue (it always throws me off too).
From the newlisp interpreter
> '( * 1 * 2 *)
(* 1 * 2 *)
> '( * a * b *)
(* a * b *)
They evaluate to different things, so it makes sense that match would have different results.
But if you try
> (list '* a '* b '*)
(* 1 * 2 *)
then the symbols a and b will be evaluated, resulting in what I think you're looking for.
There's probably a better way to explain/execute it, but hopefully this helps a little.
From the newlisp interpreter
> '( * 1 * 2 *)
(* 1 * 2 *)
> '( * a * b *)
(* a * b *)
They evaluate to different things, so it makes sense that match would have different results.
But if you try
> (list '* a '* b '*)
(* 1 * 2 *)
then the symbols a and b will be evaluated, resulting in what I think you're looking for.
There's probably a better way to explain/execute it, but hopefully this helps a little.
Last edited by m35 on Fri Mar 23, 2007 6:16 pm, edited 1 time in total.
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
well , I think it's because the a and b are inside a quoted list, so are not being expanded. So you're looking for (* a * b *) and would find it only if c was '(0 a 3 b 4).
You want a fix, I suppose. :-) I'm not sure, but it might involve expand...
Edit: Then again, it might not. As m35 suggests:
I always get a bit confused by those multiplication signs appearing as wild-cards in a quoted list... ;-)
You want a fix, I suppose. :-) I'm not sure, but it might involve expand...
Edit: Then again, it might not. As m35 suggests:
Code: Select all
(println (match (list '* a '* b '*) c))