Fandom

Distributed Interactive Functional Fiction Programming

Difference of two lists

13pages on
this wiki
Add New Page
Talk0 Share

Main_Page/Snack Code/List Recursion/Difference of two lists

Difference of two lists: xs \\ ys is the list xs with each element of ys removed from xs, if its present in ys.

Haskell:

module Sublist where

(\\) xs [] = xs
(\\) [] xs = []
(\\) ls (y:ys) = (remove ls y) \\ ys
    where
    remove [] y = []
    remove (x:xs) y
           | x == y = remove xs y
           | otherwise = x : remove xs y


test = [1,2,3,4,5] \\ [2,4]
{--
*Sublist> test
[1,3,5]
*Sublist>
--}

Scheme:






Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.