Roberto Rossi
Roberto Rossi

Reputation: 11

Scheme # void error

I tried running the following scheme code:

(define affiche-gagnant 
  (lambda (j1 j2 g1 g2)
    (begin 
      (display "Le gagnant est : ")
      (display 
       (cond ((> g1 g2) j1) 
             ((< g1 g2) j2) 
             (else (begin (display "personne. ") (display j1) (display " et ") (display j2) (display " sont exaequos. "))))))))

But I get the following output:

Le gagnant est : personne. Alper et Ezgi sont exaequos. #<void>

Where did the #void come from? How do I get rid of it?

Upvotes: 1

Views: 3037

Answers (2)

Lambda Fairy
Lambda Fairy

Reputation: 14734

In some implementations of Scheme, any function that shouldn't return anything (such as begin, define, set!) actually returns a special value #<void>. It is an error to display such a value. In your case, it was an extra "display".

(define affiche-gagnant 
  (lambda (j1 j2 g1 g2)
    (begin 
      (display "Le gagnant est : ")
      (cond
        ((> g1 g2) j1) 
        ((< g1 g2) j2) 
        (else (begin (display "personne. ") (display j1) (display " et ") (display j2) (display " sont exaequos. ")))))))

Upvotes: 0

F. P.
F. P.

Reputation: 5086

Oops, wrong answer. You have an extra display:

(define affiche-gagnant 
  (lambda (j1 j2 g1 g2)
    (begin 
      (display "Le gagnant est : ")
       (cond ((> g1 g2) (display j1)) 
             ((< g1 g2) (display j2)) 
             (else (begin (display "personne. ") (display j1) (display " et ") (display j2) (display " sont exaequos. ")))))))

Should work.

Upvotes: 2

Related Questions