04-07-2009
|
#3
|
[KAPLAN]
|
Cevap : Prolog Örnekleri | Prolog Examples
Lecture 6
Program 6 1 - classifying a list into vowels and consonants
/* ************************************************ */
/* */
/* vowel/1 */
/* Summary: True if Arg1 is a vowel */
/* Arg 1: Letter */
/* Author: P J Hancox */
/* Date: 30 October 2002 */
/* */
/* ************************************************ */
vowel(a)
vowel(e)
vowel(i)
vowel(o)
vowel(u)
/* ************************************************ */
/* */
/* classify/3 */
/* Summary: Classifies a list of letters into two */
/* lists: vowels and consonants */
/* Arg 1: List of letters */
/* Arg 2: List of vowels */
/* Arg 3: List of consonants */
/* Author: P J Hancox */
/* Date: 30 October 2002 */
/* */
/* ************************************************ */
% 1 - terminating
classify([], [], [])
% 2 - recursive: letter is a vowel
classify([Vowel|Tail], [Vowel|Vowel_Tail], Non_Vowels) :-
vowel(Vowel),
classify(Tail, Vowel_Tail, Non_Vowels)
% 3 - recursive: letter is a consonant
classify([Non_Vowel|Tail], Vowels, [Non_Vowel|Non_Vowel_Tail]) :-
classify(Tail, Vowels, Non_Vowel_Tail)
Program 6 2 - buggy version of member/2 to show singleton variables
<div align="left"> /* ************************************************ */
/* */
/* member/2 */
/* Summary: True if Arg1 occurs in Arg2 */
/* Arg 1: Term */
/* Arg 2: List */
/* Author: P J Hancox */
/* Date: 30 October 2002 */
/* */
/* ************************************************ */
% 1 - terminating
member(Head, [Heda|_])
% 2 - recursive
member(Elem, [_|Tail]) :-
member(Elem, Tail)
|
|
|