how to write prolog programs

February 20, 2011 at 17:04:00
Specs: Linux i686
:- dynamic fruit/3.
fruit(apple, crate, 6). fruit(pear, crate, 5).
fruit(mango, box, 4). fruit(apple, box, 3). fruit(banana, box, 5).
fruit(pear, box, 10). fruit(apricot, box, 4). fruit(peach, box, 5).
fruit(walnut, box, 4).
fruit(blueberry, tray, 10). fruit(blackberry, tray, 4).
fruit(watermelon, piece, 8). fruit(marrow, piece, 7).
fruit(hazelnut, sack, 2). fruit(walnut, sack, 4).
question; writing an interactive query for finding out how many packets of a certain fruit and what in format are available

See More: how to write prolog programs

Report •

February 20, 2011 at 23:42:43
Do your own homework. If you don't understand it then discuss it with your teacher.

Report •

February 22, 2011 at 13:22:25
Lol... thats the 1st part of our coursework.. common get a grip!!

Anyway. im trying touse the write predicate write/2 which the help menu says
Write(S,Term) writes Term to S.

where list is an output from bagof
Write( S, List)

However when i do this it complains that "Arguments are not sufficiently instantiated
" any help on where im doing this wrong??

Report •

February 22, 2011 at 13:39:23
That error means that you haven't bound one of the variables (i.e. you haven't assigned a value to it). (I assume that you are actually using "write" rather than "Write".) There are only two variables, so it should be easy to figure out which one. Make things simpler by using the /1 form:


That should work. For example:

List = [1, 2, 3],

will produce the output "[1, 2, 3]". But note that:

List = [1, 2, 3].

won't produce the desired output. Play around with really simple examples and you should be able to get it to do what you want.

Note: I'm using SWI Prolog here. There may be syntactic differences in other implementations.

Report •
Related Solutions

Ask Question