[#8168] {literal}#[]= — EGUCHI Osamu <eguchi@...>

えぐち@エスアンドイーです。

16 messages 1999/11/01
[#8172] Re: {literal}#[]= — matz@... (Yukihiro Matsumoto) 1999/11/01

まつもと ゆきひろです

[#8176] Multiple self assignment — Kazuhiro Yoshida <moriq.kazuhiro@...>

もりきゅうです。

35 messages 1999/11/01
[#8178] Re: Multiple self assignment — matz@... (Yukihiro Matsumoto) 1999/11/01

まつもと ゆきひろです

[#8212] Re: Multiple self assignment — Kazuhiro Yoshida <moriq.kazuhiro@...> 1999/11/02

もりきゅうです。

[#8213] Re: Multiple self assignment — matz@... (Yukihiro Matsumoto) 1999/11/03

まつもと ゆきひろです

[#8232] 例外を処理する 2 項演算子 — Kazunori NISHI <kazunori@...> 1999/11/05

西@九大です。

[#8233] Re: 例外を処理する 2 項演算子 — matz@... (Yukihiro Matsumoto) 1999/11/05

まつもと ゆきひろです

[#8236] Re: 例外を処理する 2 項演算子 — Kazuhiro Yoshida <moriq.kazuhiro@...> 1999/11/05

もりきゅうです。

[#8266] Re: 例外を処理する 2 項演算子 — EGUCHI Osamu <eguchi@...> 1999/11/07

えぐち@エスアンドイー です。

[#8269] Re: 例外を処理する 2 項演算子 — gotoken@... (GOTO Kentaro) 1999/11/07

In message "[ruby-dev:8266] Re: 例外を処理する 2 項演算子"

[#8271] Re: 例外を処理する 2 項演算子 — matz@... (Yukihiro Matsumoto) 1999/11/08

まつもと ゆきひろです

[#8274] Re: 例外を処理する 2 項演算子 — keiju@... (石塚圭樹) 1999/11/08

けいじゅ@日本ラショナルソフトウェアです.

[#8204] Re: [ruby-list:18281] Re: アクセス制御について — Shugo Maeda <shugo@...>

前田です。

12 messages 1999/11/02
[#8205] Re: [ruby-list:18281] Re: アクセス制御について — Shin-ichiro Hara <sinara@...> 1999/11/02

原です。

[#8315] Re: [ruby-list:18601] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — Kazunori NISHI <kazunori@...>

西@九大です。

37 messages 1999/11/15
[#8316] Re: [ruby-list:18601] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — matz@... (Yukihiro Matsumoto) 1999/11/15

まつもと ゆきひろです

[#8369] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — Koji Arai <JCA02266@...> 1999/11/18

新井です。

[#8374] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — matz@... (Yukihiro Matsumoto) 1999/11/18

まつもと ゆきひろです

[#8384] Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{} — Koji Arai <JCA02266@...> 1999/11/19

新井です。

[#8405] 1.4.3 (Re: Re: [REQ] [].grep(pat){} ==> [].grep(pat).collect{}) — matz@... (Yukihiro Matsumoto) 1999/11/24

[#8319] Re: Exception handling — Jun Adachi <adachi@...>

安達@沖データと申します。

21 messages 1999/11/16
[#8350] Re: Exception handling — Kazunori NISHI <kazunori@...> 1999/11/17

西@九大です。

[#8446] [REQ] {enumerable, integer, range}.rand — Kazunori NISHI <kazunori@...>

西@九大です。

37 messages 1999/11/29
[#8449] Re: [REQ] {enumerable, integer, range}.rand — matz@... (Yukihiro Matsumoto) 1999/11/30

まつもと ゆきひろです

[#8463] Re: [REQ] {enumerable, integer, range}.rand — Kazunori NISHI <kazunori@...> 1999/11/30

西@九大です。

[#8474] Re: [REQ] {enumerable, integer, range}.rand — matz@... (Yukihiro Matsumoto) 1999/12/01

まつもと ゆきひろです

[#8476] Re: [REQ] {enumerable, integer, range}.rand — Kazunori NISHI <kazunori@...> 1999/12/01

西@九大です。

[#8487] Re: [REQ] {enumerable, integer, range}.rand — matz@... (Yukihiro Matsumoto) 1999/12/02

まつもと ゆきひろです

[#8494] Re: [REQ] {enumerable, integer, range}.rand — Kazunori NISHI <kazunori@...> 1999/12/02

西@九大です。

[#8451] new Hash (Re: [ruby-list:19043]) — Wakou Aoyama <wakou@...>

青山です。

18 messages 1999/11/30

[ruby-dev:8311] Re: [ruby-list:18316] Re: [book] csv_split2

From: Koretsugu Daigoro <tmmcross@...>
Date: 1999-11-13 04:55:58 UTC
List: ruby-dev #8311
これつぐです。


少し前の話ですが。

[ruby-list:18316] Re: [book] csv_split2
> まつもと ゆきひろです

> というか、String#scanとm//gの挙動の違いが原因のようです。
> scanの方は空パターンにマッチすると、無限ループになることを避
> けるために、1文字分ポインタを移動させます。ですから、次のマッ
> チは先頭からではなく、「"z"」の先頭に対して行われ、結果とし
> て(マッチしない)"z"の部分は無視されます。
> 
> ところがPerlの方ではどういうわけかポインタは進まず、より長い
> マッチが選択されるようです。この動作原理は良く分かりませんが、
> このルールが明確にできればRubyの方でも合わせることはできると
> 思います。どういうルールなんだろう? m//gが正規表現と一体化
> しているがゆえにできることなんだろうか?

まつもとさんもすでに見たと思いますが、
perlre によると zero-length match のあとの zero-length match を禁止し、
その代わりに( zero-length でない) the second best match が使われるようです。

--- perlre
       The higher level-loops preserve an additional state
       between iterations: whether the last match was zero-
       length.  To break the loop, the following match after a
       zero-length match is prohibited to have a length of zero.
       This prohibition interacts with backtracking (see the
       section on "Backtracking"), and so the second best match
       is chosen if the best match is of zero length.

       For example:

           $_ = 'bar';
           s/\w??/<$&>/g;

       results in `"<><b><><a><><r><>"'.  At each position of the
       string the best match given by non-greedy `??' is the
       zero-length match, and the second best match is what is
       matched by `\w'.  Thus zero-length matches alternate with
       one-character-long matches.
---

確認のために上記の例を Ruby と Perl でやってみました。
(あえて Perl 風に書いています)

$ perl -le '$_ = "bar"; s/\w??/<$&>/g; print'
<><b><><a><><r><>
$ ruby -le '$_ = "bar"; gsub(/\w??/,"<\\&>"); print'
<>b<>a<>r<>


で、
肝心の動作原理については、
私は C が読めない人なのではっきりとはわかりませんが、
ここが怪しいのではないかと思います。

--- regexec.c
STATIC I32			/* 0 failure, 1 success */
S_regmatch(pTHX_ regnode *prog)

-- 中略

	case END:

-- 中略

	    if (locinput < PL_regtill) {
		DEBUG_r(PerlIO_printf(Perl_debug_log,
				      "%sMatch possible, but length=%ld is smaller than requested=%ld, failing!%s\n",
				      PL_colors[4],
				      (long)(locinput - PL_reg_starttry),
				      (long)(PL_regtill - PL_reg_starttry),
				      PL_colors[5]));
		sayNO_FINAL;		/* Cannot match: too short. */
	    }
---

これを私は
「match に成功しても上記条件のときには失敗と扱う」
と理解しましたが……?

In This Thread

Prev Next