From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Newsgroups: gmane.emacs.help Subject: Navigating Lisp data structures Date: Sun, 04 Dec 2022 14:00:25 -0500 Message-ID: <184de82cf09.eebfb5c8843687.6482234845227025147@excalamus.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11166"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Zoho Mail To: "help-gnu-emacs" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Dec 05 00:30:08 2022 Return-path: Envelope-to: geh-help-gnu-emacs@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 1p1yQy-0002dD-Bo for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 05 Dec 2022 00:30:08 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p1yQM-0007L3-Ia; Sun, 04 Dec 2022 18:29:30 -0500 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 1p1uEA-0000DI-Mk for help-gnu-emacs@gnu.org; Sun, 04 Dec 2022 14:00:38 -0500 Original-Received: from sender4-op-o14.zoho.com ([136.143.188.14]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p1uE7-0007Oi-FZ for help-gnu-emacs@gnu.org; Sun, 04 Dec 2022 14:00:37 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1670180427; cv=none; d=zohomail.com; s=zohoarc; b=fznAqf5o/jHqUwVp+e8Ghuza+nGzWxQWcLhoJkZ/5Mg1GHXxDTlbc7ge3BauD2Q8QQn5EDzbyVIDxueXnX+h1oYJruSmpVpCfy+0gvj36ktn47VBbWbYUSskSSlSwqY0dtaNjdJcrsAOrHpV96vfOAG6RsjuCxcmVzNNMjprvK4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670180427; h=Content-Type:Content-Transfer-Encoding:Date:From:MIME-Version:Message-ID:Subject:To; bh=pDhp6fCa0UL2GDPcRAR1C76CiXsGDD6G/2GELZJl+Rs=; b=F39aaEXyAzFM+kiE8cnA5wYI44cufgQMEEak6XzENIu6YuO27x1VDJfBPmbHOdX9f7VbbhhmhEndKHXqQ98Tqtf/r25o0ZNfUWtrCHUMts4jQZRutkCIrPsugPAXxRw4+8+esoJ6K0pwwwBLM/YAduyLD9prkBXa0o0PjBQHmKw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=excalamus.com; spf=pass smtp.mailfrom=matt@excalamus.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1670180427; s=zmail; d=excalamus.com; i=matt@excalamus.com; h=Date:Date:From:From:To:To:Message-ID:In-Reply-To:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To:Cc; bh=pDhp6fCa0UL2GDPcRAR1C76CiXsGDD6G/2GELZJl+Rs=; b=OVHjdJQTXgSseG3T3J+qMx/so5SxJ6n9hcbLV6XA2T2eQYqA0Qucxj5Bvig3wtSg +SgQEFG0c9K/jyeHIAXb+THPRI+iYWL40obr9pyTFonFgpUocEbnMUwnwmwXQ6DgClZ cTnB1VFVPUiwP4BnU/BwrV5L5wM0pKe0MfOk120E= Original-Received: from mail.zoho.com by mx.zohomail.com with SMTP id 1670180425496256.100685642235; Sun, 4 Dec 2022 11:00:25 -0800 (PST) Importance: Medium X-Mailer: Zoho Mail Received-SPF: pass client-ip=136.143.188.14; envelope-from=matt@excalamus.com; helo=sender4-op-o14.zoho.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, 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-Mailman-Approved-At: Sun, 04 Dec 2022 18:29:29 -0500 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:141377 Archived-At: I'm writing an Emacs package and struggling to figure out how to represent the data in a Lisp data structure. I'm getting lost in whether it should be an alist of alists, a plist of plists, an alist of plists, etc. Or maybe it would be better to use a cl-struct or a hash or a class or a vector or a record. Should I use keywords or not, etc. Here is a detailed explanation of my issue: My Emacs package manages my project workflows (e.g. Python or C). Each project has a name, associated files, one or more shell processes (comints), as well as commands for a specific shell and commands used across the shells. It also sets my window layout. In Python, I might structure the data something like this: projects = { "my_c_project": { 'shells': { "*build*": {"root": "/path/to/build/directory/", "setup": ("export MYBUILDVAR1=1", "export MYBUILDVAR2=0")}, "*run*": {"root": "/path/to/run/directory/", "setup": ("export MYRUNVAR=1")} }, 'commands': ("./build_my_project.sh", "./run_my_build"), 'files': ("/path/to/entrypoint.c", "/path/to/other/file/I/care/about.c"), 'window_split': ("quad", ), # C-x 3 C-x 2 other-window other-window C-x 2 }, "my_python_project": { 'shells': {"*my_python_project*": {"root": "/path/to/my/python/project", "setup": ("source venv/bin/activate")}}, 'commands': ("python3 -m my_python_project", "python3 -m unittest discover tests/ --failfast --quiet", ), 'files': ("/path/to/my_python_project/entry_point.py", ), 'window_split': ("half", ), # C-x 3 } } I could then get the information I need through chaining look ups. If we pretended that Emacs used Python, activating a project might look something like this: (Pdb) # create shells (Pdb) for name in projects['my_python_project']['shells']: pass # call comint creation command (Pdb) # setup shell environments (Pdb) for command in projects['my_python_project']['shells']['*my_python_project*']['setup']: pass # pass each command in the comint (Pdb) # load files (Pdb) for file in projects['my_python_project']['files']: pass # run emacs find-file (Pdb) # and so on Of course the data could be represented using classes instead of dicts. However, I hope the problem is clear. I'm obviously looking at the problem through the lens of Python key-value structures. When I try to translate the data structure to something like nested plists, it feels messy. Maybe that's me simply being uncomfortable with nested lists? When I mix list types (e.g. an alist of plists), the lookup syntax becomes inconsistent (a mix of assocs and plist-gets, scattered with cars and cdrs and weird cases in which I have a list of strings I can't seem to access). Guidance would be sincerely appreciated.