From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.user Subject: RE: Understanding `symbol??` macro from okmij.org Date: Thu, 14 Mar 2024 02:03:07 +0100 Message-ID: <20240314020307.yR322B00F319MNK01R36Mg@andre.telenet-ops.be> References: <9142ff20-0722-4fb7-b35a-7434e68d1777@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29242"; mail-complaints-to="usenet@ciao.gmane.io" To: Zelphir Kaltstahl , Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Mar 14 02:08:44 2024 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 1rkZaM-0007Oc-FH for guile-user@m.gmane-mx.org; Thu, 14 Mar 2024 02:08:42 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkZa3-0004BO-GU; Wed, 13 Mar 2024 21:08:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkZa1-0004AI-Vf for guile-user@gnu.org; Wed, 13 Mar 2024 21:08:22 -0400 Original-Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkZZz-0000XX-Tg for guile-user@gnu.org; Wed, 13 Mar 2024 21:08:21 -0400 Original-Received: from [IPv6:2a02:1808:87:8558:390e:9878:25ff:3c59] ([IPv6:2a02:1808:87:8558:390e:9878:25ff:3c59]) by andre.telenet-ops.be with bizsmtp id yR322B00F319MNK01R36Mg; Thu, 14 Mar 2024 02:03:06 +0100 Importance: normal X-Priority: 3 In-Reply-To: <9142ff20-0722-4fb7-b35a-7434e68d1777@posteo.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=telenet.be; s=r24; t=1710378187; bh=jXajDlnjgYxxDppeR1awCON00auq2mXZWYd+6ZJSwIA=; h=To:From:Subject:Date:In-Reply-To:References; b=UBTVwO1+X2AoDYxyO9Sdn0TVb0A5H7a1FA4QjLDbAyf/vhTOpo4tE1u+bA4fkmQ5K TCG+sMTXbIfXGeDGgw/x93GoCa4z0tFsPJDehsyXrwmBtLJ9q6Q2lmP7QW7IrE/YXu 7P/SJBJ03hqo29xgwp3Ea2MkXv+ka91k68tdaNU5llB6wMmvrGlwv+X7ju1j1MdP/J /lb8wx44ApjNaKWunSGG4IG2KNXGRDX3/hJQwIpcYMFUMYtlXuZqEV6Lk0dBST/W/C ZQZAwlWjoEhuWdX7KIy4pNpIwsPp+jTF2f9TU9ebhDkKrSlklxgqLIrxmSE85r7hlR J5NQqMj6f+IRA== Received-SPF: pass client-ip=2a02:1800:120:4::f00:15; envelope-from=maximedevos@telenet.be; helo=andre.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19461 Archived-At: (define-syntax symbol?? (syntax-rules () ;; The check is done by first pattern matching against some other ;; forms, that are not a symbol. ((symbol?? (x . y) kt kf) kf) ; It's a pair, not a symbol ((symbol?? #(x ...) kt kf) kf) ; It's a vector, not a symbol The first two cases don=E2=80=99t need any explanation I think. ;; After those things are excluded, the thing might be a symbol. ((symbol?? maybe-symbol kt kf) (let-syntax ((test (syntax-rules () ((test maybe-symbol t f) t) ((test x t f) f)))) (test abracadabra kt kf))))) If maybe-symbol is a symbol, then (test abracadabra kt kf) matches (test ma= ybe-symbol t f) (let t=3Dkt, f=3Dkf, maybe-symbol=3Dabracadabra). If maybe-symbol is not a symbol, for example it is a string =E2=80=9Chello= =E2=80=9D (please ignore wrong quoting), then (test maybe-symbol t f) becomes (test =E2=80=9Chello=E2=80=9D t f). The st= ring =E2=80=9Chello=E2=80=9D cannot act as an identifier (because it is a s= tring, not a symbol), so (test abracadabra kt kf) does not match the first = case (test maybe-symbol t f). Only the second case (test x t f) remains, an= d (test abracadabra kt kf) matches this (set x to abracadabra, t to kt, f t= o kf). I think the first two cases are superfluous, but perhaps there is a perform= ance advantage. (I=E2=80=99m wondering if this still works in the case (symbol? ...), becau= se ... is special in syntax-rules) Best regards, Maxime Devos.