3
scheme@(guile-user)> (define val (when #f 1))
scheme@(guile-user)> val
scheme@(guile-user)> (null? val)
$6 = #f
scheme@(guile-user)> (boolean? val)
$7 = #f
scheme@(guile-user)> (pair? val)
$8 = #f
scheme@(guile-user)> (when val 1)
$9 = 1

It does evaluate to #t but what is it?

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Ernest A
  • 7,526
  • 8
  • 34
  • 40

1 Answers1

4

update: the docs says: "When ... the test evaluates to #f, the value of the expression is not specified." So it might be anything, and shouldn't be relied upon for anything.


It returns a value which is not null?, not boolean? and not pair?:

scheme@(guile-user)> (null? val)
$6 = #f
scheme@(guile-user)> (boolean? val)
$7 = #f
scheme@(guile-user)> (pair? val)
$8 = #f

It is not an #f, as evidenced by

scheme@(guile-user)> (when val 1)
$9 = 1

And it prints as nothing,

scheme@(guile-user)> val
scheme@(guile-user)> 

So what is it? A value is defined by its interactions. Its internal representation in a specific implementation is not that important.

Short answer is, it is a "not a value". (sic)

Chez Scheme prints it as #<void>:

(define val (when #f 1))
(display val)
; Output:
#<void>

And Guile 2.0.13 at ideone.com prints it as #<unspecified>.

Will Ness
  • 70,110
  • 9
  • 98
  • 181
  • So, if it is not a value, why in [Guile Reference Manual](https://www.gnu.org/software/guile/manual/html_node/Definition.html#Definition) it is said “To define a new variable, you use Scheme’s define syntax like this: `(define variable-name value)` This makes a new variable called `variable-name` and stores `value` in it as the variable’s initial value.” ? – Renzo Nov 04 '18 at 16:14
  • @Renzo obviously I was being poetic more than I was being rigorous. :) maybe it's "not a value to be used anywhere". a special kind of value that is not a value in the same sense as a null pointer is not really a pointer. I dunno. :) – Will Ness Nov 04 '18 at 16:16
  • Ok, I was just curious! – Renzo Nov 04 '18 at 16:16
  • but actually, it doesn't change anything. `(when #f 1)` must return something; but it shouldn't return anything of value. what's the poor thing to do? return a special something which really is nothing. hence the "a" in "*a* 'not a value'". – Will Ness Nov 04 '18 at 16:18
  • I find Chez Schema more coherent with a vision of values returned by expressions (and this is an almost universal case): what an expression returns is something which is called a value, be it # or #null or NIL or () or whatever, which has some role in the data system of the language. Otherwise the variable `val` is associated to something, which is not a value (but if a variable is initialized it is initialized to a value...) – Renzo Nov 04 '18 at 16:24
  • I bet there's something specific in the Report about this, but I'm also pretty sure it won't change this explanation in a very significant way. What my answer is actually saying is, "this is self-evident, and it also makes sense". – Will Ness Nov 04 '18 at 16:27
  • btw Guile is returning some value too; it just might be that the OP's specific version's way of *printing* such values is to print nothing. ideone.com prints `#`. (I've edited that in, thanks). – Will Ness Nov 04 '18 at 16:38
  • Yes, I think you are correct that this is a special value simply not printed by default. For instance [Chez Scheme](https://www.scheme.com/csug8/objects.html) uses the term “Void object”, while [Racket](https://docs.racket-lang.org/reference/void.html?q=void) uses explicitly “#void value", or "constant #void" (and prints always it). Now it remains only to find the name of its type... :) – Renzo Nov 04 '18 at 16:45
  • Does guile have documentation that "It returns a value which is not null?, not boolean? and not pair?"? The scheme reports, by design, underspecifies it so anything goes. Guile documentation for `define` doesn't specify what it returns, only the side effect it provides. It might do `#t` every odd line number and `#` the other times. One should not rely on underspecified behaviour. – Sylwester Nov 04 '18 at 19:14
  • @Sylwester you're right, of course. I was being too light-minded with this. the bottom line is the same though: it doesn't matter what it is, as it shouldn't ever be used for anything. but I wasn't clear enough about this. – Will Ness Nov 04 '18 at 19:39