# Ambiguous first argument?

**URL:** <https://rubytalk.org/t/ambiguous-first-argument/59689>\
**Category:** ruby-talk\
**Created:** [19 August 2010 00:39 UTC](https://rubytalk.org/t/ambiguous-first-argument/59689 "2010-08-19T00:39:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger\_Pack4](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Roger\_Pack4](https://rubytalk.org/u/Roger_Pack4)\
**Post date:** [19 August 2010 00:39 UTC](https://rubytalk.org/t/ambiguous-first-argument/59689/1 "2010-08-19T00:39:13Z")

</div>

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/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Ryan\_Davis1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/ryan_davis1/32/1848_2.png) [@Ryan\_Davis1](https://rubytalk.org/u/Ryan_Davis1)\
**Post date:** [19 August 2010 01:51 UTC](https://rubytalk.org/t/ambiguous-first-argument/59689/2 "2010-08-19T01:51:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![GianFranco\_Bozzetti](https://avatars.discourse-cdn.com/v4/letter/g/7c8e57/32.png) [@GianFranco\_Bozzetti](https://rubytalk.org/u/GianFranco_Bozzetti)\
**Post date:** [19 August 2010 15:26 UTC](https://rubytalk.org/t/ambiguous-first-argument/59689/3 "2010-08-19T15:26:54Z")

</div>

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/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Rob\_Biedenharn1](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@Rob\_Biedenharn1](https://rubytalk.org/u/Rob_Biedenharn1)\
**Post date:** [19 August 2010 15:42 UTC](https://rubytalk.org/t/ambiguous-first-argument/59689/4 "2010-08-19T15:42:53Z")

</div>

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/](http://AgileConsultingLLC.com/)  
rab@GaslightSoftware.com [http://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/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Roger\_Pack4](https://avatars.discourse-cdn.com/v4/letter/r/bb73d2/32.png) [@Roger\_Pack4](https://rubytalk.org/u/Roger_Pack4)\
**Post date:** [19 August 2010 15:50 UTC](https://rubytalk.org/t/ambiguous-first-argument/59689/5 "2010-08-19T15:50:22Z")

</div>

> 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 🙂  
-r

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
