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

  • SEARCH
  • Home
  • 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 3633498
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:39:39+00:00 2026-05-19T00:39:39+00:00

I am trying to do a word calculator .. read words from a file

  • 0

I am trying to do a word calculator .. read words from a file .. translate them into numbers and then calculate the result .. i managed to do all of that but i think i have two bugs in my program ..

I mainly have two functions …

extract(Words),
calculate( Words,0).

extract will read from the file .. and then return a list of Words .. ex: [one,plus,three] ..
now calculate will translate the value for these words into numbers and calculate ..
i managed to do that also ..
now the bugs are : i must stop reading and terminate if i encounter stop in the file ..
so if Words was [stop] End.
i tried the following …

execute :-
 extract(Words),
 Words = [stop],nl,print('Terminating ...'),!.
execute :-
 extract(Words),
 calculate( Words,0).

it successfully terminates .. but it skips lines as i extract more than once ..
i have tried to do ..

execute :-
 extract(Words),
 Words \= [stop],execute(Words).
execute(Words) :-
 calculate( Words,0).

if the Words is not stop .. then go and calculate .. but its not working !!

i appreciate the help ..
Thank You

  • 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-05-19T00:39:39+00:00Added an answer on May 19, 2026 at 12:39 am

    Side-effects (here: reading from a file and moving on to the next term) are not undone on backtracking. You can read once and then make the choice based on the read term with if/then/else or an auxiliary predicate, for example:

    execute :-
            extract(Words),
            (   Words == [stop] -> nl, write('Terminating ...')
            ;   calculate(Words, 0)
            ).
    

    In SWI-Prolog, consider using library(pio) for pure file reading described via dcg, which handles backtracking as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to replace a word in a text file with a
I'm trying to retrieve only word from inside each new instance of the newEntry
I am trying to extract a single word from a content editable div at
I'm trying to strip MS Word formatting on a paste into a Telerik RadEditer.
I am trying to extract the word need from this string. ctl00_ctl00_ContentMainContainer_ContentColumn1__needDont_Panel1 I have
I'm trying to highlight all matching word inside the body but not words inside
I am trying to calculate a future date with MS-Word Form Fields. I pulled
Hi Im trying to open word file using java program. The program gives me
I'm trying to get a word from a label and compare it to an
I am trying to calculate a score for a word so that it will

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.