The python implementation
import sys
def move(src, dst, tmp, num):
if num == 1: print 'Move from', src, 'to', dst
else:
move(src, tmp, dst, num-1)
move(src, dst, tmp, 1)
move(tmp, dst, src, num-1)
move('left', 'right', 'middle', int(sys.argv[1]))
Gives the right solution for tower of hanoi. But my scheme port,
(define move
(lambda (src dst tmp num)
(if (= num 1) (printf "Move from ~s to ~s \n" src dst)
((move src tmp dst (- num 1))
(move src dst tmp 1)
(move tmp dst src (- num 1))))))
Gives the right solution but in the end throws the following error.
procedure application: expected procedure, given: #<void>; arguments were: #<void> #<void>
I know that its my print statement that is throwing the error, but I can't figure out why is this happening ?