10-prolog-part3 - CSE 452: Programming Languages Logical...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSE 452: Programming Languages Logical Programming Languages Part 3 2 Organization of Programming Languages Acknowledgements ? P. Tan ? http://www.csupomona.edu/~jrfisher/www/prolog_tut orial/contents.html ? http://cs.wwc.edu/~cs_dept/KU/PR/Prolog.html ? http://pauillac.inria.fr/~diaz/gnu-prolog/ 3 Organization of Programming Languages Prolog Example ? Delete an element from a list ? deleteElem/3 ( /3 means there are 3 arguments) ? Example: ? deleteElem(4, [2,3,4,5], X) ? X = [2,3,5]. ? deleteElem(6, [2,3,4,5],X) ? X = [2,3,4,5].
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 4 Organization of Programming Languages Delete an Element from a List ? Functor: deleteElem ? Arguments ? Input: ? An element ? List of elements ? Output: ? Result list 5 Organization of Programming Languages Delete an Element from a List ? Base step: ? deleteElem(_, [], []). %% underscore means any symbol ? deleteElem(P,[P|Tail],Tail). ? Recursive step: ? deleteElem(P,[H|Tail],[H|Res]) :- P \= H, deleteElem(P,Tail,Res). 6
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

10-prolog-part3 - CSE 452: Programming Languages Logical...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online