HiPhish
2018-09-13 21:49:10 UTC
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?
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?