0
votes

I have a problem with Racket (Scheme) and the procedure "Eval".

To check "eval" in Dr.Racket, we can type in the interpreter, e.g.,

(eval '(+ 5 2))

If we work with lists, we can have,

(eval '(append '(a) '(b)))

That returns,

'(a b)

Until here all is fine, but I want to do something like:

(define x_list '(append a))
(define y_list '(b c))

(eval (list (car x_list) (cdr x_list) (list (car y_list)))) 

That obviously doesn't work, because there are not quotes in front of the lists, i.e. what is doing is,

(eval '(append (a) (b)))

My question is, there is any way to put the quotes in front of the lists to make this working??

(eval (list (car x_list) (cdr x_list) (list (car y_list))))
1
I'll chime in with the usual caution that eval is usually the wrong thing to use. See this blog post.Greg Hendershott

1 Answers

1
votes

Try this:

(eval (list (car x_list) `',(cdr x_list) `',(list (car y_list))))
=> '(a b)

The trick was using quasiquoting, check the documentation for more details.