unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
To: Rob Browning <rlb@defaultvalue.org>
Cc: guile-devel@gnu.org
Subject: Re: [PATCH v1] SRFI-19: Add support for ISO 8601 zones with a colon.
Date: Mon, 11 Mar 2024 19:25:08 +0100	[thread overview]
Message-ID: <20240311192508.5b974e64@trisquel64> (raw)
In-Reply-To: <87r0gnjj7h.fsf@trouble.defaultvalue.org>

[-- Attachment #1: Type: text/plain, Size: 2665 bytes --]

Hi,

Sorry for the delay,

On Wed, 06 Mar 2024 12:42:10 -0600
Rob Browning <rlb@defaultvalue.org> wrote:

> Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> writes:
> (...and (not related), I also wondered about making some of the error
>  messsages more specific, i.e. "Invalid time zone minutes digit" or
>  something.)

Would something like that be OK instead?:
> (time-error
>  'string->date 'bad-date-template-string 
>  (list "Invalid time zone number" ch))

My code had indeed big duplication of code: it duplicated the read,
the test and even the error message:
> > +              (if (char=? ch #\:)
> > +                  (set! ch (read-char port))
> > +                  (if (eof-object? ch)
> > +                      (time-error 'string->date
> > 'bad-date-template-string
> > +                                  (list "Invalid time zone number"
> > ch)))) (set! offset (+ offset (* (char->int ch)
> >                                          10 60))))  

And if I understood right the goal of this example is to avoid this
duplication of code:
> This looks reasonable to me -- I wondered about moving the check "up
> front", eliminating the need for the extra eof?, i.e.
> 
>             (let ((ch (read-char port)))
>               (when (char=? ch #\:)
>                   (set! ch (read-char port))
>               (if (eof-object? ch)
>                   (time-error 'string->date 'bad-date-template-string
>                               (list "Invalid time zone number" ch)))
>               (set! ...))
However here (char=? ch #\:) can fail if ch is an eof-object. I tested
that by adding that in some test.scm file:
> (define ch (read-char))
> (char=? ch #\:)
and running guile test.scm and typing ctrl+d to make ch an eof-object,
and that produces the following error:
> In procedure char=?: Wrong type argument in position 1 (expecting
> character): #<eof>

And since we can read a character twice we need to do that eof-object?
test twice.

So would something like that work instead?:
> (let ((f (lambda ()
> 	   (let ((ch (read-char port)))
> 	     (if (eof-object? ch)
> 		 (time-error
> 		  'string->date 'bad-date-template-string
> 		  (list "Missing required time zone minutes" ch))
> 		 ch)))))
>   (let ((ch (f)))
>     (if (char=? ch #\:) (set! ch (f)))
>     (set! offset (+ offset (* (char->int ch) 10 60)))))

Here the downside is that the code is slightly more complex but there
is no duplication of code and it also does one check for each read.
Also note that I didn't test the code above yet.

If all that is good, I can send a v2 of the patch.

Denis.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  parent reply	other threads:[~2024-03-11 18:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 21:23 [PATCH v1] SRFI-19: Add support for ISO 8601 zones with a colon Denis 'GNUtoo' Carikli
2024-03-06 18:42 ` Rob Browning
2024-03-06 18:58   ` Rob Browning
2024-03-11 18:25   ` Denis 'GNUtoo' Carikli [this message]
2024-03-19 14:26     ` Denis 'GNUtoo' Carikli
2024-03-19 20:18     ` [PATCH v2] " Denis 'GNUtoo' Carikli
2024-03-20  0:21     ` [PATCH v1] " Rob Browning
2024-04-05 22:03       ` Rob Browning
2024-04-12 15:19         ` Denis 'GNUtoo' Carikli
2024-04-13 19:44           ` Rob Browning
2024-04-12 15:19       ` Denis 'GNUtoo' Carikli

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://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=20240311192508.5b974e64@trisquel64 \
    --to=gnutoo@cyberdimension.org \
    --cc=guile-devel@gnu.org \
    --cc=rlb@defaultvalue.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.
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).