guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using srfi-189 in (gnu services configuration)


From: Maxime Devos
Subject: Re: using srfi-189 in (gnu services configuration)
Date: Mon, 28 Mar 2022 17:54:31 +0200
User-agent: Evolution 3.38.3-1

Attila Lendvai schreef op ma 28-03-2022 om 14:35 [+0000]:
> this is a follow up to: using an SRFI that is not available in Guile
> 
> https://lists.gnu.org/archive/html/guix-devel/2022-01/msg00249.html
> 
> let me summarize the discussion, and with that my argument why i'd
> like to use srfi-189 in the configuration code:
> 
> - sometimes we need to be able to unambiguously distinguish whether a
>   config field value has been specified by the user or not. [...]
> 
>   in the current setup, simply specifying a default value would make
>   it impossible to distinguish, because [...]
> 
> - the current code uses the symbol 'DISABLED

It's a bit of a distraction to the discusses issue, but in Guile
Scheme, symbols are case-sensitive, so (not (eq? 'disabled 'DISABLED)).

>  as a special field value
>   to signify that the field has not been set (i.e. what Nothing would
>   mean if we used srfi-189). it is rather confusing, because many
>   config fields are boolean fields, where 'DISABLED sounds like a
>   valid off value. it is also prone for clashes with user specified
>   values.
> 
> - the current codebase also uses 'UNDEFINED as yet another special
>   marker. once i understood, but unfortunately, i have forgotten what
>   for since then... looks like only as a marker in the macro for the
>   situation when no default value form has been specified for a
>   field's definition.
> 
> - using symbols as markers for special values is a bad idea, because
>   the user may specify a field type to be SYMBOL?, which wouldn't
>   error when the value is 'DISABLED.
> 
> - we can't use Guile's *UNSPECIFIED* for this, because the underlying
>   record implementation of Guile uses it for pretty much the same
>   thing, and it errors whenever this value is encountered in a
>   record's field.

This does not appear to be true, at least for (srfi srfi-9) records:
the following code can put *unspecified* in Guile records without any
errors:

(use-modules (srfi srfi-9))
(define-record-type <foobar>
 (make-foobar foo) foo? (foo foobar-foo))

(pk 'foobar (make-foobar *unspecified*))
;;; (foobar #<<foobar> foo: #<unspecified>>)

Anyway, even if *unspecified* causes problems, this can be resolved by
introducing a new constant like *unspecified* or the symbol 'disabled',
but without the potential confusion with a symbol.  E.g.:

(define-values (*unset-configuration-value* unset-configuration-value?)
  (let ()
    (define-record-type <unset-configuration-value>
      (*make-unset-configuration-value*) unset-configuration-value?
      unset-configuration-value?)
    (values (*make-unset-configuration-value*)
            unset-configuration-value?)))

srfi-189 is also an option, but it seems to me that Haskell-style
Maybe/Just/None that would require lots of wrapping and unwrapping
which seems a bit tedious to me -- doable and definitely an option, but
potentially tedious.

Additionally, for your Swarm example, would something like the
following work:

   ;; defined in (gnu services cryptocurrencies) or such
   (define swarm-testnet
     (swarm-instance
       (bootstrap-peers (list "x.y.z.w" "1111:2222:3333::4"))
       (foo-rate 1.5+2i)
       ...))
   (define swarm-mainnet [...])

   (swarm-configuration
     (ethereum-account ...)
     (port 12345) ; default: 54321
     ;; If the user known what they are doing, they can override
     ;; 
     (swarms (list swarm-testnet swarm-mainnet)))

?  This way, the well-known swarms 'testnet' and 'mainnet' do not have
to be special-cased.

Greetings,
Maxime.

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]