Scheme # void error

2019-08-10 20:43发布

问题:

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?

回答1:

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.



回答2:

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. ")))))))


标签: scheme void