Question

In PROLOG, write a binary predicate fof, short for 'full of full', which will precede each...

In PROLOG, write a binary predicate fof, short for 'full of full', which
will precede each atom in a list by the atom full.
E.g. ?- fof([a,b,c]),L).
L = [full,a,full,b,full,c]
NOTE: only atoms, not numbers or lists or trees.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The required problem can be solved as follows

%to assign one list to another
set(X,X).

%%Leave the empty list as it is
fof([],[]).

%H is first element of old list
%if it is atom find T2 from T1 and append it in front of full,H
%other wise append it in front of H only
fof([H|T1] , L) :-
    (   atom(H)
    -> fof(T1,T2) , set([full,H|T2],L)
    ;   fof(T1,T2) , set([H|T2],L)
    ).

In case of any doubt please comment. Happy Learning :)

Add a comment
Know the answer?
Add Answer to:
In PROLOG, write a binary predicate fof, short for 'full of full', which will precede each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SWI-Prolog a) Write a predicate called lastEle(Atom,List) to find the last element of a list. You...

    SWI-Prolog a) Write a predicate called lastEle(Atom,List) to find the last element of a list. You may not use the built-in last predicate in your answer. E.g., ?- lastEle(X,[how,are,you,today]). X=today. b) Write a predicate gradeMap(L,R), where L is a list of percentage grade values (integers from 0 to 100), and R is a list of corresponding grade letters (a-f, no +/-'s). You may assume the grade list contains the correct types. E.g., ?-gradeMap([0, 16, 49, 55, 63, 78, 92], R)....

  • Prolog questions. Thanks! Write a predicate that removes consecutive duplicate elements from a list. ?- remove_consecutive_duplicates...

    Prolog questions. Thanks! Write a predicate that removes consecutive duplicate elements from a list. ?- remove_consecutive_duplicates ([a, a, b, c, c, a, a, a, e, d, d, a, c], L). L = [a, b, c,,a, e, d, a, c].

  • ///Program needs to write in prolog/// 6. A binary tree is either empty or it is...

    ///Program needs to write in prolog/// 6. A binary tree is either empty or it is composed of a root element and two successors, which are binary trees themselves. In Prolog we represent the empty tree by the atom 'nil' and the non-empty tree by the term t(X,L,R), where X denotes the root node and L and R denote the left and right subtree, respectively. The following Prolog term represents the given binary tree below. T1 = t(a,t(b,t(d,nil,nil),t(e,nil,nil)),t(c,nil,t(f,t(g,nil, nil),nil))) d...

  • Question 3 (13] (a) Write a procedure filter (L,PredName, L1,L2) that accepts a list L and...

    Question 3 (13] (a) Write a procedure filter (L,PredName, L1,L2) that accepts a list L and returns two lists Li and L2, where Li contains all elements in L for which PredName (x) fails, and L2 contains all elements in L for which PredName (x) succeeds. The predicate PredName/1 should be defined when calling the procedure filter. For example: let test be defined as test(N).- N > 0. 7- filter((-6,7,-1,0),test,L1,L2). L1 - (-6.-1) L2 - [7, 0] NB Use the...

  • THIS IS A PROLOG QUESTION: Write a Prolog rule to repeat each element of the list...

    THIS IS A PROLOG QUESTION: Write a Prolog rule to repeat each element of the list TWO times. Hint: You should use recursion. For example, repeat_elements([a,b,c], Result) should return Result as [a,a,b,b,c,c] The result of repeating an empty list [] is an empty list [] so your base case should be the following: repeat_elements([], []). % This is the base case Once you complete your rule by adding recursion rule to the base case, you should test it by a...

  • Write a C# program to generate 2 Lists of random 5 elements each containing only binary...

    Write a C# program to generate 2 Lists of random 5 elements each containing only binary numbers like 1 or 0 only such that there is only one 1 in the list in any random position and the rest four elements are zeroes. Create another list of 3 elements and such that there are random 1s or 0s. And concatenate these 3 Lists together to produce "one List" named "datablock".

  • Write a C# program to generate Lists of random 5 elements each containing only binary numbers...

    Write a C# program to generate Lists of random 5 elements each containing only binary numbers like 1 or 0 only such that there is only one 1 in the list in any random position and the rest four elements are zeroes. . For eg: (10000) or (01000) or (00100) or (00010) or (00001).

  • 1. An integer is said to be perfect if the sum of its factors, including 1,...

    1. An integer is said to be perfect if the sum of its factors, including 1, is equal to the number itself. Write a Prolog predicate perfect(N, F), which determines if integer N is perfect and if so, return it’s list of factors F. If N is not perfect, the predicate fails. You may find the arithmetic operation M mod N to be useful. Test your predicate on the following. • perfect(6, Factors) ⇒ Factors = [1, 2, 3] •...

  • (10 points) Recall that the set of full binary trees is defined as follows: Basis: A...

    (10 points) Recall that the set of full binary trees is defined as follows: Basis: A single vertex with no edges is a full binary tree. The root is the only vertex in the tree. Recursive rule: If T1 and T2 are full binary trees, then a new tree T' can be constructed by first placing T1 to the left of T2, adding a new vertex v at the top and then adding an edge between v and the root...

  • 3. Write a full set of quantum numbers for each of the following: a. The outermost...

    3. Write a full set of quantum numbers for each of the following: a. The outermost electron in an Li atom b. The electron gained when a Br atom becomes a Brion. C. The electron lost when a Cs atom ionizes (Cs) d. The highest energy electron in the ground-state B aton 3. Write a full set of quantum numbers for each of the following: a. The outermost electron in an Li atom b. The electron gained when a Br...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT