chicken-hackers
[Top][All Lists]
Advanced

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

[Chicken-hackers] locale and chicken >= 3.4.7


From: Timothy Beyer
Subject: [Chicken-hackers] locale and chicken >= 3.4.7
Date: Fri, 06 Mar 2009 14:54:46 -0800
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.7 (Sanjō) APEL/10.6 MULE XEmacs/21.4 (patch 21) (Educational Television) (i386--freebsd)

Hi,

(My first post was rejected by the list, so I sent it again; I hope it doesn't 
send two copies)

I know that I'm not supposed to depending on the development versions of 
chicken, but I really wanted irregex -- I have lots and lots of scsh code that 
I wanted to port, and I can't stand heavy use of perl or emacs regular 
expressions, so irregex was a no-brainer. :) (thanks for making the switch, by 
the way)

It seems that when irregex was imported in 3.4.7, there were some subtle but 
important changes to the procedures. (string-match in particular until 3.5.2 
temporarily omitted it's support for a start argument, though I'm not if it 
works in the current version, more that it doesn't break compilation)

After a lot of experimenting and fumbling around, I was able to get srfi-19 and 
locale to work in 3.5.2 simply by changing one use of string-match to 
string-diff: (in 3.4.7, substring is needed, and even then the regexp parsing 
will probably silently fail, and then I get UTC on current date which isn't 
appropriate)

--- locale-posix.scm.orig       2008-02-25 13:15:12.000000000 -0800
+++ locale-posix.scm    2009-03-06 05:13:34.000000000 -0800
@@ -60,7 +60,7 @@
                           #t)]
                       [next-match
                         (lambda (re)
-                          (and-let* ([m (string-match re str-val str-idx)])
+                          (and-let* ([m (string-search re str-val str-idx)])
                             (set! str-idx (+ str-idx (string-length (car m))))
                             m ) )]
                       [empty-match?

I think that the larger problem is that the regexp used in locale-posix.scm is 
kind of obscure, (might be a good idea to just use irregex's scsh style API 
instead) as it seems to depend on some specific feature that string-search has 
but not string-match.  For what it's worth, switching to string-search alone 
doesn't fix the problem in 3.4.7, so there must have been some improvements 
since then.

Here are some pseudo-unit tests that I wrote that pass in 3.4.0, but fail in 
3.5.2, (at least without my patch, then they all pass) and don't even load in 
3.4.7 without some additional minor changes to locale-posix.scm. (the function 
of interest seems to be posix-timezone-value->timezone-components)

** Tests that pass in 3.4.0

#;2> (current-date)
#,(date 857000000 37 7 0 6 3 2009 -28800 PST #f #f #f #f)
#;3> (posix-timezone-value->timezone-components "PST8PDT")
((name . "PST8PDT") (source . "POSIX") (std-name . "PST") (std-offset . 28800))
#;6> (current-timezone)
"PST8PDT"
#;7> (getenv "TZ")
"PST8PDT"
#;8> (posix-timezone-value->timezone-components "PST+8:00")
((name . "PST+8:00") (source . "POSIX") (std-name . "PST") (std-offset . 28800))
#;9> (default-timezone-components)
((name . "") (std-name . "UTC") (std-offset . 0))
#;10> (unknown-timezone-components "PST8PDT")
((name . "PST8PDT"))
#;11> (unknown-timezone-components "PST+8:00")
((name . "PST+8:00"))
#;12> (getenv "LANG")
"en_US.UTF-8"
#;3> (let ([name-re (regexp "([A-Za-z]+)|<([^>]+)>")]) (string-match name-re 
"PST8PDT" 0))
("PST" "PST" #f)
#;4> (let ([name-re (regexp "([A-Za-z]+)|<([^>]+)>")]) (string-match name-re 
"PST+8:00" 0))
("PST" "PST" #f)
(let ([time-re (regexp "/([0-9]+)(:[0-9]+)?(:[0-9]+)?")]) (string-match time-re 
"PST+8:00" 0))
#f
#;8> (unknown-locale-components "PST8PDT")
((name . "PST8PDT"))
#;9> (unknown-locale-components "PST+8PDT")
((name . "PST+8PDT"))
#;21> (let* ([str-idx 0] [name-re (regexp "([A-Za-z]+)|<([^>]+)>")] [time-re 
(regexp "/([0-9]+)(:[0-9]+)?(:[0-9]+)?")]) (and-let* ([m (string-match name-re 
"PST+8:00" 0)]) (set! str-idx (+ str-idx (string-length (car m)))) m))
("PST" "PST" #f)
#;22> (let* ([str-idx 0] [name-re (regexp "([A-Za-z]+)|<([^>]+)>")] [time-re 
(regexp "/([0-9]+)(:[0-9]+)?(:[0-9]+)?")]) (begin (and-let* ([m (string-match 
name-re "PST+8:00" 0)]) (set! str-idx (+ str-idx (string-length (car m)))) m) 
str-idx))
3
#;9> (let ([name-re (regexp "([A-Za-z]+)")]) (string-match name-re "PST8PDT" 0))
("PST" "PST")
#;10> (let ([name-re (regexp "[A-Za-z]+")]) (string-match name-re "PST8PDT" 0))
("PST")
#;11> (let ([name-re (regexp "[A-Za-z]+")]) (string-match name-re "PST+8:00" 0))
("PST")
#;13> (let ([name-re (regexp "([A-Za-z]+)")]) (string-match name-re "PST+8:00" 
0))
("PST" "PST")
(let ([offset-re (regexp "([+-])?([0-9]+)(:[0-9]+)?(:[0-9]+)?")])
        (string-match offset-re "PST+8:00" 3))
#;2> (let ([offset-re (regexp "([+-])?([0-9]+)(:[0-9]+)?(:[0-9]+)?")])
        (string-match offset-re "PST8PDT" 0))
("8" #f "8" #f #f)
#;3> (let ([offset-re (regexp "([+-])?([0-9]+)(:[0-9]+)?(:[0-9]+)?")])
        (string-match offset-re "PST8PDT" 3))
("8" #f "8" #f #f)
#;4> (let ([offset-re (regexp "([+-])?([0-9]+)(:[0-9]+)?(:[0-9]+)?")])
        (string-search offset-re "PST8PDT" 3))
("8" #f "8" #f #f)

** These apparently work in 3.5.2 (without my changes)
#;4> #;3> (let ([name-re (regexp "([A-Za-z]+)|<([^>]+)>")]) (string-search 
name-re "PST8PDT" 0))
("PST" "PST" #f)
#;8> (let ([offset-re (regexp "([+-])?([0-9]+)(:[0-9]+)?(:[0-9]+)?")])
        (string-search offset-re "PST8PDT" 3))
("8" #f "8" #f #f)

** These do NOT work in 3.5.2 (without my changes)
#;5> (let ([name-re (regexp "([A-Za-z]+)|<([^>]+)>")]) (string-match name-re 
"PST8PDT" 0))
#f
#;6> (let ([offset-re (regexp "([+-])?([0-9]+)(:[0-9]+)?(:[0-9]+)?")])
        (string-match offset-re "PST8PDT" 3))
#f
#;6> (let ([name-re (regexp "([A-Za-z]+)|<([^>]+)>")]) (string-match name-re 
"PST8PDT" 3))
#f

Please Cc: any replies to me as I read the list primarily through Gmane.

My apologies if this is the wrong list or if this should be a bug report 
instead...

Regards,
Tim




reply via email to

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