Scheme homework help

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-03-25T23:59:06Z Indexed on 2010/03/26 0:03 UTC
Read the original article Hit count: 741

Filed under:
|
|

Okay so I have started a new language in class. We are learning Scheme and i'm not sure on how to do it. When I say learning a new language, I mean thrown a homework and told to figure it out. A couple of them have got me stumped.

My first problem is:

Write a Scheme function that returns true (the Boolean constant #t) ifthe parameter is a list containing n a's followed by n b's. and false otherwise.

Here's what I have right now:

(define aequalb (lamda (list)
(let ((head (car list)) (tail(cdr list)))
(if(= 'a head)
((let  ((count (count + 1)))
(let (( newTail (aequalb tail))))
#f
(if(= 'b head)
((let ((count (count - 1)))
(let (( newTail (aequalb tail))))
#f
(if(null? tail)
(if(= count 0)
#t
#f)))))))))))

I know this is completely wrong, but I've been trying so please take it easy on me. Any help would be much appreciated.

© Stack Overflow or respective owner

Related posts about Scheme

Related posts about homework