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 8966045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:56:26+00:00 2026-06-15T16:56:26+00:00

Here is a simple Prolog program to exhibit a problem that I currently have

  • 0

Here is a simple Prolog program to exhibit a problem that I currently have with my real code.

I am trying to write a Brainf*ck interpreter in Prolog, but it is not returning the right Output

I am running bf("+.", Output)

Expected Return – Output = [1]

Actual Return – Output = [].

Output looses its value when it returns to iterateProg(Prog,Output) in bf2.

Program is as follows:

bf2(Prog,Output):-
    iterateProg(Prog,Output).

iterateProg([],_):- !.
iterateProg(Prog, Output):-
    checkInstruction(Prog,Output, NewProg, NewOutput),
    iterateProg(NewProg, NewOutput).

checkInstruction([Plus|ProgTail],Output,ProgTail,Output):-
    char_code('+',Plus)
    %increase memory by 1 for printing later.
    .

checkInstruction([Period|ProgTail], Output, ProgTail, NewOutput):-
    char_code('.',Period),
    %take the value in memory from addition just now, we will assume it is 1
    append(Output,[1],NewOutput).
  • 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-15T16:56:27+00:00Added an answer on June 15, 2026 at 4:56 pm

    Your predicate bf2(Prog, Output) has the meaning of: this program Prog correspond with this output Output – so the Output in the bf2 predicate and also in iterateProg should contains the full output.

    So in checkInstruction predicate, the first 2 arguments should contain the full program and the full output, and the last 2 arguments should contain the partial program and the corresponding partial output.

    Therefore, you should append the [1] with NewOutput, to produce the final output in Output for the second rule of checkInstruction predicate. You should rename the New... with a different name – since it is actually the partial/”tail” program and corresponding output.

    append([1], NewOutput, Output)
    

    Note the order (I was inaccurate in the comment). [1] is the output for the current instruction, and it should precede the output of the instruction in ProgTail.

    By the way, bf2 predicate is unnecessary – since it call iterateProg predicate with exact same arguments.

    Another thing is iterateProg([],_) should be iterateProg([],[]) since an empty program should correspond with empty output. (The converse is not true, so you should never put a cut ! here, if you have learned about it).

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

Sidebar

Related Questions

I am working on a simple prolog program. Here is my problem. Say I
What I have here real simple activity with two buttons. When you press each
Well its simple here you have my vb.net code: Public Class Class1 Public Overridable
I'm trying to do something relatively simple here. Basically I have a table with
I've omitted some code(package declarations, imports, other fields) for shortness. I have here simple
I'm starting with Prolog, and i'm a bit confused... I have a simple program:
I have here a simple image converter code using Magick++(ImageMagick interface) library.(Eclipse IDE) #include
here my simple code to add filename and their associated icon to virtualtreeview PFileInfoRec
All my code is here,quite simple,and I don't konw where it goes wrong. Person
Hi i've got here a simple program, but it's not working properly. When i

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.