True AND false OR true?

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 ?

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
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:

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:

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:

?- assert(animal(elephant)).

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

?- 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! for more details and a structured learning path.

when i follow the Learning-Link, I get this:
ScreenShot

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, 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


For much more info also see Useful Prolog references

The Link: Learn Prolog Now!
is exactly, where I get the Information for the ScreenShot.

okay. SWISH works

1 Like

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

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.

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.

?- 

Thanks for hanging in there.

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

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.