Welcome to W3Courses
 Like Us on Facebook

Two Lists

Appends Two Lists using Prolog Source Code

The following code appends two lists

CODE
append([],Y,Y).
append([X|T],Y,[X|R]) :- append(X,Y,R).

RESULT
?- append([a],[b,c],R).
R = [a, b, c]
Yes
 

Share

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

Share

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

Share