From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: What should the constructor for a record look like? Date: Mon, 27 Aug 2018 14:22:38 +0200 Message-ID: <87pny49ey9.fsf@gnu.org> References: <1617672.9nuLs2ACSm@aleksandar-ixtreme-m5740> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1535372474 12378 195.159.176.226 (27 Aug 2018 12:21:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 27 Aug 2018 12:21:14 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Aug 27 14:21:10 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 1fuGW5-00037g-CH for guile-user@m.gmane.org; Mon, 27 Aug 2018 14:21:09 +0200 Original-Received: from localhost ([::1]:52969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuGYB-0002vU-N1 for guile-user@m.gmane.org; Mon, 27 Aug 2018 08:23:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59433) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fuGXp-0002vM-FK for guile-user@gnu.org; Mon, 27 Aug 2018 08:22:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fuGXk-0002E3-Ds for guile-user@gnu.org; Mon, 27 Aug 2018 08:22:57 -0400 Original-Received: from [195.159.176.226] (port=40307 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fuGXk-0002CE-50 for guile-user@gnu.org; Mon, 27 Aug 2018 08:22:52 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fuGVZ-0002R3-RE for guile-user@gnu.org; Mon, 27 Aug 2018 14:20:37 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 45 Original-X-Complaints-To: usenet@blaine.gmane.org X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 10 Fructidor an 226 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Cancel-Lock: sha1:VIqL/uR5yBwlnbRSGBmjDM6ENhU= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 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:14780 Archived-At: Hi, HiPhish skribis: > 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. For immutable records (which should be the norm :-)), I often leave out ‘make-’ nowadays. (The analogy is ‘string’ vs. ‘make-string’, for instance.) > I have seen both types of constructors, what do you guys say? And guys and gals :-) > 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? You could enforce it by not exporting the raw record constructor, and instead exporting a procedure that performs all the necessary checks: (define-record-type (%ext type data) ;private ext? …) (define (ext type data) ;public (assert-valid-arguments type data) (%ext type data)) HTH! Ludo’.