Scheme # void error

2019-08-10 20:57发布

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?

标签: scheme void
2条回答
聊天终结者
2楼-- · 2019-08-10 21:30

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.

查看更多
Luminary・发光体
3楼-- · 2019-08-10 21:32

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. ")))))))
查看更多
登录 后发表回答