-->

Visual Prolog Program to delete a given element from the list.

Visual Prolog Program to delete a given element from the list.

    To delete a element from a list the position and the element list is passed to the predicate delete. Then the delete predicate continuously breaks the list into head (H) and Tail (T) to find that the correct position is reached. On reaching the appropriate position to delete the element the predicate slices the head off the list and finally merges the remaining art with the rest. The prolog code is given as below:

    DOMAINS
    int_list = integer*

    PREDICATES
    del(integer, int_list, int_list)

    CLAUSES
    del(0,[H|T], T).
    del(P,[H|T], [H|Z]):-
    P1 = P - 1, del(P1,T,Z).

    GOAL
    del(2, [0,1,2,3,4,5],X).

    fardi zayden
    @مرسلة بواسطة
    كاتب ومحرر اخبار اعمل في موقع دراسات تقنية .

    إرسال تعليق