For Programmers: Free Programming Magazines  


Home > Archive > Scheme > March 2008 > [newbie][syntax]begin









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [newbie][syntax]begin
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.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com