Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenation in scheme

Tags:

scheme

I have the following code:

(define rest '(((di (a) (b c)) (sh (b) (e d))) ((al (a) (b)))))
(define first '((di (a) (5)) (sh (b) (3))))

I want to get the following list:

(((di (a) (5)) (sh (b) (3))) ((di (a) (b c)) (sh (b) (e d))) ((al (a) (b)))))

meaning, add the list first, to be the first element in rest.

When I do append, it gives me:

((di (a) (5)) (sh (b) (3)) ((di (a) (b c)) (sh (b) (e d))) ((al (a) (b))))

And any other library function, or function that I try to do, didn't help.

Thank you.

like image 937
Adam Sh Avatar asked Nov 30 '11 08:11

Adam Sh


1 Answers

Append takes two lists and puts them together. Given that you have a first and a rest, you probably want cons. Cons takes an element and prepends it to a list. In this case, the element is first and the list is rest. So you want something like

(cons first rest)
like image 76
Tikhon Jelvis Avatar answered Oct 04 '22 17:10

Tikhon Jelvis