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

We are trying to read each word from a text file and replace it
I am trying to access a word file from my c# code. I want
I am trying to extract telephone word numbers from free text. The general format
I am trying to attach a word file from one of the folders in
I'm trying to get the plain text from a word document. Specifically, the xpath
I'm trying to serve a word document (docx) from an asp.net page using the
I've been trying to calculate all the unique permutations for a very long word
i am trying to put some word in tempfile via commandline temp file creat
I am trying to load a word document into Rich Textbox control so that
I'm trying to remove first word from given string. I'm done so far... $word

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.