[Gauche-devel-jp] rxmatchの挙動

Back to archive index

Shiro Kawai shiro****@lava*****
2003年 2月 28日 (金) 09:50:38 JST


From: OGURISU Osamu <oguri****@lagen*****>
Subject: [Gauche-devel-jp] rxmatchの挙動
Date: Fri, 28 Feb 2003 08:16:14 +0900

> rxmatchで、z,Zを含む文字クラスでcase-foldingにすると期待通りの動
> 作にならないようです。
[...]
> gosh> (rxmatch #/(.*)a/ "漢字")
> *** ERROR: stack overrun during matching regexp #/(.*)a/
> Stack Trace:
> _______________________________________
> gosh> (d (rxmatch #/([^a]*)a/ "漢字"))
> #<<regmatch> 0x8184450> is an instance of class <regmatch>
> gosh> 

バグでした。以下のパッチをどうぞ。

===================================================================
RCS file: /cvsroot/gauche/Gauche/src/char.c,v
retrieving revision 1.33
diff -u -r1.33 char.c
--- char.c	21 Sep 2002 08:52:49 -0000	1.33
+++ char.c	28 Feb 2003 00:12:28 -0000
@@ -465,7 +465,7 @@
 ScmObj Scm_CharSetCaseFold(ScmCharSet *cs)
 {
     int ch;
-    for (ch='a'; ch<'z'; ch++) {
+    for (ch='a'; ch<='z'; ch++) {
         if (MASK_ISSET(cs, ch) || MASK_ISSET(cs, (ch-('a'-'A')))) {
             MASK_SET(cs, ch);
             MASK_SET(cs, (ch-('a'-'A')));
Index: regexp.c
===================================================================
RCS file: /cvsroot/gauche/Gauche/src/regexp.c,v
retrieving revision 1.37
diff -u -r1.37 regexp.c
--- regexp.c	5 Feb 2003 01:44:34 -0000	1.37
+++ regexp.c	28 Feb 2003 00:12:36 -0000
@@ -1118,9 +1118,10 @@
         }
     }
 #endif
-    for (; start <= end-mustMatchLen; start++) {
+    while (start <= end-mustMatchLen) {
         ScmObj r = re_exec(rx, str, start, end);
         if (!SCM_FALSEP(r)) return r;
+        start += SCM_CHAR_NFOLLOWS(*start)+1;
     }
     return SCM_FALSE;
 }
===================================================================

> ついで?に、infoの有理数の説明で「Gaucheでは、数の集合は複素数の
> 集合と同一であり、有理数の集合は整数の集合と同一です」とあります
> が「実数の集合と同一」のtypoですよね?英語版も同様でした。

そうですね…と言おうとしてあれっと気づきました。
確かに今の実装はreal? == rational? にしてるんですが、
これって正しいのかな、と。

有限の精度しかない浮動少数点数を使っている限り、
全てのflonumは有理数で表現できてしまうのですが
(rational? (sqrt 2)) ==> #t はやっぱり変ですよね。

Gaucheではexact rationalの集合=exact integerの集合、
とした方が良いのかな。で、inexact rationalなんてのは
サポートしない、全部inexact realにcoerceだと。

--shiro



Gauche-devel-jp メーリングリストの案内
Back to archive index