How to get the first, middle and last element of a list scheme and prolog?
问题 I am trying to write a function in Scheme and Prolog that returns first, middle and last item of a list. E.g., find([4,5,8,7,9],L), L = [4,8,9] . I came up with this piece of code for Scheme language, but I am new to Prolog and don't know much, so how I can get the same result in Prolog? (define (frst L) (car L)) (define (last L) (if (null? (cdr L)) (car L) (last (cdr L)))) (define (nth L x) (if (= x 1) (car L) (nth (cdr L) (- x 1)))) (define (firstMidLast L) (list (frst L) (nth L (ceiling (/