(def null?
(fn [a]
(or
(nil? a)
(= () a))))
(def member?
(fn [a lat]
(cond
(null? lat) false
true (or
(= (first lat) a)
(member? a (rest lat)))) ))
(println "")
(println "member?")
(println (member? 'sweet '(potato wedges with sweet chilli sauce))) ; //=> true
(println (member? 'sweet '(potato wedges with sweet sweet chilli sauce))) ; //=> true
(def rember
(fn [ a lat]
(cond
(null? lat) '()
true (cond
(= (first lat) a) (rest lat)
true (cons (first lat)
(rember
a (rest lat)))))))
(println "")
(println "rember")
(println (rember 'banana '(apple banana orange))) ; //=> (apple orange)
(println (rember 'banana '(apple banana banana orange))); //=> (apple banana orange)
(def multirember
(fn [a lat]
(cond
(null? lat) '()
true (cond
(= (first lat) a) (multirember a (rest lat))
true (cons (first lat) (multirember a (rest lat)))))))
(println "")
(println "multirember")
(println (multirember 'sweet '(potato wedges with sweet sweet chilli sauce))); //=> (potato wedges with chilli sauce)
(def multiinsertR
(fn [new old lat]
(cond
(null? lat) '()
true (cond
(= (first lat) old) (cons (first lat) (cons new (multiinsertR new old (rest lat))))
true (cons (first lat) (multiinsertR new old (rest lat)))))))
(println "")
(println "multiInsertR")
(println (multiinsertR 'hot 'with '(with potato wedges with chilli sauce))); //=> (with hot potato wedges with hot chilli sauce)
(def multiinsertL
(fn [new old lat]
(cond
(null? lat) '()
true (cond
(= (first lat) old) (cons new (cons old (multiinsertL new old (rest lat))))
true (cons (first lat) (multiinsertL new old (rest lat)))))))
(println "")
(println "multiinsertL")
(println (multiinsertL 'with 'hot '(hot potato wedges hot chilli sauce))); //=> (with hot potato wedges with hot chilli sauce)
(def multisubst
(fn [new old lat]
(cond
(null? lat) '()
true (cond
(= (first lat) old) (cons new (multisubst new old (rest lat)))
true (cons (first lat) (multisubst new old (rest lat)))))))
(println "")
(println "multisubst")
(println (multisubst 'hot 'sweet '(sweet potato wedges with sweet chilli sauce))); //=> (hot potato wedges with hot chilli sauce)
(def add1
(fn [n]
(+ 1 n)))
(def occur
(fn [a lat]
(cond
(null? lat) 0
true (cond
(= (first lat) a) (add1 (occur a (rest lat)))
true (occur a (rest lat))))))
(println "")
(println "occur")
(println (occur 'hot '(potato wedges with hot hot hot chilli sauce))); //=> 3
(def one?
(fn [n]
(= n 1)))
(def sub1
(fn [n]
(- n 1)))
(def rempick
(fn [n lat]
(cond
(null? lat) '()
(one? n) (rest lat)
true (cons (first lat) (rempick (sub1 n) (rest lat))))))
(println "")
(println "rempick")
(println (rempick 4 '(potato wedges with hot chilli sauce))); //=> (potato wedges with chilli sauce)