Hello New Prolog Programmer!

Hello all,

i am a new programmer and i decided to learn i prolog. I find the language fascinating. I hope you do not mind me being around here at all, i might ask some questions. So, hello!

2 Likes

Welcome! a good way to start learning is trying to solve logical puzzles, just google some logical puzzles and choose the easiest one to start.

Welcome! It’s delightful to have you here, and I hope you enjoy learning Prolog! definitely feel free to ask whenever you have questions :smiley:

Thank you! I am following a book on how to program in prolog for beginners. Its a pretty good book so far and I find the language very interesting on how it works so far. I will be doing the practical questions to get the hang of how to write code and define rules.

1 Like

Hi,

Once you have done some practicing, I highly recommend reading Markus Trishka’s online book and his accompanying youtube videos – they were eye opening for me, when i started programming in Prolog in earnest a few years ago.

https://www.metalevel.at/prolog

Dan

1 Like

I wonder if logic puzzles are the best place to start, although they do show off some of the things in Prolog that are much easier than in other programming languages. There are often representation issues that can confuse beginners, and also various termination techniques (e.g., when solving the dog-rabbit-cabbage puzzle, making sure that a position isn’t repeated).

It’s probably more boring to follow one of the texts, but will lead to a quicker understanding of the basics. (Depends on the text of course; some are very good, some have very bad advice.)

1 Like

When i started programming, there were those programming magazines that published code for games and other useful stuff.

One couldn’t simply download them, so i had copied them into my home computer – looking at each line – later i studied programs of others – not puzzles – to learn more.

It would be great if there was a repository of open source programs written in prolog that one can study – even annotated ones …

OKefee has in his Crafts book a short example of a tax rules evaluation program fragment – which, i found instructive to look at …

If games interest you, this is a reasonable introduction to Prolog: Amzi! inc. Adventure in Prolog
It uses assert and retract to manage where you are in the game, which might not be the best style, but does simplify things somewhat.

1 Like

Thanks for the responses. Im reading Logic programming with prolog by “Max Bramer”. Ill check out the other book once i have a grasp on the language.

Hello,

So i checked out that book, and its a bit to text heavy for me, i like something with a bit more hands-on approach.

Hi, What do you do with Pro log? pro log use backward chaining strategy.

Hi Roham,

It is amazing in my mind that the backward chaining strategy, through backtracking, opens the door for a declarative specification approach that is closer to mathematical problem-oriented than imperative solution-oriented descriptions.

I currently do three main things with Prolog:

  1. I explored the design of data structures and algorithms by use of a high level language well suited for recursive algorithms.

  2. I use Prolog to prototype problems – and find that such explorations are at a higher-level of abstraction than when using imperative languages such as Java.

  3. Explore the development of a commercial product – and as much as possible within Prolog

Dan

I had a question for all of you if don’t mind answering this. as i understand, let’s say you had the following facts
dog(fido).
cat(mary). dog(rover).
dog(tom). cat(harry).
dog(henry).
cat(bill). cat(steve).
as i understand it, you cannot write facts like this. the book i am reading has facts written like this, and because the predicates are not in order, SWI Prolog says it doesn’t like it, same with GNU Prolog. I took the initiative and just fixed it, but why would the book have it written like this?

Try adding discontiguous/1 directives:

:- discontiguous dog/1, cat/1.
dog(fido).
cat(mary). dog(rover).
dog(tom). cat(harry).
dog(henry).
cat(bill). cat(steve).

The warning from SWI-Prolog (and other Prologs) catches some common typos; but you can override the warning. (And it’s only a warning; without the discontiguous/1 directive, the code will work fine.)

oh, they are just literal “warnings”. my bad, sorry to bother you peter. Thank you for the fix as well.

Literal warnings that you shouldn’t ignore :slight_smile: so good that you didn’t!

Normally you’d keep the clauses of the same predicate together. The warning is to prevent a situation where you forgot that you defined a predicate already and start adding additional clauses to the same predicate thinking that you are defining a new predicate.

In this particular situation it is obviously safe to tell Prolog “yes this is exactly how I want it”.

Thanks grossdan