What's the return value of `define` in Scheme?

断了今生、忘了曾经 提交于 2020-01-04 13:39:59

问题


I'm curious about the return value of define in Scheme. So I wrote the following lines in Racket

#lang r5rs
(display (define a 3))

And get the error

 define: not allowed in an expression context in: (define a 3)

I have 2 questions about this:

  1. Does it mean that define has no return value?
  2. According to R5RS, define is not an expression. It's a program structure. Is it true that only expressions have return values, and other forms don't?

回答1:


"If a tree falls in a forest and no one is around to hear it, does it make a sound?"

It's not valid to use define in any context where a return value could meaningfully be obtained. So it's moot whether it has a return value or not; you'll never be able to observe it.




回答2:


In Scheme, define can only be used in two places:

  1. At the top level, or
  2. At the very beginning of a "body".

In neither of those places is a "return value" relevant.



来源:https://stackoverflow.com/questions/18799032/whats-the-return-value-of-define-in-scheme

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