| kkwweett 2008-03-07, 7:22 pm |
| Hi,
I don't understand the logic behind the use of the word "begin".
For example, this is a program (TinyScheme) which solves the Hanoi
towers problem :
(define (move n f t s)(if(not(= n 0))(begin(move (- n 1) f s t)(display
(string-append f "->" t ", "))(move (- n 1) s t f))))
where n is the integer number of towers, f the string representing the
initial location, t the string representing the final location and s the
string representing the intermediate location.
(move 4 "A" "B" "C") gives :
A->C, A->B, C->B, A->C, B->A, B->C, A->C, A->B, C->B, C->A, B->A, C->B,
A->C, A->B, C->B, ()
Now, I'm trying Without The Begin Keyword
(define (moveWTBK n f t s)(if(not(= n 0))((moveWTBK (- n 1) f s
t)(display (string-append f "->" t ", "))(moveWTBK (- n 1) s t f))))
Here, (moveWTBK 4 "A" "B" "C") gives :
A->C, Error: illegal function
and I can't figure out what's happened and why can't moveWTBK be right.
Can you help me, please ?
Have you got references ?
Thanks.
|