Search code examples
listschemelisp

Guile scheme cond ERROR: Wrong type to apply: (1 2 3 4)


I am playing with scheme and puzzled in to this crazy issue

(define func((lambda N lst)
          (if(eq? N 0) 0 (+ (car lst) 2))))

calling function

(func 2 (list 1 2 3 4 5))

got following error when I called function

ERROR: In procedure (1 2 3 4):
ERROR: Wrong type to apply: (1 2 3 4)

Solution

  • It is a parenthesis issue. It happens quite a lot when beginning with scheme.

    I recommend that you indent your code correctly, it will make it more readable and much less error prone.

    (define func
      (lambda (N lst)
        (if (eq? N 0)         
            0 
            (+ (car lst) 2))))
    

    The extra () you had was translated to a function call