From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id OMaMAcD7v2XQ9QAAqHPOHw:P1 (envelope-from ) for ; Sun, 04 Feb 2024 22:04:00 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id OMaMAcD7v2XQ9QAAqHPOHw (envelope-from ) for ; Sun, 04 Feb 2024 22:04:00 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=telenet.be header.s=r24 header.b=YER98i8Q; spf=pass (aspmx1.migadu.com: domain of "help-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="help-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1707080639; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=T8/3su7ZZy5INprOmPPlaMePAvmozJneL0KLdYtCGZ0=; b=VE3iMJeik+EWCgftnOUP1PE+anrWbA6quaAp5mAne47OvoumxGMhw8K5rtk2RpjhPBh2u8 xNBpxpojqGbBetP6RKUSVSFkIGTrAamIinkHXBtKeOfclOqTAaI713fe2vEUdJAFw/3QMD RukhbJX1aZanuzacWAzeERmezt119pu/rpxqe9xEvKk/iickA5reiIbR6C7gcEpqxQsDZ1 u0R+w1o3UPoi3YgAeXZtGzfsHqNfMrjhZY213nRXHfdzrREfUkcHPnXWyvx1cEqnM0kfDu sVa7WUVtwv+9Jvd+FNu7h7g4/LcZBlK8dAmAkrKWCwK/V896LDvSrMDIyd63gQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=telenet.be header.s=r24 header.b=YER98i8Q; spf=pass (aspmx1.migadu.com: domain of "help-guix-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="help-guix-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1707080639; a=rsa-sha256; cv=none; b=sw8M8kgVZT5h01CVEqSBaWOBwfZGCEPlf8fXNBjokAoUDJmKrcnLlZ7jh0z3GtIbos2d6N SYwuktO54CUWvhaOt0tcYQmOtnoTgUxtpEpSuWpKO6Bv9htGOS6HK6SBH2KLFoshuHk4PT BzsReYpvWYwatKaAG2GRBGsYlG/lEEniKwDOuLwhhshQU88sP8R7OjvNbgK77PrWV3DCTG WRksnbjP67/itnHlB+3byLQkzfvMTxDyJeubhGrPofhosbd1nw129TH8y+FAKYu3NCzkzO iJ8p6RptGttC32k4u2CW1L7NHSzHVbq/l9Qfmcqu+BgoEm71MPAt3QkAPh+TQA== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id AEF7E3AAD1 for ; Sun, 4 Feb 2024 22:03:59 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWjeN-000513-6P; Sun, 04 Feb 2024 16:03:39 -0500 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 1rWjeL-0004xE-5G for help-guix@gnu.org; Sun, 04 Feb 2024 16:03:37 -0500 Received: from laurent.telenet-ops.be ([2a02:1800:110:4::f00:19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rWjeH-0006Eb-1J for help-guix@gnu.org; Sun, 04 Feb 2024 16:03:36 -0500 Received: from [IPv6:2a02:1811:8c09:9d00:e5aa:e8c2:b860:4c97] ([IPv6:2a02:1811:8c09:9d00:e5aa:e8c2:b860:4c97]) by laurent.telenet-ops.be with bizsmtp id j93T2B00C1cshW70193U6r; Sun, 04 Feb 2024 22:03:28 +0100 Message-ID: <20240204220328.j93T2B00C1cshW70193U6r@laurent.telenet-ops.be> MIME-Version: 1.0 To: Christina O'Donnell , "guile-user@gnu.org" Cc: "help-guix@gnu.org" From: M Subject: RE: Getting all symbols in a Scheme file as a list Date: Sun, 4 Feb 2024 22:03:28 +0100 Importance: normal X-Priority: 3 In-Reply-To: <03f7199a-daf2-e070-8156-6837d7e20e32@mutix.org> References: <03f7199a-daf2-e070-8156-6837d7e20e32@mutix.org> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=telenet.be; s=r24; t=1707080608; bh=JpdEbbXo8QQRZeTDFQh5tOs2vGoKdg0o/lhF77q/fls=; h=To:Cc:From:Subject:Date:In-Reply-To:References; b=YER98i8QIoMMeNdf/hDSWhpfnFxzyGEwH76uQcaS2rpYrSqN0aki8CODEKemqzMjQ zFTaj2k0rHyThk9qfA7GxTV8N1Y4PbcbQxpM6fdwCiFZ5cHL4xdrQR7ofZpuc1UXCB yMee4Uj5PbVJzrBQglC5qNPM5GvGDFxr31q4L/IP83COlrZoAx8jJDSrrf6HkqWYta XTZE8rTvuALQa9cQP6KZy9561kCoOe61DvbRLpmF61VAoe/YBKZJyk0rfd36nq2uWr b09MqeR9nD4ZLtpmKeQXlSKARVBeg13LC2DIWMXQx5Dy+Q6+HBFNbN5rcug9Plmncv g0899WE/YV0ZA== Received-SPF: pass client-ip=2a02:1800:110:4::f00:19; envelope-from=maximedevos@telenet.be; helo=laurent.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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: help-guix@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-guix-bounces+larch=yhetil.org@gnu.org Sender: help-guix-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: 2.24 X-Migadu-Scanner: mx13.migadu.com X-Spam-Score: 2.24 X-Migadu-Queue-Id: AEF7E3AAD1 X-TUID: Dp7CMBfCg3T1 >Onderwerp: Getting all symbols in a Scheme file as a list The following will give you a list of all the symbols (unless I made some s= yntax errors) (also replace =E2=80=98 by a proper quote, e-mail program is = corrupting it): (use-modules (ice-9 match)) (define (all-symbols s-exp) (match s-exp ((? symbol? a) (list a)) ((a . b) (append (all-symbols a) (all-symbols b))) ;; insert rules for vectors and arrays [=E2=80=A6] (_ =E2=80=98()))) [ also open file with open-input-file, apply =E2=80=98read=E2=80=99 to the = port and pass the result to all-symbols, in a loop, and append the results = together. ]. Doesn=E2=80=99t seem useful for what you are mentioning later, though =E2= =80=A6 >I'm trying to write a Guile script to trace symbol definition and referenc= e between modules in a large Guile repo (GNU/Guix), for the purposes of large scale refactoring. There is no such thing as symbol definitions in Scheme =E2=80=93 you can ma= ke symbols with symbol->string, but you can=E2=80=99t define a symbol to an= ything, symbols simply are. You can, however, define variables, which have a symbol as name (and that n= ame may depend on context in case of hygienic macros or renamed imports/exp= orts in modules). >I'm wondering how I could programmatically get all the values in a=20 Scheme file as an S-expression. From the manual, I know that the REPL has meta keyword ',binding' and ',apropos' =20 which let you search and list all bindings in accessible to a module. These are=20 exactly what I need only, since they're meta-commands, they don't produce Scheme expressions. >Does anyone have any pointers? Should I go down the route of, > =C2=A0=C2=A0 (open-input-pipe (string-append "guile -l" file "-c ,binding= ")) >? Seems a little bit baroque to me, I'd expect a simpler way of doing=20 it. Any libraries anyone knows of? No. The quoting is incorrect when file has spaces, \, =E2=80=A6, guile in P= ATH might not be the Guile that is being run, =E2=80=A6 (For the former, co= nsider open-input-pipe*.) You can probably find a simpler way of doing it by locating where =E2=80=9C= ,binding=E2=80=9D is implemented (in the Guile source code). It probably us= es the module reflection API. This API is documented in https://www.gnu.org/software/guile/manual/html_node/Module-System-Reflectio= n.html However, the documentation is incomplete =E2=80=93 IIRC there is a procedur= e =E2=80=98module-bindings=E2=80=99 to find a list of top-level definitions= , but it doesn=E2=80=99t seem to be documented. To find what modules a module uses, there is module-uses, though I doubt it= is reliable w.r.t. optimisation, inlining, uses of (@ (module name) variab= le), =E2=80=A6 So, instead, I would propose to instead work on the Tree-IL level (https:/= /www.gnu.org/software/guile/manual/html_node/Tree_002dIL.html). In particul= ar, see for definitions and , fo= r uses of other modules. This also allows for more fine-grained information =E2=80=93 e.g. these etc. objects contain the location in the source code, and if a is inside a then you know that it is the proce= dure (assuming it is a procedure) of the that uses the va= riable of the . (See https://www.gnu.org/software/guile/manual/html_node/The-Scheme-Compile= r.html for how to compile stuff =E2=80=93 also, IIRC, the compilation proce= dure accepts ports instead of only S-expressions, despite what the example = suggests.) Best regards, Maxime Devos