Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Prolog, anyone else use it?

  1. #1
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default Prolog, anyone else use it?

    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:
    Code:
    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
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    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.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    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.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I mean, when you compare it to other languages it's very limited in what it can do
    Hmm... 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 It looks quite similar to Erlang!
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.)
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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 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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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 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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •