Welcome to W3Courses

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) ))))

0

Cartesian Product Using Scheme Source Code

Cartesian product code

3.5
Average: 3.5 (2 votes)

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)) ))))

1
Average: 1 (1 vote)

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)))

 

0

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)))))))

1.5
Average: 1.5 (2 votes)

Delete the Third Occurrence of an Element from a List Using Scheme Source Code

The following code deletes the third occurrence of an element from a list

1
Average: 1 (1 vote)

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!

3
Average: 3 (1 vote)

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!

0

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))))

3.5
Average: 3.5 (2 votes)

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))))

4.5
Average: 4.5 (2 votes)