From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: John Cowan Newsgroups: gmane.lisp.guile.user Subject: Re: Implementing a "write" method for self-evaluating objects (by equal?) Date: Thu, 17 Sep 2020 16:17:58 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21868"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: divoplade Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Sep 17 22:19:14 2020 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 1kJ0N8-0005Zx-Nl for guile-user@m.gmane-mx.org; Thu, 17 Sep 2020 22:19:14 +0200 Original-Received: from localhost ([::1]:57344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kJ0N7-0006X4-QK for guile-user@m.gmane-mx.org; Thu, 17 Sep 2020 16:19:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kJ0M9-0005wK-EY for guile-user@gnu.org; Thu, 17 Sep 2020 16:18:13 -0400 Original-Received: from mail-qv1-xf2e.google.com ([2607:f8b0:4864:20::f2e]:40742) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kJ0M6-0000Sh-BB for guile-user@gnu.org; Thu, 17 Sep 2020 16:18:13 -0400 Original-Received: by mail-qv1-xf2e.google.com with SMTP id j3so1669766qvi.7 for ; Thu, 17 Sep 2020 13:18:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ccil-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RdGHpLSEwaFRF7zH8mTsJzRBUmR0QMnIxws1l0moc9A=; b=NaCJmKho0/fDwdzlQzZrTrsbyR8+b5QD9Ae/tNLarx3bE3jtQBmwTYNVr5BqyBqO8i Ru9yGRZ4kG6z2CK6gJWh5cpU2LPymIBdr12eYQbGiGjWR+Ou2Grcg8bvcPv79lc2BIP+ Xny0WAiDuUQ8EbqyWMkyc5NUeN2xdutLLl0CWCBtuPFGVPcS09QQUe9CHc75ZRnDAvNm D+IJaFxGLAxBS6kdXz03PgKNPRgisUJNgjCUT+J1Jyu7X10ZGNPwBratvQpE8Sfzc9A1 E2MKuWbz/YWYZf7CE34Lot5l9MrOGnBD7/Rfqo/0WWCK0VzfUSqf/l8jAW9+VV9mXveh xfZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RdGHpLSEwaFRF7zH8mTsJzRBUmR0QMnIxws1l0moc9A=; b=MDvE6ITPNvAcO883wJdfXYPftzzpKPtve+Kul7Xlxqkg3/YhUTqUeAeuPIa1rpLO/Y +adEc0eVtE5pF/Mt/13H8hK6Xm+Ri6Ub2iQc/6Xn+SzxUrMgzrNCNaCMskhAxnBo5Q7s tX4DPPZ+K/MmPXg87xDKuY+LrbNQsCwPE4DUb/+r+41k7/Hi5RE3Sb1CPJ3RoMjRcxc+ e9N9RCVwtnogsbJg1U5J+fabLMyYjyWHjQKOFI+oC3mEuf7cYeVfq6mKpR/ikhfZxgiH Lz36TGMU3m6avS1rSMhX7Vc+wm9YrVv8TdfEMGaxW8om16+8VWxVG3Zt7QJ5D1uLNVDB gzzA== X-Gm-Message-State: AOAM533M20zsfwXkxeTgsJHZkAIAqMbLCyC7rRVs8MFoOV+hXMF3oSM6 gob1jL8aZyRfLbx8kRV6d2VydHaOC8wL1Ba07S3fTLKqmQCjbg== X-Google-Smtp-Source: ABdhPJxIRQ6UdaTF4FiWEx/CrEVyKrt38WxpXMJoLRkrf1u2OxU3VG04o8fECClEhOlf0aKT6Z0p3/qoBfLjhlshqB0= X-Received: by 2002:a0c:e5cf:: with SMTP id u15mr29713296qvm.24.1600373888805; Thu, 17 Sep 2020 13:18:08 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::f2e; envelope-from=cowan@ccil.org; helo=mail-qv1-xf2e.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:16918 Archived-At: In general you want to print records but not make them readable, as there are often constraints against allowing arbitrary values in the fields. For example, in SRFI 117 list queues, there are two fields named head and tail. Either both must be the empty list, or they must both be pairs and tail must be a tail of head: that is, if you apply cdr to head repeatedly, you will eventually get a value that is eq? to tail. Allowing other random values to be read in would break the SRFI 117 procedures. On Thu, Sep 17, 2020 at 4:12 PM divoplade wrote: > Hello guile users, > > In the manual, I read: > > (define-method (write (file ) port) > (format port "#< ~s ~a>" (name file) (fd file))) > > So it is possible to define a write method for foreign objects (and > more generally GOOPS classes). > > My question is: why use such a bizarre syntax with # and not be better to make it self-evaluating: > > (format port "(make #:fd ~a #:name ~s)" > (fd file) (name file)) > > This is a little more verbose, but at least the syntax explains how to > construct the value. There must be some cases where it would not be > possible (such as pointers to opaque data that do not have a > constructor...), and it would break if for instance "make" is renamed > to something else. However, if I were to implement a write method, I > would use this, a textual representation of a constructor that would > produce the same value (according to equal?). > > >