unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Csepp <raingloom@riseup.net>
To: guix-devel <guix-devel@gnu.org>
Subject: threading macro instead of modify* macros
Date: Tue, 17 Jan 2023 01:22:17 +0000	[thread overview]
Message-ID: <868ri22alp.fsf@riseup.net> (raw)

Here is what I'm trying to do:
I have a package that inherits from the ocaml package.  Because of
Various Reasons (tm) I am using substitute-keyword-arguments and
modify-phases and I need to duplicate the shebang patching phase after
multiple phases.
What I wanted to do was write a helper function like:
(duplicate-after 'conf-2 'patch-sh 'patch-sh-again)
Then I realized I'd have to patch modify-phases to add this to its
grammar.
Then came the realizations that in Haskell this would instead be a
composition of curried applications, that's the thing that the cut macro
emulates in Scheme.
So, (modify-phases foo (add-after 'a 'b f) (delete 'c)) is really:
```
(compose
  (cut add-after <> 'a 'b f)
  (cut delete <> 'c))
```
And from having used Fennel a bit I know that it copied a very nice
syntactic feature from Clojure, called the threading macros, which
implements this exact idiom without having to write cut everywhere.

Guix currently has at least a few modify-whatever and
substitute-whatever macros that all hardcode a few operations.  Couldn't
they be made much cleaner and more general by using a solid library of
data manipulation functions and threading macros?
The phases list could be treated like the actual data type it is, an
ordered key-value mapping.

ps.: On that note, Guile has generics, why doesn't any code use it?
When I have to write things like string<? or package-native-inputs --
instead of < and native-inputs -- I feel like I'm in C again.


                 reply	other threads:[~2023-01-17  1:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=868ri22alp.fsf@riseup.net \
    --to=raingloom@riseup.net \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).