Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8428373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:02:15+00:00 2026-06-10T05:02:15+00:00

i am doing a Prolog project and below is my code. :- dynamic yes/1,no/1.

  • 0

i am doing a Prolog project and below is my code.

:- dynamic yes/1,no/1.
:- dynamic n_angle/1.

go :- hypothesize(Shape),
  write('Yes I know the shape you talking about is a '),
  write(Shape),
  write('!!!!'),
  undo.

hypothesize(circle)          :- circle,!.

circle :- not(verify(width)),
      verify(radius),
      not(verify(height)),
      verify(diameter_equal_2_radius).

ask(Question):-

write('Has the shape '),
write(Question),
write('?'),
read(Response),
nl,
((Response == yes ; Response == y)
  -> assert(yes(Question));
     assert(no(Question)), fail).

verify(S) :-
   (yes(S) ->  true ;
   (no(S)  ->  fail ;
   ask(S))).

save_file:- tell('D:ansSave.txt').

/* undo all yes/no assertions */
undo :- retract(yes(_)),fail.
undo :- retract(no(_)),fail.
undo :- retract(n_angle(_)),fail.
undo.

and the result will be like this.

?- go.
Has the shape width?n.

Has the shape radius?y.

Has the shape height?n.

Has the shape diameter_equal_2_radius?y.

Yes I know the shape you talking about is a circle!!!!

true.

i want to save the result as shown above to a txt file.

but when i try to put the save_file to the ask function

ask(Question):-
 save_file,
write('Has the shape '),
write(Question),
write('?'),
read(Response),
nl,
told,
((Response == yes ; Response == y)
  -> assert(yes(Question));
     assert(no(Question)), fail).

it will overwrite the result every time. can anyone tell me how to solve this ? thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T05:02:17+00:00Added an answer on June 10, 2026 at 5:02 am

    If you don’t want to overwrite previous file content, consider using append/1.

    So your rule must be:

    save_file:- append('D:ansSave.txt').
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Doing the below will reproduce my problem: New WPF Project Add ListView Name the
Doing code analysis of the project and get the message Reference-counted object is used
I've got a Prolog program where I'm doing some brute force search on all
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing a project in win32 in c++, attempting to double buffer the image being
Doing a code review I've stumbled over GWM in Java-Spring-GWT web-application. As this product
I'm trying to write a prolog program that behaves in the following fashion: it
I'm trying to code a simple graph search in SWI-Prolog. I came up with
doing the first Project Euler question: summing the multiples of 3 and 5 between
Doing some project clean up, and rather than just relying on my human eyes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.