ln026 - Member Predicate Write a predicate member/2 that...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Member Predicate Write a predicate member/2 that takes a list as its first argument and an element as its second element. This predicate is to return true if the element appears in the list. m e m b e r ( [E |_ ],E ) . m e m b e r ( [_ |T ],E ) :- m e m b e r ( T ,E ) . Interaction Loops Write a program that prompts a user for a list, then reads the list, reverses the elements of the list and then prints out the reversed list to the terminal. It then returns to prompting the user for a new list, etc. interact:nl, write('gimme a list> '), read(X), reverse(X,Y), write('this is the reverse: '), write(Y), nl, . interact A Translation Program Write a program that takes simple English statements and translates them into German. The sentences are given as lists of words. % the dictionary l o o k u p ( l o g i c ,l o g i k) . l o o k u p ( i s ,m a c h t) . l o o k u p ( f u n ,s p a s s) . % the translation procedure translate(,). translate([Word|Sentence ],German):t r a n s l a t e ( S e n t e n c e , G S e n t e n c e) , l o o k u p ( W o r d ,G W o r d) , G e r m a n = [G W o r d| G s e n t e n c e ] . Prolog Final Remarks Prolog has no explicit sequence control, the flow of control is driven by the pattern matching of the heads of the rules against the current (sub)goal statements. This has an effect on how we program - rather than explicit ‘how to’ statements we axiomatize the solution we are looking for, e.g., The length of an empty list is 0 The length of the overall list is the length of the rest of the list plus 1. …rather than defining explicit iterations over record structures. ...
View Full Document

This note was uploaded on 10/03/2011 for the course CSC 301 taught by Professor Hamel during the Spring '08 term at Rhode Island.

Ask a homework question - tutors are online