Comparisment

   - compare programming languages by example

40

List append

Append two lists together into a single list.

Created by sam

Add a new answer

Either add an answer for a new language or add an alternative solution.
A description is only necessary when the code is not suitably 'obvious' or to justify an alternative approach.

Haskell

app :: [Char]
app = ['a','p','p']

end :: [Char]
end = ['e','n','d']

append :: [Char]
append = app ++ end

'++' is the append operator on two lists.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Haskell

import Data.Monoid

app :: [Char]
app = ['a','p','p']

end :: [Char]
end = ['e','n','d']

append :: [Char]
append = app <> end

Lists are instances of 'Monoid' and can be appended with 'mappend' or its infix operator '<>'.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.

Python

app = ['a','p','p']
end = ['e','n','d']
append = app + end

'+ is the append operator.

Created by: sam

Edit this answer

Edit the language, code and description simultaneously.