* threading macro instead of modify* macros
@ 2023-01-17 1:22 Csepp
0 siblings, 0 replies; only message in thread
From: Csepp @ 2023-01-17 1:22 UTC (permalink / raw)
To: guix-devel
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.
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-17 1:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 1:22 threading macro instead of modify* macros Csepp
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).