From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.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 AH+3GabK02UGQAEAe85BDQ:P1 (envelope-from ) for ; Mon, 19 Feb 2024 22:39:50 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id AH+3GabK02UGQAEAe85BDQ (envelope-from ) for ; Mon, 19 Feb 2024 22:39:50 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=o36YviP4; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1708378790; 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:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=9Ndu8exGUElAZAUsNB7ogjjqGdGujfWTIZ8QIn3q7h0=; b=gPqFcHgSnVKlXWpCi05KxXK3jBM3at0sBhozuta/gJV23tgdiWPfjeThyxic/KZKVoVmk9 AzdmSGbewLvFXcvM4GwBGxYfkzB/yPAchS7vFDoIIRjSA7AjAgrLaQ9BksH+eTvgRUScGc FOZjOPS7bzOBap0MqiaGZ5Ly+TgeYf9yQS7WREsh4eYmJ+1CxiczigDFkafrrds0jqmbgs fMbsfa6iiL60pU/3OzPxMkhE0nx/Dtg/c6SIM1Um5IAJ3/R6U03r3MupEJfsVPhCRRKQcK mZ7AytGbRZjDmuDsq+H3PMZ+tBFztmQ/FdRZpEkHeW1hjTWStTAZTcUePzezYQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=o36YviP4; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1708378790; a=rsa-sha256; cv=none; b=oQYzo+k3eDJpERCKWLvJAEMrs3Ggzt7bEQ5lBAMAG1mWhpCo4n93gmMTkecJb2ogbtWnuF bt73lI+6qpSX/jPqv+VXtNu5eYqKhPN9tT8ka/UD45KA10Z0B8gKSKjmF+vCWuVG0SPynI iI1qePBOEjWOORecNY4/Ba9SSJ+9LIAavWa2AJzJZ3aZEeLyrO0G3McQa5iKNiy2/zxBWm WDk3/NVAY4dW2FNvc7Gn9ooMVDzyQbeUjiIvboTtWGAF5ji/5RusWxGVXHBozSaESuKxxY L+r9hq51FYBa8WXqMhn/3dNlXIV/wfvzypfTMPSyLeEuiCXl+O4FaQPbp4PA1Q== 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 3C23A3810E for ; Mon, 19 Feb 2024 22:39:50 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rcBMV-0001d6-Ff; Mon, 19 Feb 2024 16:39:43 -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 1rcBMT-0001cs-9h for guix-patches@gnu.org; Mon, 19 Feb 2024 16:39:41 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rcBMT-0006hW-0r for guix-patches@gnu.org; Mon, 19 Feb 2024 16:39:41 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rcBMo-0005d4-7O for guix-patches@gnu.org; Mon, 19 Feb 2024 16:40:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68935] [PATCH v2 4/6] utils: Add find-expression procedure. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 19 Feb 2024 21:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68935 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Herman Rimm Cc: Josselin Poiret , Simon Tournier , Mathieu Othacehe , Tobias Geerinckx-Rice , Ricardo Wurmus , 68935@debbugs.gnu.org, Christopher Baines Received: via spool by 68935-submit@debbugs.gnu.org id=B68935.170837875021554 (code B ref 68935); Mon, 19 Feb 2024 21:40:02 +0000 Received: (at 68935) by debbugs.gnu.org; 19 Feb 2024 21:39:10 +0000 Received: from localhost ([127.0.0.1]:43671 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcBLx-0005bZ-Hi for submit@debbugs.gnu.org; Mon, 19 Feb 2024 16:39:09 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59564) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rcBLu-0005b4-Kc for 68935@debbugs.gnu.org; Mon, 19 Feb 2024 16:39:07 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rcBLQ-0006bs-0d; Mon, 19 Feb 2024 16:38:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=9Ndu8exGUElAZAUsNB7ogjjqGdGujfWTIZ8QIn3q7h0=; b=o36YviP4/ES6rILWbzF7 A81Gdys8znT9VVx05LCH77MdvLBQxDpHXnk0j16qztDQYp8/9myU95j3+910A9lH/Z682eZ+bskPm W6Yr8Ahz3woF3JZYmZ+MYiVFN6snmILmzF9kDYHii0aSARXYqAY0+DLG/VnTnJYiXYERMxAvnW/df 8NKgPDXGt7wnSyMIVooAwlDoiXKi01U4Vhvw5O8wCw2J2v4Ds0NbeqAID1k40dRuiuhZRHYWCmxah zcTFcFPfNtj5W3DS3FMbImbV4xzUfItbLO7tblMHM63CXXYS7LhrCVuglvPMKCyj+V3j6WLJud/1r uyQL5rs/ipWIzQ==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: <028a3d700965947fa0547eb17d4894b8302eb67c.1707505804.git.herman@rimm.ee> (Herman Rimm's message of "Fri, 9 Feb 2024 20:25:16 +0100") References: <3c0da641938e96a9f0c491abb74b30c75634df9a.1707505804.git.herman@rimm.ee> <028a3d700965947fa0547eb17d4894b8302eb67c.1707505804.git.herman@rimm.ee> Date: Mon, 19 Feb 2024 22:38:32 +0100 Message-ID: <87r0h8p21z.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -4.38 X-Spam-Score: -4.38 X-Migadu-Queue-Id: 3C23A3810E X-Migadu-Scanner: mx13.migadu.com X-TUID: IAz1Ibi86hj4 Herman Rimm skribis: > * guix/utils.scm (find-expression): Add and export procedure. > * tests/utils.scm ("find-expression"): Add test. > > Change-Id: Ie209df39c1f006b20aa6436fb1aef4c84b1694ee [...] > +(define (find-expression file expr proc) > + "Search in FILE for a top-level expression which alphabetically > +succeeds EXPR. Call PROC with the location if found, or with #f > +otherwise." > + (let* ((name (match expr > + (('define-public symbol _ ...) > + (symbol->string symbol)))) > + (source-properties > + (call-with-input-file > + file > + (lambda (port) > + (do ((syntax (read-syntax port) > + (read-syntax port))) > + ((match (syntax->datum syntax) > + (('define-public symbol _ ...) > + (string> (symbol->string symbol) > + name)) > + ((? eof-object?) #t) > + (_ #f)) > + (if (eof-object? syntax) > + #f (syntax-source syntax)))))))) > + (proc source-properties))) I think it=E2=80=99d be clearer to: 1. Omit =E2=80=98proc=E2=80=99 and always return the source properties of= the thing that has been found. 2. Pass a symbol instead of =E2=80=98expr=E2=80=99. 3. Call it =E2=80=98find-definition-insertion-location=E2=80=99 to clarif= y that it=E2=80=99s really about finding where we want to insert a definition, hence alphabetical sorting. BTW, the formatting above is unusual; for instance, =E2=80=98file=E2=80=99 = would normally appear on the same line as =E2=80=98call-with-input-file=E2=80=99. Also, write: (and (not (eof-object? syntax)) (syntax-source-syntax)) =E2=80=A6 instead of using =E2=80=98if=E2=80=99. Thanks, Ludo=E2=80=99.