From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 12 11:39:45 2023 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 To: "( via Guix-patches via" , 62356@debbugs.gnu.org Subject: Re: [bug#62356] [PATCH guix-artwork] website: posts: Add Dissecting Guix, Part 3: G-Expressions. 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-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit Cc: "\(" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) 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