If item not in the lst in scheme

Posted by ms. sakura on Stack Overflow See other posts from Stack Overflow or by ms. sakura
Published on 2012-10-12T16:30:54Z Indexed on 2012/10/13 3:37 UTC
Read the original article Hit count: 107

Filed under:

I'm working on context-free grammars, and I have a function that returns the (terminal values of grammar)

for example: i have non-terminal function that results in (A B) , from calling say ((A cat) (B happy np) (A B sad)) so technically A and B are non terminals of the grammar. Now I want to be able to get the terminals (cat happy np sad)

(define terminals
  (lambda (lsts)
    (cond
     ((null? lsts) lsts)
     ((not(member? (car(car lsts)) (n-terminals lsts)))
      (cons (car(car lsts)) (terminals (car (cdr lsts)))))
     (else (terminals (cdr lsts))))))

PS: functionality of n-terminals is described above. member? is a boolean function that returns true if an item is a member of the list, false otherwise. My function returns an empty lst. What am I missing here?

© Stack Overflow or respective owner

Related posts about Scheme