unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* A value for "nothing"
@ 2018-08-26 10:13 HiPhish
  2018-08-26 17:21 ` Thomas Morley
                   ` (6 more replies)
  0 siblings, 7 replies; 42+ messages in thread
From: HiPhish @ 2018-08-26 10:13 UTC (permalink / raw)
  To: guile-user

Hello Schemers,

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? 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 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?

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?

[1] https://msgpack.org/
[2] http://docs.racket-lang.org/reference/void.html?q=void
[3] https://gitlab.com/HiPhish/MsgPack.rkt/blob/master/msgpack/unpack.rkt#L47
[4] https://gitlab.com/HiPhish/MsgPack.rkt/blob/master/msgpack/pack.rkt#L35





^ permalink raw reply	[flat|nested] 42+ messages in thread
* Re: A value for "nothing"
@ 2018-08-26 20:25 HiPhish
  0 siblings, 0 replies; 42+ messages in thread
From: HiPhish @ 2018-08-26 20:25 UTC (permalink / raw)
  To: jbranso; +Cc: guile-user

The main advantage of JSON is that it is human-readable. This is great if you 
want to save the data on disc and be able to get it without needing special 
software, or if you want to write it out by hand but be able to parse it by a 
computer. I actually had done that, I maintained a number of records by hand 
and use a small script to splice the data in a modified form into a LaTeX 
document.

However, being text-based becomes a liability when there is no need for human 
readability. For instance, if you want to send data between processes there 
will never be a human who will eyeball it, size and parsing efficiency are 
much more important. JSON is non-trivial to parse.

I am writing this implementation of MessagePack because I want to be able to 
write a Neovim client for Guile. This will effectively allow writing Neovim 
plugins in Guile: Neovim launches an external Guile process and the two 
processes communicate via RPC using MessagePack as the protocol. This way 
Neovim can be retrofitted with any language for writing plugins; old Vim 
needed be be compiled with support for foreign scripting languages baked into 
the binary.





^ permalink raw reply	[flat|nested] 42+ messages in thread
* Re: A value for "nothing"
@ 2018-09-13 21:49 HiPhish
       [not found] ` <CAD2gp_Sg-aDXZKfOcL-i2py7ne4c0Cp+2HvKS4DYi1Antm_B1A@mail.gmail.com>
  0 siblings, 1 reply; 42+ messages in thread
From: HiPhish @ 2018-09-13 21:49 UTC (permalink / raw)
  To: guile-user

After taking the advice from the mailing list users this is what I have come 
up with:

    (define-module (msgpack nil)
      #:use-module ((srfi srfi-9) #:select (define-record-type))
      #:export (nil? (get-nil . nil)))
    
    (define-record-type nil
      (make-nil)  ; The raw constructor will not get exported
      nil?)
    
    (define get-nil  ; This will be renamed on export
      (let ((the-nil (make-nil)))  ; Singleton instance
        (λ ()
          "- Scheme procedure: nil
      Return the unique object representing nothingness in MessagePack.
      
      All calls to this procedure return objects which are 'eq?' to each 
other."
          the-nil)))

The procedure `get-nil` gets exported as `nil` and returns a singleton 
instance of my `nil` type. This way `(eq? (nil) (nil))` is always `#t`. The 
only issues is that the `nil?` predicate collides with Guile's own `nil?` 
predicate, so users will have to prefix or rename it when importing. I would 
prefer not to export these two procedures with prefixes like `msgpack-nil` out 
of the box, it's really ugly :/ What is the difference between `nil?` and 
`null?` anyway? The former is not listed in the procedure index of the Guile 
manual.

What do you think?





^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2018-09-15 22:45 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-26 10:13 A value for "nothing" HiPhish
2018-08-26 17:21 ` Thomas Morley
2018-08-26 17:27 ` Joshua Branson
2018-08-26 17:49 ` John Cowan
2018-08-27  4:52   ` Mark H Weaver
2018-08-27 13:00     ` John Cowan
2018-08-27 21:29       ` Mark H Weaver
2018-08-27 21:32       ` Mark H Weaver
2018-08-26 20:07 ` Mark H Weaver
2018-08-26 22:08   ` Matt Wette
2018-08-27  8:04   ` tomas
2018-08-27 20:12     ` Mark H Weaver
2018-08-27 20:46       ` Mark H Weaver
2018-08-28  0:50         ` Matt Wette
2018-08-28  6:58           ` Mark H Weaver
2018-08-28 15:19             ` John Cowan
2018-08-28 15:38               ` Mark H Weaver
2018-08-28 15:59                 ` Mark H Weaver
2018-08-28 16:12                 ` John Cowan
2018-08-28 17:15                   ` Mark H Weaver
2018-08-28 19:07                   ` Mark H Weaver
2018-08-27 20:54       ` Hans Åberg
2018-08-27  0:17 ` Panicz Maciej Godek
2018-08-27  8:02   ` tomas
2018-08-27  8:29     ` Panicz Maciej Godek
2018-08-27  8:29   ` HiPhish
     [not found] ` <8840615.kRvQfVdCvZ@aleksandar-ixtreme-m5740>
     [not found]   ` <CAD2gp_QLqd=_RbF=HTEbCLp1onmUq-c74g0FXTvMgdz8JB4-8A@mail.gmail.com>
2018-08-27  8:24     ` HiPhish
     [not found] ` <3467110.H24gZIzStD@aleksandar-ixtreme-m5740>
     [not found]   ` <87ftz0vidc.fsf@netris.org>
2018-08-27  8:40     ` HiPhish
2018-08-27 12:37       ` Ludovic Courtès
2018-08-27 19:49         ` Mark H Weaver
2018-08-28  7:52           ` Ludovic Courtès
  -- strict thread matches above, loose matches on Subject: below --
2018-08-26 20:25 HiPhish
2018-09-13 21:49 HiPhish
     [not found] ` <CAD2gp_Sg-aDXZKfOcL-i2py7ne4c0Cp+2HvKS4DYi1Antm_B1A@mail.gmail.com>
2018-09-14 22:45   ` HiPhish
2018-09-15  0:26     ` John Cowan
2018-09-15 14:50       ` HiPhish
2018-09-15 18:28         ` Keith Wright
2018-09-15 21:50           ` Edwin Watkeys
2018-09-15 22:16             ` HiPhish
2018-09-15 22:23               ` Edwin Watkeys
2018-09-15 22:13           ` HiPhish
2018-09-15 22:45       ` David Pirotte

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).