Skip to main content
gamedev.net
🔒 Locked

Prolog Database?

Started by Anima May 8, 2004 at 10:44 AM 3 replies 350+ views
Original Post
Anima
Anima
I''m trying to create a searchable database in Prolog. Can someone explain how I can use a record containing (First Name, Second Name, Address) and then have multiple records to create a database? I know that Prolog isn''t the same as C/C++ but surely this can be done?
Wyrframe
Wyrframe
entry( jim, bean, '303 Main St, Hometown, SomeState' ).
entry( jane, bean, '303 Main St, Hometown, SomeState' ).
entry( billy, bean, 'The Slums, Hometown, SomeOtherState' ).

addentry( Fn, Sn, Ad ):- assertz( entry( Fn, Sn, Ad ) ).
delentry( Fn, Sn, Ad ):- revoke( entry( Fn, Sn, Ad ) ).


And then, at an interactive prompt...

?> entry( A, bean, _ ).
jim
jane
billy
YES
?> entry( _, bean, _ ).
YES
?> entry( _, turnip, _ ).
NO
?> addentry( alex, turnip, 'DamnedIfIKnow' ).
YES
?> entry( A, B, _ ).
A = jim B = bean
A = jane B = bean
A = billy B = bean
A = alex B = turnip
YES


[edited by - Wyrframe on May 8, 2004 6:11:52 PM]
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Anima
Anima
Thanks for the reply, it really helped.

I''m now trying to make Prolog output a formatted number (for a time) to represent a time, for example:

write(H), write('':''), write(M), nl.

If H = 12 and M = 5, then the output will be ''12:5''. Is there any way I can format this so it says ''12:05'' instead?

Thanks again
Puzzler183
Puzzler183
I don''t know prolog so no source for you but just use an if statement. If it''s less than ten, print an extra zero.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.