(define fun4
(lambda ( ls)
(cond ((null? ls ) #f)
(cons (((eqv? 'a (car ls))) && ((eqv? 'b (cdr ls)))))
(else (pattern2 cdr ls)))))
In this it showing error - procedure application: expected procedure, given: #t (no arguments), What is the erroe in my code. Is logic is fine ???
So much wheel reinvention. Just use SRFI 1!
(This operates under the assumption that
(a b a)
should be valid rather than invalid.)Running:
There are many, many errors in your solution. Let's see what's wrong in each of the conditions:
#f
immediately, and notice how we usecadr
for accessing the second element, because&&
doesn't work in Scheme, you must useand
for the logical and operation. Also you have unnecessary, erroneous parentheses surrounding each test (by the way: those were the ones causing the "expected procedure" error)cddr
. Also you must callfun4
to advance the recursion, notpattern2
This is the correct way to solve the problem, notice how the above issues were addressed:
Always test your procedures, the above will work correctly:
As a final note, if the empty list is not supposed to follow the pattern, then check for it before calling
fun4
and return#f
if the initial input list is empty.