building a list with Recursion with Prolog -
i have recursive predicate builds list it's suposed to, problem starts 'debuilding it' , gives me empty list, linha predicate ok, gives value vel, , or.
actualizarveiculos(_,[],d). actualizarveiculos(tempo,[(x,y)|restoveiculos],novaveiculos):- linha(y,or,vel), faz_andar_veic(or,(x,y),c,mod(tempo,vel)), append(novaveiculos,[c],d), actualizarveiculos(tempo,restoveiculos,d). faz_andar_veic(90,(x,y),(x+1,y),0). faz_andar_veic(270,(x,y),(x-1,y),0). faz_andar_veic(_,(x,y),(x,y),c):- c=\=0.
you need change follows:
actualizarveiculos(_,[],d, d). actualizarveiculos(tempo,[(x,y)|restoveiculos],acc, res):- or 2, vel 2, faz_andar_veic(or,(x,y),c,mod(tempo,vel)), append(acc,[c],d), actualizarveiculos(tempo,restoveiculos,d, res). faz_andar_veic(90,(x,y),(x+1,y),0). faz_andar_veic(270,(x,y),(x-1,y),0). faz_andar_veic(_,(x,y),(x,y),c):- c=\=0. test run:
[debug] ?- actualizarveiculos(5, [(-5,3), (-4,4), (-4,5)], [], res). res = [ (-5, 3), (-4, 4), (-4, 5)] . in trace provided query actualizarveiculos(5, [(-5,3), (-4,4), (-4,5)], n). since n unbound novaveiculos becomes unbound , do: append(novaveiculos,[c],d), not think or atleast intended do. tries append unbound variable list , result unified unbound variable can give infinite number of solutions, e.g.:
[debug] ?- actualizarveiculos(5, [(-5,3), (-4,4), (-4,5)], n). n = [] ; n = [_g3430] ; n = [_g3430, _g3436] ; n = [_g3430, _g3436, _g3442] ; n = [_g3430, _g3436, _g3442, _g3448] ; n = [_g3430, _g3436, _g3442, _g3448, _g3454] ; n = [_g3430, _g3436, _g3442, _g3448, _g3454, _g3460] ; n = [_g3430, _g3436, _g3442, _g3448, _g3454, _g3460, _g3466] ; n = [_g3430, _g3436, _g3442, _g3448, _g3454, _g3460, _g3466, _g3472] ; n = [_g3430, _g3436, _g3442, _g3448, _g3454, _g3460, _g3466, _g3472, _g3478] ; n = [_g3430, _g3436, _g3442, _g3448, _g3454, _g3460, _g3466, _g3472, _g3478|...] ; hope helps, comment if have questions. since didn't provide linha/3 predicate exchanged 2 unifications:
or 2, vel 2,
Comments
Post a Comment