Scheme # void error

吃可爱长大的小学妹 提交于 2019-12-11 05:16:38

问题


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


来源:https://stackoverflow.com/questions/4434638/scheme-void-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!