From: Matt Wette <matt.wette@gmail.com>
To: guile-user@gnu.org
Subject: Re: What should the constructor for a record look like?
Date: Sun, 26 Aug 2018 09:11:42 -0700 [thread overview]
Message-ID: <ba323fb1-35e1-90a4-b86b-1284abe73064@gmail.com> (raw)
In-Reply-To: <1617672.9nuLs2ACSm@aleksandar-ixtreme-m5740>
On 08/26/2018 06:04 AM, HiPhish wrote:
> Hello, it's me again, the guy who wants to implement MessagePack [1] in Guile.
> The specification defines a type of "extension" [2], a pair of an 8-bit
> integer and a byte array for data. Implementing this type as a record is
> obvious, but what should be the name of the constructor?
>
> (define-record-type ext
> (make-ext type data)
> ext?
> (type ext-type)
> (data ext-data))
>
> Either `make-ext` or just `ext` seem appropriate. I have seen both types of
> constructors, what do you guys say? And while I'm on the topic, what about
> types? An extension is only valid if the first field (type) is an integer from
> -128 to 127 and the data a vector of bytes (integer in the range from 0 to
> 255). How do I enforce this invariant without static typing?
>
> [1] https://msgpack.org/
> [2] https://github.com/msgpack/msgpack/blob/master/spec.md#ext-format-family
>
I like make-ext vs ext.
I assume you are using bytevectors for the data. You could "enforce" that type in
the record by using a separate definition of `ext?'.
(define-record-type ext
(make-ext type data)
ext-record?
(type ext-type)
(data ext-data))
(define (ext? obj)
(and (ext-record? obj)
(integer? (ext-type obj))
(bytevector? (ext-data obj)))
next prev parent reply other threads:[~2018-08-26 16:11 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-26 13:04 What should the constructor for a record look like? HiPhish
2018-08-26 16:11 ` Matt Wette [this message]
2018-08-27 12:22 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ba323fb1-35e1-90a4-b86b-1284abe73064@gmail.com \
--to=matt.wette@gmail.com \
--cc=guile-user@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).