.


:




:

































 

 

 

 





 

. . , . , . , , . ֳ .

, :

(, , _),

' stud.dba. stud.ind.

/* 6_4 */

domains

name = symbol

grup, mark = integer

session = mark*

file= dbf; ind

database

stud (name, grup, session)

predicates

use (string, string)

dbassert (dbasedom)

dbass (dbasedom, string, string)

new_rec (dbasedom, real)

new_ind (real)

dbdelete (dbasedom)

dbdel (dbasedom, string, string)

dbdel1 (dbasedom, real)

dbread (dbasedom)

dbrd (dbasedom, string, string)

dbaccess (dbasedom, real)

clauses

use (stud. ind, stud. dba).

/* */

dbassert (Term) :- use (Ind, Db), dbass (Term, Ind, Db).

dbdelete (Term) :- use (Ind, Db), dbdel (Term, Ind, Db).

dbread (Term) :- use (Ind, Db), dbrd (Term, Ind, Db).

/* */

dbass (Term, Ind, Db) :- existfile (Ind), existfile (Db), openappend (dbf, Db), new_rec (Term, Pos), openappend (ind, Ind), new_ind (Pos).

dbass (Term, Ind, Db) :- openwrite (dbf, Db), new_rec (Term, Pos), openwrite (ind, Ind), new_ind (Pos).

new_rec (Term, Pos) :- writedevice (dbf), filepos (dbf, Pos, 0), write (Term), closefile (dbf).

new_ind (Pos) :- writedevice (ind), writef (%7. 0\n, Pos), closefile (ind).

/* */

dbrd (Term, Ind, Db) :- openread (dbf, Db), openread (ind, Ind), dbaccess (Term, -1).

dbrd (_, _, _) :- closefile (dbf), closefile (ind), fail.

dbaccess (Term, Pos) :- Pos>=0, filepos (dbf, Pos, 0), readdevice (dbf), readterm (dbasedom, Term).
dbaccess
(Term, _) :- readdevice (ind), readreal (Pos), dbaccess (Term, Pos).

/* ( -1 ) */

dbdel (Term, Ind, Db) :- openread (dbf, Db), openmodify (ind, Ind), dbdel1 (Term, -1).

dbdel (_, _, _) :- closefile (dbf), closefile (ind), fail.

dbdel1 (Term, Pos) :- Pos>=0, filepos (dbf, Pos, 0), readdevice (dbf), readterm (dbasedom, Term), filepos (ind, 9, 1), flush (ind), writedevice (ind), writef ("%7. 0\n", -1), flush (ind), writedevice (screen).

dbdel1 (Term, _) :- readdevice (ind), readreal (Pos), dbdel1 (Term, Pos).

use() , .

dbassert(), dbdelet() dbrad() , . ֳ , , . , , .

, , , 䳿 , . , , . predicates.

dbass() , new_rec() new_ind(). dbass() , . .

new_ind() writef ("%7. 0\n", Pos). , Pos. , . , , .

dbrd() , , , . dbaccess (), . , ' , Pos. ³ . , . , , . Term .

dbdel() , . . dbdel1(), .

flush (). . , dbdel1 () , . dbaccess(). .

 





:


: 2015-11-05; !; : 328 |


:

:

, ,
==> ...

1616 - | 1519 -


© 2015-2024 lektsii.org - -

: 0.01 .