Hi, HiPhish <hiph...@posteo.de> writes:
> I am writing an implementation of MessagePack [1] for Guile and a part of the > spec is the presence of a "nil" data type. What would be a good value to > express "nothing" in Guile? First of all, thank you very much for asking the question. I often wish that authors of Guile libraries would more often ask for design advice here before committing to a particular API. > I cannot use '() because that would be > indistinguishable from the empty list, so I thought that the return value of > a > function that returns nothing would be a good fit. "The return value of a function that returns nothing" is a self-contradictory notion, if you think about it :) > The function `display` for > example returns an `#<unspecified>` value, but the only way of producing it > without side effects so for is the value of `(if #f #f)`. Is there a better > way? *unspecified* is identifier syntax for (if #f #f), i.e. it expands into the latter. However, I would strongly advise against writing code (or worse, APIs) that depend on (if #f #f) or *unspecified* returning a particular distinguished value. Quoting R5RS: If the value of an expression is said to be "unspecified," then the expression must evaluate to some object without signalling an error, but the value depends on the implementation; this report explicitly does not say what value should be returned. It's true that Guile historically has a special object distinct from all other objects, which (if #f #f) and various other expressions return, and which prints as "#<unspecified>". However, the fact that some existing code out there might depend on the existence of this distinguished object, and that certain expressions in Guile return it, is historical baggage which carries non-zero costs as we move to native code generation. I would also argue that it carries a terrible conceptual cost, in that it leads to confusion between the concept of a truly unspecified return value (as in R5RS) and this distinguished value in Guile that is called "the unspecified value", a non-sensical notion. I would also avoid Guile's #nil. That is a very special value, for one purpose relating to Elisp compatibility, and ideally it should not be used for anything else. > In Racket there is the `(void)` [2] procedure which returns a `#<void>` > object, so that's what I am using there [3][4]. Any suggestions for Guile? I would suggest using a symbol. How about 'nil? Mark