LaneL
LaneL

Reputation: 778

Why won't this Scheme function compile?

I have this scheme function that I'm supposed to run lists of integers on but I have no idea what the error means. The error states: "if: expected a question and two answers, but found 4 parts in: (if(null? list) '() (cons (+ 1 (car list)) (f(cdr list)))). What is missing from this function and what on earth does '() do? Thanks! I've never used Scheme before.

(define (f list)
    (if (null? list)
        ’()
        (cons (+ 1 (car list)) (f (cdr list)))))

Upvotes: 1

Views: 116

Answers (2)

hugomg
hugomg

Reputation: 69984

The character you are using to quote the empty list is the right quotation mark , U+2019. Your code works fine if you use the ascii apostrophe ', U+0027

(define (f list)
    (if (null? list)
        '()
        (cons (+ 1 (car list)) (f (cdr list)))))

Upvotes: 3

soegaard
soegaard

Reputation: 31145

You used the wrong quote (maybe a copy paste error?).

Use ' not .

Upvotes: 3

Related Questions