Re: :- at the beginning for assertional coding



newser.bbs@xxxxxxxxxxxxxxxxx escreveu:
It makes programmers chage almost nothing from the
code he wroks out in the toplevel by using assertz/1 or
asserta/1 dynamically.
[snipped]
======================================
(revised surece codes file :'test1.txt')
:-assertz((test:-write('Hello World!'))).
[snipped]
See ? The secret is ":-" at the beginning of the code line.

As I mentioned in the previous message that :- at the
beginning of the line can make that line being executed,
not compiled.

We don't need the assertz/1 being compiled , but we need
it being executed. Thus we have to use ":-" at the beginning
of the line.

In fact, no!

In Prolog you save a facts database in a file and just consult it without needing to use assert[az]/1 at all:

content of test0.txt:

test:-write('Hello World!').


Welcome to SWI-Prolog (Multi-threaded, Version 5.6.7)
Copyright (c) 1990-2006 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- consult('test0.txt').
% test0.txt compiled 0.00 sec, 596 bytes

Yes
?- test.
Hello World!

Yes
?-

--
Cesar Rabak
.