newby question about lists

  • Follow


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I have

parent(mum,[ isa,jm]).

in test_01.pl
after consulting it, I hit:
parent(mum,X).
and get as expected :

X = [isa, jm]

How should I write the file so that asking the same question I get the
answers :

X = isa ;
X = jm ;

I still want to use lists in the file.

I am using SWI-Prolog (Multi-threaded, Version 5.2.13)
on Linux.

###

How can I add knowledge in the DB using the CLI ?
for example if the user consult the file, but want to add knowledge;
- - how should he add information usable later in the same cession ?
- - how to save the whole database into a new file for later use ?

###

Is it possible in PROLOG to execute external file ? something like the C
call 'system' or such ...

###

Thanks
- --
DEMAINE Beno�t-Pierre http:/www.demaine.info/
\_o< apt-get remove ispell >o_/
There're 10 types of people: those who can count in binary and those who
can't
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBfxIrGWSTLbOSw8IRAiasAKC0mdVvnXrzA/Au+0pm18lMZhezwwCeJ7X/
cFTpn0fXwpKftVwW778j0ds=
=pNoY
-----END PGP SIGNATURE-----
0
Reply nntp_pipex (70) 10/27/2004 3:12:44 AM

In article <s7KdnYW2WsA2j-LcRVnyhA@pipex.net>, DEMAINE Benoit-Pierre wrote:
> I have
> 
> parent(mum,[ isa,jm]).
> 
> in test_01.pl
> after consulting it, I hit:
> parent(mum,X).
> and get as expected :
> 
> X = [isa, jm]
> 
> How should I write the file so that asking the same question I get the
> answers :
> 
> X = isa ;
> X = jm ;
> 
> I still want to use lists in the file.

There are two ways.  Runtime you get 

my_parent(X, Y) :-
	parent(X, List),
	member(Y, List).

You can also do it compiletime, so you can write the input the way
you like and have it available to Prolog the way Prolog likes it.

term_expansion(parent(X, List), Clauses) :-
	mk_parent_clauses(List, X, Clauses).

mk_parent_clauses([], _, []).
mk_parent_clauses([H|T0], X, [parent(X, H)|T]) :-
	mk_parent_clauses(T0, X, T).

check the manual for term_expansion/2.

> I am using SWI-Prolog (Multi-threaded, Version 5.2.13)
> on Linux.
> 
> ###
> 
> How can I add knowledge in the DB using the CLI ?
> for example if the user consult the file, but want to add knowledge;
> - - how should he add information usable later in the same cession ?
> - - how to save the whole database into a new file for later use ?

See dynamic/1, assert/1 for modifying.  You can just write the file
yourself, or use listing/1 and/or portray_clause/1.

> ###
> 
> Is it possible in PROLOG to execute external file ? something like the C
> call 'system' or such ...

See shell/1.  You should have been able to find that in the manualm where
there is a section 'Operating system interaction'.

	--- Jan

	
0
Reply Jan 10/27/2004 7:43:08 AM


1 Replies
21 Views

(page loaded in 0.059 seconds)

Similiar Articles:













7/23/2012 8:01:54 AM


Reply: