[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 2/2] pk_vercmp: Allow passing and automatically parsing strin
From: |
Jose E. Marchesi |
Subject: |
Re: [PATCH 2/2] pk_vercmp: Allow passing and automatically parsing strings |
Date: |
Tue, 31 Jan 2023 15:36:27 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Hi Arsen.
Thanks for the patch.
OK for master.
> * libpoke/std.pk (pk_vercmp): Allow passing strings.
> * doc/poke.texi (Version Tools): Document the new flexibility of
> pk_vercmp.
> ---
> ChangeLog | 8 ++++++++
> doc/poke.texi | 8 ++++++--
> libpoke/std.pk | 14 +++++++++++++-
> 3 files changed, 27 insertions(+), 3 deletions(-)
>
> diff --git a/ChangeLog b/ChangeLog
> index c9fe04dc..384cd6aa 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,5 +1,13 @@
> 2023-01-31 Arsen Arsenović <arsen@aarsen.me>
>
> + pk_vercmp: Allow passing and automatically parsing strings
> + * libpoke/std.pk (pk_vercmp): Allow passing strings.
> + * doc/poke.texi (Version Tools): Document the new flexibility of
> + pk_vercmp.
> +
> +2023-01-31 Arsen Arsenović <arsen@aarsen.me>
> +
> + pk_parse_version: Provide more context on parse failure
> * libpoke/std.pk (raise_exception): New function, takes an
> exception and augments it with more context, to create a new
> exception. Intended as a helper for errors during parsing.
> diff --git a/doc/poke.texi b/doc/poke.texi
> index 98170eb9..db88bac4 100644
> --- a/doc/poke.texi
> +++ b/doc/poke.texi
> @@ -16289,9 +16289,13 @@ @node Version Tools
>
> The standard library also provides the following helper function:
>
> -@deftypefun int<32> pk_vercmp (Pk_Version @var{a}, Pk_Version @var{a})
> +@deftypefun int<32> pk_vercmp (any @var{a}, any @var{b})
> Returns a number greater than, equal to, or lower than zero if @var{a}
> -compares greater than, equal to or lower than @var{b}, respectively.
> +compares greater than, equal to or lower than @var{b}, respectively,
> +as a GNU poke version.
> +
> +The type of @var{a} and @var{b} must be either @code{string} or
> +@code{Pk_Version}, otherwise, this function raises an @code{E_conv}.
>
> This function implements partial ordering, as it's not possible to
> distinguish some version numbers as greater or lower than each other,
> diff --git a/libpoke/std.pk b/libpoke/std.pk
> index cb14351f..09f36395 100644
> --- a/libpoke/std.pk
> +++ b/libpoke/std.pk
> @@ -787,8 +787,20 @@ fun pk_version_parse = (string a) Pk_Version:
>
> /* Compare a pair GNU poke version strings. */
>
> -fun pk_vercmp = (Pk_Version a, Pk_Version b) int<32>:
> +fun pk_vercmp = (any _a, any _b) int<32>:
> {
> + fun shoehorn = (any x) Pk_Version:
> + {
> + if (x isa Pk_Version)
> + return x as Pk_Version;
> + if (x isa string)
> + return pk_version_parse (x as string);
> + raise E_conv;
> + };
> +
> + var a = shoehorn (_a);
> + var b = shoehorn (_b);
> +
> fun cmp = (uint<32> a, uint<32> b) int<32>:
> {
> if (a > b)