Hello all,

I had to write a program that would take a list and check for alternate atoms and list, if there were two atoms in a row, it would #f, same for two lists. I now need to make it #f for 3 in a row. This is what I did for the first ass.

#lang scheme
(define a (list 1 (list 2 3) 1  (list 2 3) 4)) ;one list
(define b (list (list 2 3) (list 2 3) 4)) ;one list
(define c (list 1 (list 2 3) 1 (list 2 3) 4)) ;one list
(define d (list 1 1 (list 2 3) 1 (list 2 3) 4)) ;one list
(define e (list 1)) ;one list


(define (altlis lis1)         
          
(if (list? (car lis1)) 
    (if (list? (car(cdr lis1))) 
        (quote(false)) 
        (altlis (cdr lis1)
                )
        ) 
    (if (null? (cdr lis1)) (quote(true))
        (if (list? (car(cdr lis1))) 
            (altlis (cdr lis1)) 
            (quote(false)))
        )
    )     
  
)

(altlis e)

I cannot figure this out to catch the third one, any help will be appreciate it as I have NO experience with scheme prior to this class I am taking.

Thanks

First, make your life easier by making a function

(define (name x)
  (cond ((pair? x) 'pair)
        ((symbol? x) 'symbol)
        (else (error "i don't know how to handle this case"))))

Once you have this, make a recursive function that takes three arguments: a symbol (whose value is 'pair or 'symbol), an integer saying how many times that kind of thing occurred before the start of the current list, and a list of stuff.

Rashakil,

Thank you. I did think about that even for the first program, however for some reason I think he only wants a list passed as a parameter. Your suggestion takes a lot of the complication away so I will try to implement and discuss with the professor.

I have modified the code above to what I need, since everything is a list essentially I will always pass just the car of whatever is next - It seems to be working with a couple of examples, now I will work on the main recursive function:

(define (name x)
  (cond ((not(pair? x)) 'atom)
        ((list? x) 'list)
        (else (error "i don't know how to handle this case"))))

Wanted to let you know that it looks like I completed it. Thank you!

It's a good thing, because I'm banned and wasn't going to give any further help.

Wow, why? you were great help... Anyway.. i read his requirements, he wanted one parameter function... So I did another function passed it the list and made that call my function with 3 paramaters lol :)

Oh, it was because Ken Hess made some racist comments on his blog and Rashakil (me) called him out on it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.