Earlier quoted context omitted.
The way you write imperative programs in Prolog by exploiting the search order, using cuts, etc. seems clever when you see it in school and do a few assignments for a comparative programming languages class (the only 3 credit CS course I took) but it is painfully awkward if you have to do very much of it.
It isn't. I do most of my programming in Prolog, I write oodles of it daily, and it's not a problem. You learn to think that way easily. The argument is basically that Prolog is not 100% declarative and that if we jump through a few hoops, and translate it all to functional notation, we can make it "more declarative". But let's instead compare the incomplete declarativeness of Prolog to a fully-imperative, zero-decla…
result(World0, move(robot(R), Dir), World) :-
dissoc(World0, at(robot(R), X0), World1),
direction_modifier(Dir, Modifier),
X #= X0+Modifier,
conj(World1, at(robot(R), X), World).
result(World0, drop_rock(robot(R), Place), World) :-
dissoc(World0, capacity(Place, Capacity0), World1),
dissoc(World1, carring_rock(robot(R)), World2),
Capacity #= Capacity0 + 1,
conj(World2, capacity(Place, Capacity), World).
result(World0, pickup_rock(robot(R), Place), World) :-
dissoc(World0, capacity(Place, Capacity0), World1),
Capacity #= Capacity0 - 1,
conj(World1, capacity(Place, Capacity), World2),
conj(World2, carrying_rock(robot(R)), World).
See if you can spot the bug....
...
...
carrying_rock vs carring_rock
Because the typo was in a functor (not predicate or singleton variable) there was no IDE or language support, Prolog assumed that I wanted an reported the wrong answer.
of course the snippet I showed was part of a larger example.
In other languages it would've taken me 5 minutes to bisect the program or debug and find the error but it took me 3-4 hours.
I ended up needing to write a lot of error correcting code, basically a half-assed type system, and that code ended up being more substantial than the actual program logic.
Is this common? Am I "doing it wring"?Right now this seems to have all the downsides of programming exclusively with "magic strings", and I haven't been able to find any cure for it or even seen this problem discussed elsewhere.
*Edit:*
I even rewrote it for SICStus and downloaded their IDE and taught myself Eclipse just to use their IDE plugin, and found that setting breakpoints didn't help the problem, because naturally due to the fact that the functor is in the predicate signature, the predicate is never stepped into in the first place!
I could linearize the arguments and include them in the body but this destroys the indexing and can put me into "defaulty representation" territory.