Quick Scheme question, begginners

SnoopCat

Senior member
Jan 19, 2001
926
0
0
(define fact
(lambda (x)
(cond
( ( = x 0 ) 1 )
( else ( * x ( fact x - 1 ) ) )
)
)
)




=> (fact 3)


i get an error..... anyone see the bug?
its for factorials
 

Platypus

Lifer
Apr 26, 2001
31,046
321
136
(define fact
(lambda (x))
(cond
( ( = x 0 ) 1 )
( else ( * x ( fact x - 1 ) ) )
)
)
)




=> (fact 3)


try that..
 

Xede

Senior member
Oct 15, 1999
420
0
0
Try replacing (fact x - 1) with (fact (- x 1)) or something like that...