unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: fernseed@fernseed.me
Cc: Josselin Poiret <dev@jpoiret.xyz>,
	Tobias Geerinckx-Rice <me@tobias.gr>,
	Simon Tournier <zimon.toutoune@gmail.com>,
	paren@disroot.org, Christopher Baines <mail@cbaines.net>,
	64620@debbugs.gnu.org, Andrew Tropin <andrew@trop.in>,
	Ricardo Wurmus <rekado@elephly.net>,
	Mathieu Othacehe <othacehe@gnu.org>
Subject: [bug#64620] [PATCH] gnu: home: Add home-emacs-service-type.
Date: Wed, 11 Oct 2023 18:48:59 +0200	[thread overview]
Message-ID: <87lec9t890.fsf@gnu.org> (raw)
In-Reply-To: <0173e076aafb6ec389a7ebca5d56b7f4e8a02b6e.1689347338.git.fernseed@fernseed.me> (fernseed@fernseed.me's message of "Fri, 14 Jul 2023 11:12:31 -0400")

So, here is a short review of the parts I’m most familiar with.

fernseed@fernseed.me skribis:


[...]

> +(define-module (gnu home services emacs)
> +  #:use-module (gnu home services)

[...]

> +  #:re-export (blank?
> +
> +               vertical-space
> +               vertical-space?

Why re-export these things from here?  Sounds surprising because we’re
in a service module.


[...]

> +(define* (elisp->file-builder exps #:key (special-forms '()))
> +  "Return a G-expression that builds a file containing the Elisp
> +expressions (<elisp> objects or s-expressions) or G-epxressions in list EXPS.
> +See `elisp-file' for a description of SPECIAL-FORMS."

[...]

> +  (with-imported-modules (source-module-closure
> +                          '((guix read-print)))
> +    (gexp (begin
> +            (use-modules (guix read-print))
> +            (call-with-output-file (ungexp output "out")
> +              (lambda (port)

For clarity/conciseness, you can use #~ and #$ in this code.

> +(define-gexp-compiler (elisp-file-compiler (elisp-file <elisp-file>)
> +                                           system target)
> +  (match-record elisp-file <elisp-file>
> +                (name gexp)
> +    (with-monad %store-monad
> +      (gexp->derivation name gexp
> +                        #:system system
> +                        #:target target
> +                        #:local-build? #t
> +                        #:substitutable? #f))))
> +
> +(define* (elisp-file* name exps #:key (special-forms '()))
> +  "Return as a monadic value a derivation that builds an Elisp file named NAME
> +containing the expressions in EXPS, a list of Elisp expression objects or
> +G-expressions.
> +
> +This is the monadic counterpart of `elisp-file', which see for a description
> +of SPECIAL-FORMS,"
> +  (define builder
> +    (elisp->file-builder exps
> +                         #:special-forms special-forms))
> +
> +  (gexp->derivation name builder
> +                    #:local-build? #t
> +                    #:substitutable? #f))

I think you don’t need to fiddle with the monadic interface.  I’d
suggest removing the <elisp-file> type and gexp compiler and instead
defining ‘elisp-file’ in terms of ‘computed-file’.  WDYT?

> +(define (record-value rec field)
> +  "Return the value of field named FIELD in record REC."
> +  ((record-accessor (record-type-descriptor rec) field) rec))
> +
> +(define-syntax extend-record
> +  ;; Extend record ORIGINAL by creating a new copy using CONSTRUCTOR,
> +  ;; replacing each field specified by ORIG-FIELD with the evaluation of (PROC
> +  ;; ORIG-VAL EXT-VALS), where ORIG-VAL is the value of ORIG-FIELD in ORIGINAL
> +  ;; and EXT-VALS is the list of values of EXT-FIELD in EXTENSIONS.
> +  (lambda (s)
> +    (syntax-case s ()
> +      ((_ constructor original extensions (proc orig-field ext-field) ...)
> +       (with-syntax (((field-specs ...)
> +                      (map
> +                       (lambda (spec)
> +                         (syntax-case spec ()
> +                           ((proc orig-field ext-field)
> +                            #'(orig-field
> +                               (apply
> +                                proc
> +                                (list
> +                                 (record-value original 'orig-field)

I would advice against accessing record fields by name, with run-time
field name resolution.

The spirit of records, unlike alists, is that there’s a
statically-defined mapping of fields to their offsets in the struct;
without having access to record accessors, you’re not supposed to be
able to access the record (I know Guile has ‘struct-ref’,
‘record-accessor’, etc., but these are abstraction-breaking primitives
that should be avoided IMO).

How could this code be adjusted accordingly?  I guess you’re looking for
a way to iterate over fields?

> +;;; Elisp reader extension.
> +;;;
> +
> +(eval-when (expand load eval)
> +
> +  (define (read-elisp-extended port)
> +    (read-with-comments port
> +                        #:blank-line? #f
> +                        #:elisp? #t
> +                        #:unelisp-extensions? #t))
> +
> +  (define (read-elisp-expression chr port)
> +    `(elisp ,(read-elisp-extended port)))
> +
> +  (read-hash-extend #\% read-elisp-expression))

I’d lean towards not having a reader extension because they don’t
compose and it’s easy to end up colliding with another, unrelated
extension.  I think it’s okay if people write:

  (elisp …)

rather than:

  #%(…)

It’s also arguably easier to understand for a newcomer.

> +++ b/guix/read-print.scm

This part is the most “problematic” for me: I’m already dissatisfied
with the current state of things (the pretty-printer in particular is
too complex and hard to work with), and this change brings more
complexity and lacks orthogonality.

What I’d like to see, ideally, is a clear separation between elisp
concerns and Scheme concerns in the reader and in the pretty printer.

Probably, a preliminary step (I could look into it) would be to rewrite
the pretty printer based on Wadler’s “prettier printer” paper and/or
Shinn’s formatting combinators¹.

WDYT?

Thanks,
Ludo’.

¹ https://srfi.schemers.org/srfi-159/srfi-159.html




  parent reply	other threads:[~2023-10-11 16:49 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-14 15:12 [bug#64620] [PATCH] gnu: home: Add home-emacs-service-type fernseed
2023-07-22  2:45 ` 宋文武 via Guix-patches via
2023-08-23 10:01 ` Ludovic Courtès
2023-08-23 16:14   ` Kierin Bell
2023-08-24 12:26 ` Hilton Chain via Guix-patches via
2023-08-24 13:13   ` Kierin Bell
2023-08-24 20:00 ` ( via Guix-patches via
2023-08-26 14:06   ` Kierin Bell
2023-08-28  6:24     ` ( via Guix-patches via
2023-08-28 22:32       ` Kierin Bell
2023-08-29  6:03         ` ( via Guix-patches via
2023-10-11 16:16           ` Ludovic Courtès
2023-10-12 22:15             ` Kierin Bell
2023-10-13  4:30               ` Liliana Marie Prikler
2023-10-13 13:59                 ` Kierin Bell
2023-08-26 20:01 ` Liliana Marie Prikler
2023-08-28 22:27   ` Kierin Bell
2023-08-29  4:24     ` Liliana Marie Prikler
2023-10-11 16:48 ` Ludovic Courtès [this message]
2023-10-12 22:26   ` Kierin Bell
2024-04-01  8:28 ` [bug#64620] Bumping - " Steve George

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=87lec9t890.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=64620@debbugs.gnu.org \
    --cc=andrew@trop.in \
    --cc=dev@jpoiret.xyz \
    --cc=fernseed@fernseed.me \
    --cc=mail@cbaines.net \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=paren@disroot.org \
    --cc=rekado@elephly.net \
    --cc=zimon.toutoune@gmail.com \
    /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).