Prolog returns variable name instead of value

Jakob Auer

I have a method which checks where to place the next brick while building a tower.

freePosition(POS, LEVEL) :- levelWithSpace(LEVEL),
                            freePositionOnLevel(POS, LEVEL).

This method checks for a level with space and asks for the free positions on this level. In my case it should return two results:

  • POS=1, LEVEL=2
  • POS=2, LEVEL=2

However it returns the following output:

?- freePosition(POS, LEVEL).
POS = 1,
LEVEL = 2 ;
POS = LEVEL, LEVEL = 2 ;

How can I change the behavior that it returns POS=2 instead of POS=LEVEL?

repeat

You can use the builtin format/2 to emit a formatted string:

?- freePosition(POS, LEVEL),
   format('Pos = ~d, Level = ~d~n', [POS,LEVEL]).

This will make it easy to get a uniform output style no matter what Prolog implementation you use.

Note that the concrete style of answers given by the Prolog interpreter top-level differs quite a bit between different Prolog implementations.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Lambda function returns function name instead of value in Python

Laravel query returns question mark instead of variable value

Controlling Prolog variable value selection

Adding variable name instead of value of variable to select list

Prolog programm returns yes instead of value

Prolog: Assign value to Variable in Predicate

Indirect expansion returns variable name instead of value

Lua puts of variable name instead of variable value in table

Can't use $refs using variable name instead of direct value

Bash - How to show variable value instead of name in background process descriptions?

Assigning a function to the value of a variable instead of the variable name

How do i print Variable name instead of the value assigned to the variable?

Python get variable name instead of value

AngularJS returns variable name in curley brackets, not the value

Returning a true value instead of integer value in prolog

How can I get Matlab to use the variable value instead of name

PHP PDO mySQL query returns column name instead of value

MySQL returns the name of the column instead of the value

Sql: Query returns column name instead of Value

create variable of select option name instead of value in php

Using context variable to name a "section" instead of passing a value

display variable name instead of value in foreach loop

Prolog - Assign value instead of evaluating it

prolog returns value twice

GetDetailsOf returns property name instead of value (delphi 2007)

Macro variable is not printing the table value but instead the column name

evalf in sympy returns expression instead of value in single variable expression

Why is the object property using variable name as key instead of variable value?

How to use min() and max() functions to print the variable name instead of the value?