From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.user Subject: Re: A value for "nothing" Date: Sun, 26 Aug 2018 16:07:13 -0400 Message-ID: <87sh30vqmm.fsf@netris.org> References: <21036238.c6yQEfjfIL@aleksandar-ixtreme-m5740> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1535314027 8176 195.159.176.226 (26 Aug 2018 20:07:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 26 Aug 2018 20:07:07 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: guile-user@gnu.org To: HiPhish Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Aug 26 22:07:03 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fu1JO-0001z7-SJ for guile-user@m.gmane.org; Sun, 26 Aug 2018 22:07:02 +0200 Original-Received: from localhost ([::1]:50237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fu1LU-00069x-KN for guile-user@m.gmane.org; Sun, 26 Aug 2018 16:09:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fu1LA-00069o-L4 for guile-user@gnu.org; Sun, 26 Aug 2018 16:08:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fu1L6-0000rv-HI for guile-user@gnu.org; Sun, 26 Aug 2018 16:08:52 -0400 Original-Received: from world.peace.net ([64.112.178.59]:44116) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fu1L6-0000rn-DX for guile-user@gnu.org; Sun, 26 Aug 2018 16:08:48 -0400 Original-Received: from mhw by world.peace.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1fu1L5-0006qj-7e; Sun, 26 Aug 2018 16:08:47 -0400 In-Reply-To: <21036238.c6yQEfjfIL@aleksandar-ixtreme-m5740> (HiPhish's message of "Sun, 26 Aug 2018 12:13:31 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 64.112.178.59 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14766 Archived-At: Hi, HiPhish 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 `#` 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 "#". 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 `#` > 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