An if
can only have one expression as the consequent, and one as the alternative. If you need more than one you have to use a begin
to enclose the sequence of expressions - surrounding the expressions with ()
won't work, and that's causing the error reported, because Scheme interprets ()
as function application. This would be the correct syntax:
(define (threes var)
(if (atom? var)
(begin
(newline)
(display "Bad input")))
(append (listful (car var)))
(if (> 3 (length var))
(begin
(threes (cffffdr (listful)))
(listful))))
… However, that's unlikely to work. What you want to do has been asked a couple of times in the last days, in particular here is my own previous answer:
(define (threes lst)
(cond ((or (null? lst) (null? (cdr lst))) lst)
((null? (cdr (cdr lst))) (list (car lst)))
(else (cons (car lst)
(threes (cdr (cdr (cdr lst))))))))
For example:
(threes '(a b c d e f g h i j k l m n o p))
=> '(a d g j m p)
See the original question for other ways to solve the problem, with detailed explanations.