Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Merge 2 lists into one in racket

Tags:

scheme

racket

I have 2 dynamic lists that I would like to merge into one.

Say

'(1 2 3 4)

and

'(15 16)

and get

'(1 2 3 4 15 16)

How can this be done?

like image 414
user2175783 Avatar asked Feb 10 '15 19:02

user2175783


People also ask

How do you add two lists together?

The append function joins two lists together to make one. The append function is built into Scheme. It concatenates two lists, that is to say, given two lists list1 and list2 it produces a new list which starts with the same elements as list1 and finishes with those of list2 .

What is pair in Racket?

Pairs and Lists in The Racket Guide introduces pairs and lists. A pair combines exactly two values. The first value is accessed with the car procedure, and the second value is accessed with the cdr procedure. Pairs are not mutable (but see Mutable Pairs and Lists).


1 Answers

Use append for this:

(append '(1 2 3 4) '(15 16))
=> '(1 2 3 4 15 16)
like image 74
Óscar López Avatar answered Nov 03 '22 06:11

Óscar López