View Full Version : Prolog, anyone else use it?
djr33
01-19-2009, 03:09 AM
Just wondering in general if anyone here has experience with Prolog, or any other language like it. It's a declarative language, based in logic.
As far as I can tell, it's basic function is to generate based on rules then answer based on matching to what has been generated-- something like brute force. It's in theory efficient (at least some say it is), but I have my doubts, and it does things like get into endless loops quite easily.
I'm using it for a linguistics course, trying to model language.
Here's an example of the syntax:
word([joe],[noun]).
word([jim],[noun]).
word([thinks],[verb]).
word([sleeps],[verb]).
sentence(S) :-
word(N,[noun]),
word(V,[verb]),
concatenation(N,V,S).
concatenation([],List,List).
concatenation([Head|List1],List2,[Head|List3]) :-
concatenation(List1,List2,List3).
That takes the information, setting up the words. Then it sets up a sentence if it meets the conditions that the two words are a noun then a verb and the two words make up a list to form the sentence. (Concatenation is a function written for the purpose of checking whether two components add up to a certain list-- sorta like an array.)
It works entirely from the command line, and it would then output basic sentences like "jim sleeps," though as a "list" (with commas and such), rather than a properly formatted string.
Here's the wikipedia information:
http://en.wikipedia.org/wiki/Prolog
Yes, I've played with it. It's very good for a certain class of problems, but seems a bit roundabout for others. Logic programming is, based on my little experience, best when embedded into a more general-purpose language (yes, I know Prolog is general-purpose, but it's not happy about it).
Schmoopy
01-19-2009, 04:27 PM
Yea, we have to do a bit of Prolog programming in A level computing, I personally dislike it, it's more for academics I think.
I don't know how you define 'for academics'. It's ideal in quite a few real-life situations, but it makes others awkward enough to not be worth it (in my opinion).
Why did you not like it?
Schmoopy
01-19-2009, 08:30 PM
I mean, when you compare it to other languages it's very limited in what it can do and there's not that much demand for it. I also don't like it because it's different to other languages which share common syntaxes, meaning you have to completely change how you write it, but then I guess it is a logic programming language, so it's not going to be like others.
I mean, when you compare it to other languages it's very limited in what it can doHmm... it's Turing-complete, so it can do anything another Turing-complete language can do.
I also don't like it because it's different to other languages which share common syntaxes, meaning you have to completely change how you write it'It doesn't look like C' isn't a very good criticism :p It looks quite similar to Erlang!
djr33
01-22-2009, 11:08 PM
I agree about the academic idea. My professor uses it but no other languages-- he likes it because it is easy and accessible for the sort of problem he does.
It is very limited, despite it theoretically being general purpose.
What sort of implementation do you know of for it? Using it within a real language sounds like it might be very helpful.
For some problems, it's unbeatable in simplicity, but overall it is limited and I think very unintuitive in its process-- things like endless loops are not hard to avoid if it had any sense (trying to match an 8 word string to another string would never get to a 100 word string in the middle, so it should realize it needs to exit that loop.)
It is very limited, despite it theoretically being general purpose.It is no more limited than any other Turing-complete language: speaking in terms of inputs and outputs, one can do anything with Prolog that one can do with, say, Python, or Java. The only difference is the method in which the inputs are transformed to outputs within the program, and on that score it could even be described as more powerful than Java. What it is, however, is specialized to a particular class of problems. This doesn't limit it to those problems — there are, for example, GUI libraries (http://www.swi-prolog.org/packages/xpce/) for Prolog — but it could be considered to make it less elegant for problems outside its domain. Your statement:
It works entirely from the command line, and it would then output basic sentences like "jim sleeps," though as a "list" (with commas and such), rather than a properly formatted string.... is entirely wrong, and doesn't even entirely make sense: in a Turing-complete language, the default output format does not have much to do with anything. It's somewhat like doing print([1, 2, 3, 4, 5]) and then declaring that Javascript is only capable of outputting to the command line, and only in its own syntax. Of course it is possible to format the output as one likes, and to bind to other methods of output. The language would hardly be Turing-complete, and thereby deserve the title of programming language, were it not.
djr33
01-23-2009, 01:54 AM
The implementation we're using in my class is entirely command line and it seems the basic nature of the language is to use it in this fashion: facts and conditions entered in the code then queries used in interaction to produce results, nothing more.
Anything else isn't part of the original implementation of prolog. Other implementations may have other features, but not the original idea/base for all current versions.
What I meant about the list issue is that it doesn't have, from my limited exposure, any easy way (within itself, at least, maybe there are within embedded commands of a non-native sort) to deal with the strings aside from making a list. In another language, string functions are easy and readily available, like capitalization and punctuation.
The implementation we're using in my class is entirely command line ... Anything else isn't part of the original implementation of prolog. Other implementations may have other features, but not the original idea/base for all current versions.By which you mean to say that it doesn't have a GUI library included in the standard libraries, a claim which could also be applied to C or C++.
What I meant about the list issue is that it doesn't have, from my limited exposure, any easy way (within itself, at least, maybe there are within embedded commands of a non-native sort) to deal with the strings aside from making a list. In another language, string functions are easy and readily available, like capitalization and punctuation.Your exposure is indeed limited. String support (http://www.cs.mu.oz.au/303/Manual/strings.html) exists in just about any Prolog implementation used in the real world. You will note the string_to_list/2 function, which can be used to convert a string into a list: after this, Prolog's substantial list-handling features can be used to implement any operation desired on the string. It's maybe not as direct as the string manipulation in other languages (although there are a number of third-party string libraries that implement all the string functions found in other languages, a fairly trivial task), but nevertheless it is available. The indirectness is a symptom of what I was describing earlier: string handling is not Prolog's primary problem domain.
djr33
01-23-2009, 01:32 PM
By which you mean to say that it doesn't have a GUI library included in the standard libraries, a claim which could also be applied to C or C++.No. I have not yet seen a way to do ANYTHING in terms of functional programming, beyond just setting up condition. However, we haven't done much yet... it's just that my entire impression of the program is outside any of the useful and common methods that get things done so easily. It's an adjustment, though perhaps just as formidable as any other with some of what I haven't seen yet used.
I'll certainly be looking into it more. As of yet, it's just been casual investigation and whatever is on the introductory assignments.
No. I have not yet seen a way to do ANYTHING in terms of functional programming, beyond just setting up condition.That doesn't mean that it doesn't exist :) You should also note that logic programming is not the same as functional programming, although they are a bit closer to each other than either to imperative programming.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.