![]() |
![]() OCAU News - Wiki - QuickLinks - Pix - Sponsors |
|
|||||||
| Notices |
|
Sign up for a free OCAU account and this ad will go away! Search our forums with Google: |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Imperator Augustus
Join Date: Jun 2001
Location: Holy Roman Empire
Posts: 2,642
|
Code:
x(a). x(b). x(c). y([]). y([H|T]):-y(T),x(H). Q2: what happens after entering Code:
?- y(X). Code:
x(a). x(b). x(c). y([]). y([H|T]):-x(H),y(T). |
|
|
|
| Join OCAU to remove this ad! |
|
|
#2 |
|
(Banned or Deleted)
Join Date: Sep 2001
Location: dots in the location field break it. note
Posts: 2,034
|
looks like prolog
|
|
|
|
|
|
#3 | ||
|
Member
Join Date: Jun 2001
Location: Adelaide
Posts: 2,377
|
Quote:
2) It will evaluate every element in the "list" X for x(a), x(b) and x(c), making sure each element is either a, b or c. If one of the elements is not it return "False". It will check them in reverse order and there will be the length of X many calls to Y. Quote:
NB: Its been a while since Ive done prolog so Im not sure if the terminology is right, or even the answer.
__________________
"That's the way good software gets designed. So if you pull out a piece it won't run" - Steve Ballmer |
||
|
|
|
|
|
#4 |
|
Imperator Augustus
Join Date: Jun 2001
Location: Holy Roman Empire
Posts: 2,642
|
Hey, you are all right, it is Prolog. Geo, you are sort of re-describing the code in English. Perhaps I should have asked more precisely: what is the output - in simple terms? Whilst logically equivalent, there is a definite difference between the two versions...
|
|
|
|
|
|
#5 |
|
Member
Join Date: Jun 2001
Location: Adelaide
Posts: 2,377
|
heh, I cant even remember what prolog has as output.
![]() Isn't the main difference that the first one checks the list in reverse order and the second one checks it in 'forwards' order?
__________________
"That's the way good software gets designed. So if you pull out a piece it won't run" - Steve Ballmer |
|
|
|
|
|
#6 |
|
Member
Join Date: Jun 2001
Location: Hobart
Posts: 1,242
|
Prolog is confusing, though not nearly as confusing as other similar languages.
J, anyone? |
|
|
|
|
|
#7 |
|
Imperator Augustus
Join Date: Jun 2001
Location: Holy Roman Empire
Posts: 2,642
|
OK then. I will describe the output only. That way there should be an incentive left for those who are willing to learn more about the semantics of prolog and the backtracking mechanism.
In fact, prolog is usually explained using two different semantics. In the logical semantic, the comma operator represent the logical "and", which makes both programs above equivalent. In everyday's language, the programs say: "The letters (atoms) a, b and c have the property x" "The empty list has the property y" "A list has property y, if the first element (the head) has property x, and the remaining list (the tail) has propert y. the query says: "does the variable X have property y?" prolog will now go and find "solutions" for X that satisfy the query. Obviously in a logical sense all lists (all finite strings) containing a,b and c fulfill the query. Indeed the first program produces: Code:
X = [] ; X = [a] ; X = [b] ; X = [c] ; X = [a, a] ; X = [b, a] ; X = [c, a] ; X = [a, b] ; X = [b, b] ; X = [c, b] ; X = [a, c] ; X = [b, c] ; X = [c, c] ; X = [a, a, a] ; X = [b, a, a] Code:
X = [] ; X = [a] ; X = [a, a] ; X = [a, a, a] ; X = [a, a, a, a] ; X = [a, a, a, a, a] ; X = [a, a, a, a, a, a] ; X = [a, a, a, a, a, a, a] ; X = [a, a, a, a, a, a, a, a] ; X = [a, a, a, a, a, a, a, a, a] ; Right, no winner for the first price this time... I'll keep the slab.
|
|
|
|
|
|
#8 |
|
Member
Join Date: Feb 2002
Location: Brisbane
Posts: 511
|
What is the user of ProLog, is it an Array driven language or something. I being a 16 yo I have never head of it.
|
|
|
|
|
|
#9 |
|
Imperator Augustus
Join Date: Jun 2001
Location: Holy Roman Empire
Posts: 2,642
|
prolog stands for programming in logic. essentially you describe the problem and the prolog interpreter finds the solution(s) for you. there's more info on google.
|
|
|
|
![]() |
| Bookmarks |
|
Sign up for a free OCAU account and this ad will go away! |
| Thread Tools | |
|
|