From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Taylan Kammer Newsgroups: gmane.lisp.guile.user Subject: Re: Guix records Date: Wed, 10 Feb 2021 00:14:19 +0100 Message-ID: References: <87lfc2e9vn.fsf@clara> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27275"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 To: Olivier Dion , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Feb 10 00:14:43 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l9cDT-0006y2-An for guile-user@m.gmane-mx.org; Wed, 10 Feb 2021 00:14:43 +0100 Original-Received: from localhost ([::1]:57174 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l9cDS-0001ay-3F for guile-user@m.gmane-mx.org; Tue, 09 Feb 2021 18:14:42 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l9cDF-0001aq-QQ for guile-user@gnu.org; Tue, 09 Feb 2021 18:14:29 -0500 Original-Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]:35794) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l9cDA-0004JZ-Cu for guile-user@gnu.org; Tue, 09 Feb 2021 18:14:29 -0500 Original-Received: by mail-ed1-x532.google.com with SMTP id g10so415864eds.2 for ; Tue, 09 Feb 2021 15:14:23 -0800 (PST) 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-language:content-transfer-encoding; bh=MmmInGIvPTCGu5jeQ/VprYhLNrLEeWgNIAtJ30e6ww8=; b=Gj5t1UU9axRNROoslkQlCjAE92+e4r94D0lERkBLJwl7sSuhexgw9N99PynGqyEjWx TDSRdSpmsX1WbIX5ue+MJ21xWTNtS5bVSnv8ke3bGLQC4yTfej3eKrL7Y7beKBMGhfkc vc+/0nhb4D4ShMpnHYjNY0u4wqCqyK7kVozfDek0DZuaGJ/OM9ikmciuaZel76P9pez8 4reMF6ClXp7PL/hGyw//cIdb0WZ9Y//Cbw+Qq2tzoo9TNUz/pJ/U7+qKCc2/pY80caUg EJqQeTaV8iog5XAtcUQ1mskjfOfynmDhKOqOlI6OFQvpcEGtQZnsLbR0QTtr+9Z7VWdu +zbA== 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-language :content-transfer-encoding; bh=MmmInGIvPTCGu5jeQ/VprYhLNrLEeWgNIAtJ30e6ww8=; b=PmsKyOHzPnOLtQJTLl/0b5S6Ma4C00o4HGq4vDuvc+2FjOsJmJ40iCFg+EYf8gghGb tWCZZhmj8/8WGVmtMiVrHwYuqAnjShnvuHp6WxRl33yCjLfm6Y4WT2Ni2kh13haE7em9 cs0PZR1032FiWYAaoO2PlqVvjPVdDZJdxPvIpJ6VfmjHhLhtxIsQY48xIacHJiIdlMm5 FxfCcz7gfKoR1KHdSJn2NUwkwgbgzuRXnXEbT5fnkQ6WBkL7vUUemK4+1ZE5a4M7VOxd whVzm7QS0BWuJZQZn0lJDlZKewmFhg1dB6vrZNK7nbyePEgVrvVxR2pO7MF6EAJqfIc+ 7PBA== X-Gm-Message-State: AOAM5320axJym4pdE9X0cpyg2Kp87J7exwl54MWim26atzgP5iVXi9YM Hm9bi1VYUJby5X1Ov4kg2AoFmv15uXU= X-Google-Smtp-Source: ABdhPJxpDq2ePX6fB3N4K1XTFnqr+I7Ct8UKBQ7+e8/lhabs1GHKyBF4WFqM88SPmnO2sfz94+22Aw== X-Received: by 2002:a50:d51d:: with SMTP id u29mr453418edi.167.1612912461983; Tue, 09 Feb 2021 15:14:21 -0800 (PST) Original-Received: from [192.168.178.20] ([109.90.125.150]) by smtp.gmail.com with ESMTPSA id a9sm12440136edk.22.2021.02.09.15.14.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 Feb 2021 15:14:21 -0800 (PST) In-Reply-To: <87lfc2e9vn.fsf@clara> Content-Language: en-US Received-SPF: pass client-ip=2a00:1450:4864:20::532; envelope-from=taylan.kammer@gmail.com; helo=mail-ed1-x532.google.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.265, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17233 Archived-At: On 05.02.2021 17:51, Olivier Dion via General Guile related discussions wrote: > Hello, > > In the module (guix records), there's some very nice syntax rule > `define-record-type*` that allows very powerfull declarative style of > records. For example: > ---------------------------------------------------------------------- > (employee > (age 30) > (name "Foo") > (profession "Teacher")) > ---------------------------------------------------------------------- > > I would like to use this feature in my software. However, I don't want > to have Guix as a dependency only for that. For now, I've copied the > content of (guix records) into (my-software records). But this put > burden of maitenance into my hands. > > Thus, I'm looking for an alternative, perhaps there's a Guile library > (other than Guix' module) or a SRFI that offers similar feature? > The most feature-rich record system supported by Guile is probably the R6RS record system, which is available through the modules: (rnrs records syntactic (6)) (rnrs records procedural (6)) (rnrs records inspection (6)) However, it doesn't allow a definition style like in your example, where you explicitly name the fields that you're assigning values to during instance creation. It does, however, implicitly define getters (and setters for mutable fields). The Guile documentation is brief. You might want to read the R6RS spec or search for another guide for detailed explanations and examples of how to use the R6RS record system, if it sounds interesting. Note that it's quite dissimilar to the SRFI-9 system, and some aspects of it are rather complex, which is why many people don't like it. To be honest I find some of those complex features quite ingenious on paper, though I couldn't say how often they would prove to be useful in practice. Here's a super brief example usage of R6RS records, demonstrating that field accessors are defined implicitly, but constructors still use an unnamed sequence of arguments to assign fields: (import (rnrs records syntactic (6))) ; must use 'import' for R6RS (define-record-type (cat make-cat cat?) (fields name age color)) (define garfield (make-cat "Garfield" 42 'orange)) (cat-color garfield) ;=> orange Then there is SRFI-99 which could be seen as an update to SRFI-9, but last I checked it's not in Guile yet. It also doesn't really feature the declarative style like in your example. - Taylan