Ambiguous first argument?

Hi all.
With this code:

memory_bitmap.scan /\x00{5}+/

I get this warning:

test.rb:1: warning: ambiguous first argument; put parentheses or even
spaces

Could somebody please help me to understand what exactly is ambiguous
there?
Thank you!
-r

···

--
Posted via http://www.ruby-forum.com/.

2 / 2

2 / 2 /

···

On Aug 18, 2010, at 17:39 , Roger Pack wrote:

Hi all.
With this code:

memory_bitmap.scan /\x00{5}+/

I get this warning:

test.rb:1: warning: ambiguous first argument; put parentheses or even
spaces

Could somebody please help me to understand what exactly is ambiguous
there?

Roger Pack wrote:

Hi all.
With this code:

memory_bitmap.scan /\x00{5}+/

I get this warning:

test.rb:1: warning: ambiguous first argument; put parentheses or even
spaces

Could somebody please help me to understand what exactly is ambiguous
there?
Thank you!
-r

The ambiguity comes from the double quantifier {5}+ where:
- {5} means exactly 5 occurrences of \x00
- + means 1 or more occurrences of preceding expression.

Given the string:
bitmap="\x30\x50\-\x00\x00\x00\x00\x00\x00\-\x40\x50\x30"

p bitmap.scan(/\x00+/) #=> ["\000\000\000\000\000\000"]
p bitmap.scan(/\x00{2}/) #=> ["\000\000", "\000\000", "\000\000"]

HTH gfb

···

--
Posted via http://www.ruby-forum.com/\.

I think the ambiguity is actually in parsing:

memory_bitmap.scan / \x00 { 5 } + /
Is that perhaps dividing by the result of calling \x00 with a block?

Spaces won't help in this case, but some nice parentheses will do.

memory_bitmap.scan(/\x00{5}+/)

That will ensure that the parser sees /\x00{5}+/ as an argument to the scan method. Whether the Regexp does what you want/expect is another question.

-Rob

Rob Biedenharn
Rob@AgileConsultingLLC.com http://AgileConsultingLLC.com/
rab@GaslightSoftware.com http://GaslightSoftware.com/

···

On Aug 19, 2010, at 11:26 AM, Gianfranco Bozzetti wrote:

Roger Pack wrote:

Hi all.
With this code:

memory_bitmap.scan /\x00{5}+/

I get this warning:

test.rb:1: warning: ambiguous first argument; put parentheses or even
spaces

Could somebody please help me to understand what exactly is ambiguous
there?
Thank you!
-r

The ambiguity comes from the double quantifier {5}+ where:
- {5} means exactly 5 occurrences of \x00
- + means 1 or more occurrences of preceding expression.

Given the string:
bitmap="\x30\x50\-\x00\x00\x00\x00\x00\x00\-\x40\x50\x30"

p bitmap.scan(/\x00+/) #=> ["\000\000\000\000\000\000"]
p bitmap.scan(/\x00{2}/) #=> ["\000\000", "\000\000", "\000\000"]

HTH gfb
-- Posted via http://www.ruby-forum.com/\.

I think the ambiguity is actually in parsing:

memory_bitmap.scan / \x00 { 5 } + /
Is that perhaps dividing by the result of calling \x00 with a block?

Interesting. Ok thanks for all the responses.
It does work as expected :slight_smile:
-r

···

--
Posted via http://www.ruby-forum.com/\.