prolog - Why is my list not being populated? -


for assignment asked write predicate route/3 succeeds if there route start finish, visiting town in list visits.

i've come idea solution reason visits list empty after route terminates , can't figure out why is. i'm not looking solution question, point me in right direction.

here code far:

note calls write debugging reasons.

road('wellington', 'palmerston north', 143). road('palmerston north', 'wanganui', 74). road('palmerston north', 'napier', 178). road('palmerston north', 'taupo', 259). road('wanganui', 'taupo', 231). road('wanganui', 'new plymouth', 163). road('wanganui', 'napier', 252). road('napier', 'taupo', 147). road('napier', 'gisborne', 215). road('new plymouth', 'hamilton', 242). road('new plymouth', 'taupo', 289). road('taupo', 'hamilton', 153). road('taupo', 'rotorua', 82). road('taupo', 'gisborne', 334). road('gisborne', 'rotorua', 291). road('rotorua', 'hamilton', 109). road('hamilton', 'auckland', 126).  route(start, start, visits) :-     write(visits), nl.  route(start, finish, visits) :-     write(visits),nl,     road(finish, from, _),     route(start, from, [from | visits]).  test :-     visits = [],     route('auckland', 'wellington', visits),     write(visits). 

the output when running test.:

1 ?- test. [] [palmerston north] [wanganui,palmerston north] [taupo,wanganui,palmerston north] [hamilton,taupo,wanganui,palmerston north] [auckland,hamilton,taupo,wanganui,palmerston north] [] true .

variables in prolog unified, not assigned. surely argument part of course.

then visits in test keeps empty list (the accumulator) 'assigned' when start. should add (or better, insert) argument route, holds built list. like

test :-     route('auckland', 'wellington', [], visits),     write(visits). 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -