From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id 4ALiIdnQNmR6eAEASxT56A (envelope-from ) for ; Wed, 12 Apr 2023 17:40:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id yPrjIdnQNmS0VgAA9RJhRA (envelope-from ) for ; Wed, 12 Apr 2023 17:40:09 +0200 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 C2A479965 for ; Wed, 12 Apr 2023 17:40:08 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pmcZn-0001Yl-FY; Wed, 12 Apr 2023 11:40:03 -0400 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 1pmcZm-0001YR-Ny for guix-patches@gnu.org; Wed, 12 Apr 2023 11:40:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmcZm-0001gu-2h for guix-patches@gnu.org; Wed, 12 Apr 2023 11:40:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pmcZl-0005FA-PW for guix-patches@gnu.org; Wed, 12 Apr 2023 11:40:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62356] [PATCH guix-artwork] website: posts: Add Dissecting Guix, Part 3: G-Expressions. Resent-From: Simon Tournier Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 12 Apr 2023 15:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62356 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62356@debbugs.gnu.org Cc: "\(" X-Debbugs-Original-To: "( via Guix-patches via" , 62356@debbugs.gnu.org Received: via spool by submit@debbugs.gnu.org id=B.168131398520119 (code B ref -1); Wed, 12 Apr 2023 15:40:01 +0000 Received: (at submit) by debbugs.gnu.org; 12 Apr 2023 15:39:45 +0000 Received: from localhost ([127.0.0.1]:40932 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pmcZU-0005EQ-Sa for submit@debbugs.gnu.org; Wed, 12 Apr 2023 11:39:45 -0400 Received: from lists.gnu.org ([209.51.188.17]:38004) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pmcZS-0005ED-KH for submit@debbugs.gnu.org; Wed, 12 Apr 2023 11:39:43 -0400 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 1pmcZS-0001Rr-CL for guix-patches@gnu.org; Wed, 12 Apr 2023 11:39:42 -0400 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pmcZP-0001a0-IZ for guix-patches@gnu.org; Wed, 12 Apr 2023 11:39:42 -0400 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3f080fc6994so4062295e9.1 for ; Wed, 12 Apr 2023 08:39:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681313978; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=LYRP2WA5w5Ny/z4nwtBAVTBQuJ0wTvbFkC4uIKdxZO4=; b=SZzCUoKFaUyGm/aRwbPt7MvbSDpWO/cCZ47Ouvt3cn8qshwZpTTR/FtPbQ6u6eAy1e P26oHNgMN1j7GFmLKRplD4acM/6wp4nJzDGC9DWy+HwdfTfPeDeFWNuqZQjEL9ukAdks 8sixzKtvyouvOXi/HwReXOFU7WXR/KLYzNl1Rhekei+6Zygy8hIzggCvJ+hj1Dgcd+M/ xwzQ+kEZSygOa7RqJydxoLJA+zFD03l6YJZ82IFSQgEwfb33MWhn+8/RRStqEVfJO9+l 7v0dvyPRIJg6Az7sWtsobuc6asVh+nntHrOy+csBVrBdTtZXskXR/HmH1uuoWoJNPgdW tvDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1681313978; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LYRP2WA5w5Ny/z4nwtBAVTBQuJ0wTvbFkC4uIKdxZO4=; b=R+jQZyYWOEW2H5MQP2hoO5Yu8Y/HCcxhZwlY8HeO/COtH7O2AnuiKRXBv7qSjNhmjL 9YVjaoi6XEQPmeq6Kkw/wv4cG3Uv8t8Yx9Ep12JKKK+fqJNoaWrQ8bp2lLCC/s7wjqWh 2xGTy0QOSgGJ/KP4ZojBau2/RETl251D/27gSaLz/BNFXUL+Gm/MZ/i780pkjKqDFTKA TXCsGIP2fpEyjVJ6TNHBX3ASzvf+Un6qfNG3WjLjpkjt741sfQnHYDJZdyLNWQoKa17v uzPag6s1cuXpYgQr5eCx2/10PhsZrTgZJscBx+/8E/GbzLunBXdIGQt9VLVWUVCOnx03 ADtA== X-Gm-Message-State: AAQBX9c6tGlBQCBcMskk3RNLmTZqm3slFfFvp2mo2WD6YykivfFAFD9o gkY1WPzBn5TxK99+XJhe8qY= X-Google-Smtp-Source: AKy350akyAI1pwhWIVhGTbNJMyjcisouH7NfNdQtXsCOvNDurAtG0z1+d6DYc51rwYzCckxDuLJIkw== X-Received: by 2002:a05:600c:c8f:b0:3f0:9deb:c60a with SMTP id fj15-20020a05600c0c8f00b003f09debc60amr2145845wmb.4.1681313977755; Wed, 12 Apr 2023 08:39:37 -0700 (PDT) Received: from pfiuh07 ([193.48.40.241]) by smtp.gmail.com with ESMTPSA id i6-20020a05600c290600b003e91b9a92c9sm2717034wmd.24.2023.04.12.08.39.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Apr 2023 08:39:37 -0700 (PDT) From: Simon Tournier In-Reply-To: <20230321205749.4974-1-paren@disroot.org> References: <20230321205749.4974-1-paren@disroot.org> Date: Wed, 12 Apr 2023 17:29:17 +0200 Message-ID: <87ile1glv6.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=zimon.toutoune@gmail.com; helo=mail-wm1-x32d.google.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, FREEMAIL_FROM=0.001, 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-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-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1681314009; a=rsa-sha256; cv=none; b=F4315WK+wNBhsgqEtKeDeiJ6Hc3/x6Cv5OaX4p6de5TAlF9E3dkIqytpB6WLqZfVIn1Rt9 pzqVWJrNmRiwxDxOnyEHYwbXI5rK7pYSuC/DSbcDFn0/16y4/DNLdkiWtpmpUoyeVXRr/L BE0ETloKM96TaMU1KWKmIaz9hx6EHJ0r2c7rRzVbrZ0h8QnpIyLyOMGgU2zzpFODqAdWXk 662W3SOv9yyOZsbcUaUE63Kr2E8uToI3qjLEogFjw9jRAciKJ6BNesomfuhNjcl2iHhowA IDp//usn7RfbM1OgrBhHAAxEu3T2ed+COJmUuDiYNxG5IDh34c12eEEJ8Ei3Wg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=SZzCUoKF; 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"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1681314009; 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=LYRP2WA5w5Ny/z4nwtBAVTBQuJ0wTvbFkC4uIKdxZO4=; b=X2hIxCu4C/W9oIJ+RWCgw+27cmbhEsWYDUTT9q/3LbImf63gdgFuEVlo+J0ObX4WnqKgJQ R9PJ+Kn1d28tpS1Dz4YZCTy1QWBa5tS+pdWW2LLCePHza3lX6rfHNyZ1TwlkWgp5brmSeK AVljByXOjcvwomEIp/+dOaCKZQehx1Dpbq4cgl9eCIc/IILuWw38pycPtNLpKdrfysNZTb WfnTSn9ESyVegYBWKZA/oVRAN8vdjQUjGtUcbsJ4MD0BSpBvXyzVDWd4mL+Y/7Py+HVzIY RYWP82N3nKSWDOmxyNNj5255Es8fNGq/fKnuYGVuILOEB8KLTwGJPhVs3nNLEA== X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -2.32 X-Spam-Score: -2.32 X-Migadu-Queue-Id: C2A479965 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20221208 header.b=SZzCUoKF; 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"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) X-TUID: jOOIu4i0/d8a Hi, Cool! Thanks, it=E2=80=99s very helpful. Minor comments. On mar., 21 mars 2023 at 20:57, "\( via Guix-patches" via wrote: [...] > +The shortcomings of using s-expressions in this way are numerous: we hav= e to > +convert everything to a derivation before using it, and _inputs are not = an > +inherent aspect of the builder_. G-expressions were designed to overcom= e these > +issues. Here I would link to the paper introducing G-expressions, https://hal.inria.fr/hal-01580582v1 > +# Premortem Examination [...] > +Here's an example gexp that is essentially equivalent to our `sexp-build= er`: > + > +```scheme > +(use-modules (guix gexp)) > + > +(define gexp-builder > + #~(symlink #$(file-append irssi "/bin/irssi") > + #$output)) > +``` > + > +`gexp-builder` is far more concise than `sexp-builder`; let's examine th= e syntax > +and the `` object we've created. To make a gexp, we use the `#~` = syntax, > +equivalent to the `gexp` macro, rather than the `quasiquote` backtick us= ed to > +create sexps. > + > +When we want to embed values from outside as references, we use `#$`, or > +`ungexp`, which is, in appearance if not function, equivalent to `unquot= e` > +(`,`). `ungexp` can accept any of four reference types: Well, maybe it is a bit stretching and is probably not natural at all but I would try to introduce some unquote in sexp-builder. I think it would help to see the parallel between S-exp and G-exp; well how G-exp extend S-exp as you explained in the introduction. >=20 > +- Sexps (strings, lists, etc), which will be embedded literally. >From a stylistic point of view, I would write =E2=80=99S-expressions=E2=80= =99 in plain and not S-exps or sexps=E2=80=A6 > +- Other gexps, embedded literally. =E2=80=A6Similarly for G-expression. Both over all the post. Except when = it refers to code as =E2=80=99gexp-builder=E2=80=99. > +That's a lot of complexity abstracted away! For more complex packages a= nd > +services, especially, gexps are a lifesaver; you can refer to the output= paths > +of inputs just as easily as you would a string constant. You do, howeve= r, have > +to watch out for situations where `ungexp-native`, written as `#+`, woul= d be > +preferable over regular `ungexp`, and that's something we'll discuss lat= er. Before the brief digression, I would do another. ;-) Mention ,build and ,lower from =E2=80=9Cguix repl=E2=80=9D. > +A brief digression before we continue: if you'd like to look inside a `<= gexp>` [...] > +# The Lowerable-Object Hardware Shop [...] > +There are many other useful lowerable objects available as part of the g= exp > +library. These include `computed-file`, which accepts a gexp that builds > +the output file, `program-file`, which creates an executable Scheme scri= pt in > +the store using a gexp, and `mixed-text-file`, which allows you to, well= , mix > +text and lowerable objects; it creates a file from the concatenation of a > +sequence of strings and file-likes. The > +[G-Expressions](https://guix.gnu.org/manual/en/html_node/G_002dExpressio= ns.html) > +manual page has more details. Maybe, I would start another section here; or split with 2 subsections. > +So, you may be wondering, at this point: there's so many lowerable objec= ts > +included with the gexps library, surely there must be a way to define mo= re? > +Naturally, there is; this is Scheme, after all! We simply need to acqua= int > +ourselves with the `define-gexp-compiler` macro. [...] > +Let's try this out now: > + > +```scheme > +(use-modules (gnu packages vim)) > + > +(define script-directory-output > + (build-derivation > + (lower-object > + (script-directory > + #~'(("irc" . #$(file-append irssi "/bin/irssi")) ---^ Hum, maybe #~' needs an explanation. Well, using G-expressions, I am missing why Schemers are complaining about Haskell syntax. ;-) > + ("editor" . #$(file-append neovim "/bin/nvim"))))))) > + > +(scandir (string-append script-directory-output "/bin")) > +=E2=87=92 ("." ".." "editor" "irc") > +``` > + > +Who knows why you'd want to do this, but it certainly works! We've look= ed at > +why we need gexps, how they work, and how to extend them, and we've now = only got > +two more advanced features to cover: cross-build support, and modules. Here, I would link to another introduction of G-expression, https://archive.fosdem.org/2020/schedule/event/gexpressionsguile/ or maybe in the Conclusion section. > +# Importing External Modules [...] > +```scheme > +(define silly-directory-output Maybe instead of =E2=80=99silly=E2=80=99, I would pick another name as =E2= =80=99simple=E2=80=99 or =E2=80=99empty=E2=80=99 or =E2=80=99trivial=E2=80=99 or =E2=80=99not-seriou= s=E2=80=99 or else. :-) And similarly for snippets from above. > +# Conclusion > + > +Mastering gexps is essential to understanding Guix's inner workings, so = the aim > +of this blog post is to be as thorough as possible. However, if you sti= ll find > +yourself with questions, please don't hesitate to stop by at the IRC cha= nnel > +`#guix:libera.chat` and mailing list `help-guix@gnu.org`; we'll be glad = to > +assist you! Maybe, you could link to Arun=E2=80=99s or Marius=E2=80=99s posts; for the = ones I am aware of. :-) https://www.systemreboot.net/post/deploy-scripts-using-g-expressions https://gexp.no/blog/guix-drops-part-3-g-expressions.html Cheers, simon