Dr.Napudo
Dr.Napudo

Reputation: 3

Racket (Scheme) with quotes inside lists

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))))

Upvotes: 0

Views: 452

Answers (1)

Óscar López
Óscar López

Reputation: 236004

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.

Upvotes: 1

Related Questions