kialios
kialios

Reputation: 11

Can't pass integer as argument to function in prolog

We are trying to do a school project in which we solve a problem of collecting items in an Amazon Building.

We think we have the code almost set up but aren't able to pass a simple integer to a Clause for it to check, we get Wrong ObjectType all the time.

domains
posicionInicial = Symbol
posicionFinal= Symbol
posicion = Symbol
idestanteria = Symbol
nombre = Symbol
distancia = integer
cantidad = integer

/* lineapedido = linea (Symbol, integer) */ 
/* pedido = lineapedido* */

predicates

estanteria (idestanteria,posicion)
valido (nombre,posicion,cantidad)
ubicacion (nombre, idestanteria, cantidad)
conectado (posicionInicial, posicionFinal, distancia)
mueve (posicionInicial,posicionFinal,nombre, cantidad, distancia)
resuelve (nombre,cantidad) 


clauses

estanteria(s1,ps1).
estanteria(s2,ps2).
estanteria(s3,ps3).
estanteria(s4,ps4).
estanteria(s5,ps5).
estanteria(s6,ps6).
estanteria(s7,ps7).
estanteria(s8,ps8).

ubicacion(patatas,s1,200).
ubicacion(melones,s1,100).
ubicacion(boligrafos,s2,500).
ubicacion(boligrafos,s3,400).
ubicacion(melocotones,s4,200).
ubicacion(berzas,s4,100).
ubicacion(papeles,s5,500).
ubicacion(boligrafos,s6,400).
ubicacion(plumas,s7,500).
ubicacion(plumas,s8,400).
ubicacion(colonias,s3,150).
ubicacion(ratones,s4,210).

/* Conexiones IDA */    
conectado (pc1,pc2,10).
conectado (pc2,pc3,10).
conectado (pc3,pc4,10).
conectado (pc4,t,10).
conectado (ps1,pc1,5).
conectado (ps2,pc2,5).
conectado (ps3,pc3,5).
conectado (ps4,pc4,5).
conectado (ps6,pc6,5).
conectado (ps7,pc7,5).
conectado (ps8,pc8,5).

/* Conexiones vuelta */
conectado (pc2,pc1,10).
conectado (pc3,pc2,10).
conectado (pc4,pc3,10).
conectado (t,pc4,10).
conectado (pc1,ps1,5).
conectado (pc2,ps2,5).
conectado (pc3,ps3,5).
conectado (pc4,ps4,5).
conectado (pc6,ps6,5).
conectado (pc7,ps7,5).
conectado (pc8,ps8,5).


/* Mueve S -> PC1 */
mueve (s,pc1,nombre, cantidad, distancia):-
    conectado (posicion,posicion, distancia),
    valido (nombre, pc1, cantidad). 

mueve (pc1,ps1,nombre, cantidad, distancia):-
    conectado (posicion,posicion, distancia),
    valido (nombre, ps1, cantidad). 


valido (nombre, posicion, cantidad):-
    estanteria (idestanteria, posicion),
    ubicacion (nombre, idestanteria, cantidad).



/* Resolucion algoritmo */

resuelve (nombre,cantidad):-
    /* lineapedido = [H|T],*/
    /* H = linea (patatas, 200), */ 
    mueve (posicionInicial, posicionFinal, nombre, cantidad, distancia),
    write ("HOLA").




goal 

resuelve(patatas, 1).

When we try to compile that, we get this error: E;Test_Goal, pos: 1922, 512 Type error: Wrong object type

And it takes us to this line:

valido (nombre, posicion, cantidad):-

Can't seem to find why, when it's only passing an integer as argument. Thanks in advance, if something else needed just tell me.

Upvotes: 1

Views: 503

Answers (2)

Anton Danilov
Anton Danilov

Reputation: 1276

in addition to answer 1 I can tell that you've almost totally typed symbols instead of variables.

Variable name syntax:

  1. The first char is upper-cased letter or underscore ("_");

  2. The rest chars are alpha-numeric chars of any case or underscore;

Replace symbols with variables when it's appropriate.

edit1: Example:

 domains 
      any=term,
      list = any*
 predicates 
      member(any, list) 
 clauses 
      member(X, [X | _ ]).
      member(X, [ _ | Y]) :- member(X,Y).

"_" means anonymuous var. Unlike the regular (named) variables, the anonymuous variables are all distinct: "_" isn't the name but it's the indicator - "This is an anon. var. don't care about its name"

edit2:

useful link:

Markus Triska

https://www.metalevel.at/prolog

Upvotes: 1

Fatalize
Fatalize

Reputation: 3543

valido (nombre, posicion, cantidad) is not a valid rule head or predicate call.

You cannot put a space between the predicate name and the first parenthesis.

For example, test (1). does not compile:

ERROR: c:/test.pl:1:5: Syntax error: Operator expected

but test(1). does.

So remove all those spaces.

Upvotes: 0

Related Questions