0

I am about to write code for my project, which is to create a database in SWI-Prolog. The program should contain ADDING, DELETING, SORTING and SEARCHING entries. My problems are:

  1. I want to ADD 'runners' with capital letters.
  2. When I'm addin/deleting something in database, the file stays either empty or the only entry is the entry I have actually added.

I'm using one file as database entries and the second file for all of the logic. Thanks for helping me in advance.

In the database, there are these records:

:- dynamic runner/6.

runner(elvis, presley, _, _, _ ,_).
runner(darth, vader, _, _, _, _).
runner(louis, armstrong, _, _, _, _).
runner(wayne, gretzky, _, _, _, _).

The '_' components are for example DATE, HEIGHT, WEIGHT, ... The database file is named database.pl.

In logic, there is this:

add :-
   write_ln('Name: '),
   readln(M),
   write_ln('Surname: '),
   readln(P),
   insert(M, P).

del :-
   write_ln('Name: '),
   readln(M),
   write_ln('Surname: '),
   readln(P),
   delete(M, P).

insert([M], [P]) :-
    tell('database.pl'),
    asserta(pretekar(M, P,_,_,_,_)),
    told,
    write('Added runner: '), write(M), write(' '), write_ln(P).

delete([M], [P]) :-
    tell('database.pl'),
    retract(runner(M, P, _, _, _, _)),
    listing(runner),
    told,
    write('Deleted runner: '), write(M), write(' '), write_ln(P).

Every runner must be written by his name and surname, the other fields can be blank. How to do to add at least Name, Surname and at maximum Name, Surna,Height, Date, Weight... That only first two fields are mandatory others are not.

4

0 回答 0