From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id KA5rDgvdwGVGDQAAqHPOHw:P1 (envelope-from ) for ; Mon, 05 Feb 2024 14:05:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id KA5rDgvdwGVGDQAAqHPOHw (envelope-from ) for ; Mon, 05 Feb 2024 14:05:15 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; 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" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1707138314; a=rsa-sha256; cv=none; b=VcISBhhXlPGLjkAInC055JwkeKvi8fySEXEzDQhFBMYo7TK2q4kLOW/8U0JOZkJFF9/7sl Ri2i83TioakGIxAzFyYzWHtCiVi9MY7f6uXID1ARg9bYIdW+Sl2NrWbDLqAELTchHO2t0O OIwG5mXCDjzaxP6cU9Yd4q/0oNFCTGVjp6nug+y0q6PHFk2RvJR42rwwKSSJ2RHf0SGMSM c/q1KKnRgkZobHBAwjhARiZ1MmKcodsQGA8pAVDgMiwEY8/0J1nXvMxSNYTW2ImwWCgwHX N0LRlW3O+U7a1JGz9lwHOPox25JK+tu2uvzvwHOAjbLlILMOBaOLaCrDXxFreQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1707138314; 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; bh=82E3myVX7+mOZOF2IQHbES5OG42wJJh/4LI2pj6Z7U4=; b=ANCCmKDDyCBkVfpAfuwii/hUgd5N2F1leoj9+ByhnrpceRDhc2ETzpjcz7f1xgcuF4b55n SzNRyLsVro5oSiwFC7pQE2SXKoC4UZsXP/KuNgxM0u0RhwABnwKcyX+JOdVygsW29+u7cS m/CZ4uNvECYDhqyGh9iT6mddxKKnYEtAfG+iiKYUqqyuaBVD2503TfSBb1H1KUJUhHEM6u z/MzGB1HQjwwz4ZL72sSNRaDp0cq0dNxXDrc6+esNXwRuw+9whjssNULGAKuybu4KiDSTC vlC5iDZ67ik2YxzJQl1A9NYl2ErWkWmvuTNArfeojp9RFeDnTdUTc1IqnfvVSw== 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 1FB80FB63 for ; Mon, 5 Feb 2024 14:05:14 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWyeW-0002YR-0M; Mon, 05 Feb 2024 08:04:48 -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 1rWyeQ-0002Xg-BC; Mon, 05 Feb 2024 08:04:43 -0500 Received: from vmi993448.contaboserver.net ([194.163.141.236] helo=mutix.org) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rWyeM-0003Pa-Ov; Mon, 05 Feb 2024 08:04:42 -0500 Received: from [192.168.1.172] (host86-132-246-87.range86-132.btcentralplus.com [86.132.246.87]) (Authenticated sender: cdo) by mutix.org (Postfix) with ESMTPSA id 11C86A63374; Mon, 5 Feb 2024 14:04:35 +0100 (CET) Message-ID: Date: Mon, 5 Feb 2024 13:04:34 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: Getting all symbols in a Scheme file as a list Content-Language: en-US To: M , "guile-user@gnu.org" Cc: "help-guix@gnu.org" References: <03f7199a-daf2-e070-8156-6837d7e20e32@mutix.org> <20240204220328.j93T2B00C1cshW70193U6r@laurent.telenet-ops.be> From: Christina O'Donnell In-Reply-To: <20240204220328.j93T2B00C1cshW70193U6r@laurent.telenet-ops.be> Received-SPF: pass client-ip=194.163.141.236; envelope-from=cdo@mutix.org; helo=mutix.org X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, HTML_MESSAGE=0.001, NICE_REPLY_A=-1.543, SPF_HELO_PASS=-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; format=flowed Content-Transfer-Encoding: 8bit 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-Scanner: mx10.migadu.com X-Spam-Score: -6.67 X-Migadu-Queue-Id: 1FB80FB63 X-Migadu-Spam-Score: -6.67 X-TUID: t/NFt8KLm+1T Hi, > There is no such thing as symbol definitions in Scheme – you can make > symbols with symbol->string, but you can’t define a symbol to > anything, symbols simply are. > > You can, however, define variables, which have a symbol as name (and > that name may depend on context in case of hygienic macros or renamed > imports/exports in modules). Thanks for the clarification. I'll try to remember this. > You can probably find a simpler way of doing it by locating where > “,binding” is implemented (in the Guile source code). It probably uses > the module reflection API. This API is documented in > > https://www.gnu.org/software/guile/manual/html_node/Module-System-Reflection.html > > However, the documentation is incomplete – IIRC there is a procedure > ‘module-bindings’ to find a list of top-level definitions, but it > doesn’t seem to be documented. > Got it! The REPL uses module-for-each, in (ice-9 boot-9), which is exported publicly: (define (module-for-each proc module)   "Call PROC on each symbol in MODULE, with arguments of (SYMBOL VARIABLE)."   (hash-for-each proc (module-obarray module))) This is called from (system repl command): (define-meta-command (binding repl)   "binding List current bindings."   (module-for-each (lambda (k v) (format #t "~23A ~A\n" k v))                    (current-module))) That'll do it for me! > 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) variable), … > > 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 particular, see for definitions and > , for uses of other modules. > > This also allows for more fine-grained information – 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 procedure (assuming it is a procedure) of the > that uses the variable of the . > > (See > https://www.gnu.org/software/guile/manual/html_node/The-Scheme-Compiler.html > for how to compile stuff – also, IIRC, the compilation procedure > accepts ports instead of only S-expressions, despite what the example > suggests.) > Thanks. I know what I'm read next. Thank you so much for your help!  - Christina On 04/02/2024 21:03, M wrote: > > >I'm trying to write a Guile script to trace symbol definition and > reference > > 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 – you can make > symbols with symbol->string, but you can’t define a symbol to > anything, symbols simply are. > > You can, however, define variables, which have a symbol as name (and > that name may depend on context in case of hygienic macros or renamed > imports/exports in modules). > > >I'm wondering how I could programmatically get all the values in a > > Scheme file > > as an S-expression. From the manual, I know that the REPL has meta keyword > > ',binding' and ',apropos' > > > > which let > > you search and list all bindings in accessible to a module. These are > > 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, > > >    (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 > > it. Any > > libraries anyone knows of? > > No. The quoting is incorrect when file has spaces, \, …, guile in PATH > might not be the Guile that is being run, … (For the former, consider > open-input-pipe*.) > > You can probably find a simpler way of doing it by locating where > “,binding” is implemented (in the Guile source code). It probably uses > the module reflection API. This API is documented in > > https://www.gnu.org/software/guile/manual/html_node/Module-System-Reflection.html > > However, the documentation is incomplete – IIRC there is a procedure > ‘module-bindings’ to find a list of top-level definitions, but it > doesn’t 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) variable), … > > 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 particular, see for definitions and > , for uses of other modules. > > This also allows for more fine-grained information – 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 procedure (assuming it is a procedure) of the > that uses the variable of the . > > (See > https://www.gnu.org/software/guile/manual/html_node/The-Scheme-Compiler.html > for how to compile stuff – also, IIRC, the compilation procedure > accepts ports instead of only S-expressions, despite what the example > suggests.) > > Best regards, > > Maxime Devos >