From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Matt Wette Newsgroups: gmane.lisp.guile.user Subject: Re: What should the constructor for a record look like? Date: Sun, 26 Aug 2018 09:11:42 -0700 Message-ID: References: <1617672.9nuLs2ACSm@aleksandar-ixtreme-m5740> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1535299810 13911 195.159.176.226 (26 Aug 2018 16:10:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 26 Aug 2018 16:10:10 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Aug 26 18:10:06 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 1ftxc6-0003UX-DG for guile-user@m.gmane.org; Sun, 26 Aug 2018 18:10:06 +0200 Original-Received: from localhost ([::1]:49626 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftxeC-0008E6-JM for guile-user@m.gmane.org; Sun, 26 Aug 2018 12:12:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftxdk-0008Dq-M2 for guile-user@gnu.org; Sun, 26 Aug 2018 12:11:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftxdh-0000QO-Ie for guile-user@gnu.org; Sun, 26 Aug 2018 12:11:48 -0400 Original-Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:41808) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ftxdh-0000Q4-AX for guile-user@gnu.org; Sun, 26 Aug 2018 12:11:45 -0400 Original-Received: by mail-pg1-x52a.google.com with SMTP id s15-v6so6305788pgv.8 for ; Sun, 26 Aug 2018 09:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=oaKJXDmN3mv0XgPIS6fy8qvY46FU4jXDHBYWMOS4vhg=; b=Y9PedMit79NaA26ddUWqvMYaLlqlM1WUr1Lh+OSEDWx61bfmey8szpS50CMjJkFjeK uy7lMUSFe8mEKJJK2WQBvGuL3cTss49L4JiWEgOcaITkH1ropTDKfae6mxcrIgEoGa+P CIyxCkeKdWKtaw+vt/su3dt/GCBeU5jsCJXq765dAGcNRFUp50O6Wy6rpXi8EfHF6i4e WV5lnknFBnCqCwjsTSdi6jk1hz8/0aQUeCxZqH77Lu0BnmvPknyI8ok058BtEg3PUMWH d4GAE/Z7zK+oVdYBgVbT+CDYwUmCbp2+X1OnI42jW6LNLwUG6NrGSqynazAJFNuePmLq L8Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=oaKJXDmN3mv0XgPIS6fy8qvY46FU4jXDHBYWMOS4vhg=; b=PpYUwTOBgtwE+obFgs97zdM0l+dluucQhFFT9zzWVS8GNuFLG3EztPQgxwpDydYHLo vHKy+lQDofmnLOzIqeTFhUGGz1q1RdOtTilwLqx+2iaFuAN8vk4RUoJA7KdU2rpB1vD4 BAEi6xn/AnhNAnVkS8EIJ+5BWlIc0eNgokSmeKwOIlDxq7p34rmlAkTFsWl8CwPPvVX2 Rg/LoMN7RYdSC9PD2TGZ5AVnb9hNgGBVk5DyqNGL1PAZw+KAGKjyWMNq3zxnGt/zWR/Q iEM+h7KTpGnlB1CiWAWaRL5GkDYV8/2Su8SStlpHgUdGk6cyfGF6SBzbpauZIDX7O2tY XzBA== X-Gm-Message-State: APzg51Cjrh0x2m9ln1uEThQRObPqgozF4UhQW6EHm22JSd85YJtvTcua lvJip2Noc29tEtF1oI++RXasVNiu X-Google-Smtp-Source: ANB0VdYWbT+eT19ZkXiKZy7JUwdHmcqgMyaQJcZh/9f7eL7n1yR9U3phUPQ7xAAGkYaegMXEca58NQ== X-Received: by 2002:a62:d085:: with SMTP id p127-v6mr10538782pfg.119.1535299904167; Sun, 26 Aug 2018 09:11:44 -0700 (PDT) Original-Received: from [192.168.2.183] (216-165-229-229.championbroadband.com. [216.165.229.229]) by smtp.gmail.com with ESMTPSA id h132-v6sm20649435pfc.100.2018.08.26.09.11.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Aug 2018 09:11:43 -0700 (PDT) In-Reply-To: <1617672.9nuLs2ACSm@aleksandar-ixtreme-m5740> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::52a 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:14760 Archived-At: 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)))