1 Replies - 233 Views - Last Post: 05 May 2019 - 06:10 AM Rate Topic: -----

#1 Neonz27   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 08-May 16

Errors With Outputs In Prolog

Posted 04 May 2019 - 09:53 PM


So I have recently started toying around with Prolog. This is my first time ever using a non-object-oriented programming language. I realize that this type of project isn't exactly suitable for the Prolog language, but I don't see why it can't do anything else I can do in another language. I would really appreciate it if anyone could help me understand why my simple write and writeln statements are throwing errors. I have made 2 other small programs so far that worked just fine, so any help with identifying what went wrong and what I can do to fix this situation is greatly appreciated!


Errors I'm Receiving


ERROR: No permission to modify static procedure `write/1`
WARNING: Clauses of `writeln/1` are not together in the source-file (use :- discontiguous `writeln/1` to supress this message




Code Causing The Issue


account("Joseph", 59562756, 365).
account("Juan", 19972759, 725).
account("Aunt Jemimah", 69266629, -999).

getbalance(id) :-
  account(name, id, balance).
  write("Account Balance: ").
  writeln($balance).

getnameAndbalance(id) :-
  account(name, id, balance).
  write("Account Name: ").
  writeln($name).
  write("Account Balance: ").
  writeln($balance).

getname(id) :-
  account(name, id, balance).
  write("Account Name: ").
  writeln($name).

deposit(id, amount) :-
  account(name, id, balance).
  balance = balance - amount.
  write("Balance Adjusted By: +").
  writeln($amount).
  write("Current Balance: ").
  writeln($balance).

withdraw(id, amount) :-
  account(name, id, balance).
  balance = balance - amount.
  write("Balance Adjusted By: -").
  writeln($amount).
  write("Current Balance: ").
  writeln($balance).

checkForDebt(id) :-
  account(name, id, balance).

  (balance >= 0 ->
    write($name),
    writeln(" is not in any debt.")
  ;balance <= 0 ->
    write($name),
    writeln(" is in debt!"),
    write("Current Balance: "),
    writeln($balance)
  ).





Is This A Good Question/Topic? 0
  • +

Replies To: Errors With Outputs In Prolog

#2 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2745
  • View blog
  • Posts: 4,405
  • Joined: 21-June 11

Re: Errors With Outputs In Prolog

Posted 05 May 2019 - 06:10 AM

Dots mark the end of a definition. So when you write:

getname(id) :-
  account(name, id, balance).
  write("Account Name: ").
  writeln($name).



What that really means is:

getname(id) :-
  account(name, id, balance).

write("Account Name: ").
writeln($name).



Where only the first two lines make up the definition of getname and the other lines are seen as definitions of their own. That's why Prolog thinks you're trying to redefine write and errors out.

You should separate the "statements" with commas and only have a dot after the last writeln.

The same applies to all of your definitions of course, not just getname.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1