# Hello New Prolog Programmer!

**URL:** <https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327>\
**Category:** Discussion\
**Created:** [August 21, 2021, 4:01pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327 "2021-08-21T16:01:46Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![turco90](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/turco90/32/3683_2.png) [@turco90](https://swi-prolog.discourse.group/u/turco90)\
**Post date:** [August 21, 2021, 4:01pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/1 "2021-08-21T16:01:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![swi](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@swi](https://swi-prolog.discourse.group/u/swi)\
**Post date:** [August 22, 2021, 2:26am UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/2 "2021-08-22T02:26:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dmchurch](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/dmchurch/32/3427_2.png) [@dmchurch](https://swi-prolog.discourse.group/u/dmchurch)\
**Post date:** [August 22, 2021, 3:00am UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/3 "2021-08-22T03:00:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![turco90](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/turco90/32/3683_2.png) [@turco90](https://swi-prolog.discourse.group/u/turco90)\
**Post date:** [August 22, 2021, 11:25am UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/4 "2021-08-22T11:25:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [August 22, 2021, 1:04pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/5 "2021-08-22T13:04:12Z")

</div>

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](https://www.metalevel.at/prolog)

Dan

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [August 22, 2021, 5:24pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/6 "2021-08-22T17:24:24Z")

</div>

> [@swi](#):
>
> a good way to start learning is trying to solve logical puzzles

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.)

---

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [August 22, 2021, 5:59pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/7 "2021-08-22T17:59:27Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [August 22, 2021, 6:24pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/8 "2021-08-22T18:24:12Z")

</div>

> [@grossdan](#):
>
> code for games and other useful stuff.

If games interest you, this is a reasonable introduction to Prolog: [Amzi! inc. Adventure in Prolog](http://www.amzi.com/AdventureInProlog/)  
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.

---

<div class="post-metadata">

**Author:** ![turco90](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/turco90/32/3683_2.png) [@turco90](https://swi-prolog.discourse.group/u/turco90)\
**Post date:** [August 25, 2021, 4:01pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/9 "2021-08-25T16:01:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![turco90](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/turco90/32/3683_2.png) [@turco90](https://swi-prolog.discourse.group/u/turco90)\
**Post date:** [August 27, 2021, 4:18pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/11 "2021-08-27T16:18:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rohamfarahani](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/rohamfarahani/32/3663_2.png) [@rohamfarahani](https://swi-prolog.discourse.group/u/rohamfarahani)\
**Post date:** [August 27, 2021, 6:18pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/13 "2021-08-27T18:18:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [August 28, 2021, 5:44pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/15 "2021-08-28T17:44:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![turco90](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/turco90/32/3683_2.png) [@turco90](https://swi-prolog.discourse.group/u/turco90)\
**Post date:** [August 28, 2021, 7:24pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/16 "2021-08-28T19:24:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![peter.ludemann](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/peter.ludemann/32/48_2.png) [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Post date:** [August 28, 2021, 7:48pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/17 "2021-08-28T19:48:45Z")

</div>

> [@turco90](#):
>
> because the predicates are not in order, SWI Prolog says it doesn’t like it

Try adding discontiguous/1 directives:

```prolog
:- 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.)

---

<div class="post-metadata">

**Author:** ![turco90](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/turco90/32/3683_2.png) [@turco90](https://swi-prolog.discourse.group/u/turco90)\
**Post date:** [August 28, 2021, 7:54pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/18 "2021-08-28T19:54:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [August 28, 2021, 8:11pm UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/19 "2021-08-28T20:11:58Z")

</div>

Literal warnings that you shouldn’t ignore 🙂 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”.

---

<div class="post-metadata">

**Author:** ![gtachta](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/gtachta/32/3699_2.png) [@gtachta](https://swi-prolog.discourse.group/u/gtachta)\
**Post date:** [September 6, 2021, 5:52am UTC](https://swi-prolog.discourse.group/t/hello-new-prolog-programmer/4327/20 "2021-09-06T05:52:00Z")

</div>

Thanks grossdan
