Scheme
Append Two Lists Using Scheme Source Code
The following code appends two lists
(define (append x y)
(cond((null? x) y)
(else (cons (car x) (append (cdr x) y) ))))
Copy List Using Scheme Source Code
The following code copies a list
(define (copy x)
(cond((null? x) ‘())
(else (cons (car x) (copy(cdr x)) ))))
Cube Function Using Scheme Source Code
The following code finds the cube of a number
(define cube(lambda(x) (* x (* x x))))
or
(define cube(lambda(x) (* x x x)))
Delete all Occurrences of an Element from a List Using Scheme Source Code
The following code deletes all occurrences of an element from a list
CODE
(define deleteall( lambda (x y)
(if (null? y )
()
(if (eqv? (car y) x)
(deleteall x (cdr y))
(cons (car y) (deleteall x (cdr y)))))))
Delete the Nth Occurrence of an Element from a List with Set! Using Scheme Source Code
The following code deletes the Nth occurrence of an element from a List with Set!
Delete the Nth Occurrence of an Element from a List without Set! Using Scheme Source Code
The following code deletes the Nth occurrence of an element from a list without using Set!
Check if two Lists are Equal using Scheme Source Code
The following code checks if two lists are equal
(define equal(lambda (x y)
(cond((and(null? x) (null? y)) #t)
((and(not (null? x)) (not (null? y))) (equal (cdr x) (cdr y)))
(else #f))))
Check if Even or Odd using Scheme Source Code
The following code checks if a number is Even or Odd
CODE
(define (even? n)
(if (eqv? n 0) #t
(odd? (- n 1))))
(define (odd? n)
(if (eqv? n 0) #f
(even? (- n 1))))
