# True AND false OR true?

**URL:** <https://swi-prolog.discourse.group/t/true-and-false-or-true/6776>\
**Category:** General\
**Created:** [August 19, 2023, 12:39pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776 "2023-08-19T12:39:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![paule32](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/paule32/32/5112_2.png) [@paule32](https://swi-prolog.discourse.group/u/paule32)\
**Post date:** [August 19, 2023, 12:39pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776/1 "2023-08-19T12:39:19Z")

</div>

Hello,  
under Windows 10 Command Line Console (noit PowerShell), i give the PATH to point to E:\SWIPL\bin.  
This works fine, when I type in swipl.exe under other directory.  
okay so far.  
now, I type on the swipl Console: (excluding the n ?- where n is the command line, and ?- the Prompt:  
?- color( red ).  
Error: Unknown procedure: color/1

I was thinking that was a fact. And facts are atomare Elements in Swipl ?  
when I type in:  
?- assert( color( red ) ).  
true

I get true. Okay so far.  
Now:  
?- color(red).  
true

?- color(blue).  
false

what is the difference ?  
I was thinking, that Fact’s a base, and/or static knowledge…  
What does the assert/1 do ?

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [August 19, 2023, 1:05pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776/2 "2023-08-19T13:05:49Z")

</div>

If you use one of the free LLM based tools such as ChatGPT, Bard, Claude, etc. it can give you a useful answer

* * *

[ChatGPT August 3 Version](https://help.openai.com/en/articles/6825453-chatgpt-release-notes)  
Model: GPT-3.5  
**Prompt**

With Prolog

What does the assert/1 do ?

**Completion**

In Prolog, the `assert/1` predicate is used to dynamically add new facts or clauses to the knowledge base during the runtime of a Prolog program. It allows you to insert new predicates or rules into the program’s database of facts and rules. The syntax for `assert/1` is:

```prolog
assert(Fact_or_Rule).

```

Here, `Fact_or_Rule` can be either a single fact (predicate) or a rule (predicate with a body). The `assert/1` predicate takes this fact or rule and adds it to the knowledge base, making it available for subsequent queries and rule evaluation.

For example, let’s say you have a Prolog program that defines a few facts and rules related to animals:

```prolog
animal(cat).
animal(dog).

mammal(X) :- animal(X), not(bird(X)).

```

You can use `assert/1` to dynamically add new facts or rules. If you run the following query:

```prolog
?- assert(animal(elephant)).

```

The `animal(elephant)` fact will be added to the knowledge base, and from that point on, you can query:

```prolog
?- animal(elephant).
true.

```

It’s important to note that the changes made with `assert/1` are usually temporary and only affect the current session. If you restart the Prolog interpreter, the added facts and rules will not persist unless you save them to a file and load them back when restarting.

Additionally, in some Prolog implementations, there might be other predicates like `retract/1` or `retractall/1` that allow you to remove facts or rules from the knowledge base. These predicates provide a way to manage and modify the dynamically asserted information.

* * *

* * *

You should work your way through [Learn Prolog Now!](https://www.let.rug.nl/bos/lpn//index.php) for more details and a structured learning path.

---

<div class="post-metadata">

**Author:** ![paule32](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/paule32/32/5112_2.png) [@paule32](https://swi-prolog.discourse.group/u/paule32)\
**Post date:** [August 19, 2023, 1:35pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776/3 "2023-08-19T13:35:44Z")

</div>

when i follow the Learning-Link, I get this:  
[ScreenShot](https://imgur.com/wm9wnZk)

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [August 19, 2023, 1:43pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776/4 "2023-08-19T13:43:19Z")

</div>

Thanks.  
Sorry about that. I grabbed the first link from Google which would always give the correct link, seems Google has changed the priority of the versions.

There are a few versions out there and that one is special in that it took the book and integrated it with [SWISH](https://swish.swi-prolog.org/), not all of the kinks were worked out of it.

The one that I find currently works best is the one with just the web pages and then using a separate running instance of SWI-Prolog. Try this link

[https://www.let.rug.nl/bos/lpn//lpnpage.php?pageid=online](https://www.let.rug.nl/bos/lpn//lpnpage.php?pageid=online)

* * *

For much more info also see [Useful Prolog references](https://swi-prolog.discourse.group/t/useful-prolog-references/1089)

---

<div class="post-metadata">

**Author:** ![paule32](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/paule32/32/5112_2.png) [@paule32](https://swi-prolog.discourse.group/u/paule32)\
**Post date:** [August 19, 2023, 1:46pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776/5 "2023-08-19T13:46:45Z")

</div>

The Link: [Learn Prolog Now!](https://www.let.rug.nl/bos/lpn//lpnpage.php?pageid=online)  
is exactly, where I get the Information for the ScreenShot.

---

<div class="post-metadata">

**Author:** ![paule32](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/paule32/32/5112_2.png) [@paule32](https://swi-prolog.discourse.group/u/paule32)\
**Post date:** [August 19, 2023, 2:12pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776/6 "2023-08-19T14:12:58Z")

</div>

okay. SWISH works

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [August 19, 2023, 2:22pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776/7 "2023-08-19T14:22:15Z")

</div>

It is not you.

I looked at the book and it seems to now be missing how to load the knowledge bases which makes the rest of the examples useless because as you found out they do not work.

* * *

From the screen shot it looks like you are not using Windows which is what I use so this next example will not be exactly correct for you but should give you an idea.

For this, do not refer back to Learn Prolog Now!. This is based on

[https://www.swi-prolog.org/pldoc/man?section=quickstart](https://www.swi-prolog.org/pldoc/man?section=quickstart)

but I am doing it for Windows. The `likes` file noted is installed with SWI-Prolog so you should be able to find it for your install.

```prolog
Welcome to SWI-Prolog (threaded, 64 bits, version 9.1.13)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- [likes].
ERROR: source_sink `likes' does not exist
ERROR: In:
ERROR: [24] throw(error(existence_error(source_sink,likes),_146))
ERROR: [19] '$resolve_source_path'(likes,_178,[expand(false),...]) at c:/program files/swipl/boot/init.pl:2497
ERROR: [18] '$load_file_e'(likes,user,[expand(false),...]) at c:/program files/swipl/boot/init.pl:2466
ERROR: [17] '$load_file'(likes,user,[expand(false),...]) at c:/program files/swipl/boot/init.pl:2433
ERROR: [9] toplevel_call(user:user: ...) at c:/program files/swipl/boot/toplevel.pl:1173
ERROR: 
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail. $`
?- pwd.
% c:/users/groot/documents/prolog/
true.

?- working_directory(_,'C:/Program Files/swipl/demo').
true.

?- pwd.
% c:/program files/swipl/demo/
true.

?- [likes].
true.

?- likes(sam,X).
X = dahl ;
X = tandoori ;
X = kurma ;
X = chow_mein ;
X = chop_suey ;
X = sweet_and_sour ;
X = pizza ;
X = spaghetti ;
X = chips.

?- 

```

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [August 19, 2023, 2:35pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776/8 "2023-08-19T14:35:23Z")

</div>

> [@paule32](#):
>
> okay. [SWISH](https://swish.swi-prolog.org/) works

Thanks for hanging in there.

I know it is frustrating just getting the first query to work and many give up, so congratulations!

---

<div class="post-metadata">

**Author:** ![paule32](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/paule32/32/5112_2.png) [@paule32](https://swi-prolog.discourse.group/u/paule32)\
**Post date:** [August 19, 2023, 2:47pm UTC](https://swi-prolog.discourse.group/t/true-and-false-or-true/6776/9 "2023-08-19T14:47:37Z")

</div>

ah. okay. wow.  
yes.  
I understand.

?- [loadfilename.pl] % \<— load a filename.pl script

?- % ← this is the Query-Prompt for Fact’s (not directly the Source Code), that stand in SourceCode.

All clear.
