candiani
candiani

Reputation: 39

Funcall inside Cons Lisp

I just began to play with Lisp and I'm trying to use funcall inside cons.

This is what I'm trying to do:

(cons  '(1 2 3) '(1 (funcall #'rest '(a b)) ))

The result should be:

((1 2 3) 1 (b))

I know this works:

(cons  '(1 2 3) (funcall #'rest '(a b)))

And I tried this already and it didn't work

(cons  '(1 2 3) `,'(1 (funcall #'rest '(a b)) ))
(cons '(1 2 3) '(1 (apply 'rest '(a b))))
(cons '(1 2 3) '(1 `,(apply 'rest '(a b))))

Thanks in advance.

Upvotes: 1

Views: 132

Answers (2)

monoid
monoid

Reputation: 1671

(cons '(1 2 3) `(1 ,(funcall #'rest '(a b))))

Upvotes: 3

piokuc
piokuc

Reputation: 26164

When you quote a list, everything is quoted inside the list, so there is no function call. You can achieve what you want like this:

[1]> (cons  '(1 2 3) (list 1 (funcall #'rest '(a b)) ))
((1 2 3) 1 (B))
[2]> 

Upvotes: 3

Related Questions