On 03/09/2012 06:37 PM, rob cook wrote:
That is, without using a macro or eval. Id like to do:

(define a 4)
(define l1 '(1 2 3))
(match l1
   (`(1 2 ,a) #t)
   (_ #f))

So that this example would result in #f, and #t if a bound to 3.

Since of course match has its own quasiquote behavior, this does not
seem possible w/o making a macro for "dynamic" match, or building the
s-exp and using eval (yuck!).

Is this correct, or have I missed something obvious?

It looks like what you're trying to do is to match a particular value which just so happens to be built using a quasiquote expression. The right way to do it is with the == match expander:

(define a 4)
(define l1 '(1 2 3))
(match l1
  ((== `(1 2 ,a)) #t)
  (_ #f)) ; -> #f

You can also put any other expression there:

(match l1
  ((== (append (take l1 2) (list (sub1 a)))) #t)
  (_ #f)) ;-> #t

Or use a different comparison predicate:

(match l1
  ((== `(1 2 ,(sub1 a)) eq?) #t)
  (_ #f)) ; -> #f

Hope that helps!

--
Brian Mastenbrook
br...@mastenbrook.net
http://brian.mastenbrook.net/

____________________
 Racket Users list:
 http://lists.racket-lang.org/users

Reply via email to