<p>I thought I'd implement some missing members on the String class in order to get my feet wet and start to understand the software. I chose String.scan on the grounds that it was a fairly common function (between 20 and 30 references in the standard library) with straightforward semantics, but one which requires dealing with overloads and blocks.
</p>
<p>There are basically four variations of this function:<br>String.scan <string><br>String.scan <regexp><br>String.scan <string>, <block><br>String.scan <regexp>, <block></p>
<p>I've attempted to implement each of these, and believe that all but the last are correct. The <string> variations are implemented in two different flavors for both CLR strings and mutable strings. A patch can be found at
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://hagenlocher.org/software/MutableString.scan.patch.txt" target="_blank">http://hagenlocher.org/software/MutableString.scan.patch.txt</a></p>
<p>The two issues I ran into are as follows:<br>1) The overload mechanism is picking the wrong method at runtime. Here are two of the function prototypes:</p>
<p>[RubyMethodAttribute("scan", RubyMethodAttributes.PublicInstance)]<br>public static List<object> Scan(MutableString/*!*/ self, MutableString/*!*/ searchStr)</p>
<div>[RubyMethodAttribute("scan", RubyMethodAttributes.PublicInstance)]<br>public static object Scan(CodeContext/*!*/ context, MutableString/*!*/ self, MutableString searchStr, BlockParam block)</div>
<div> </div>
<div>When I run from rbx.exe, I get the following:</div>
<div><font face="courier new,monospace">>>> "hello world".scan("l")<br>=> ["l", "l", "l"]</font></div>
<div><font face="courier new,monospace">>>> "hello world".scan("l") {|x| print x}<br>=> ["l", "l", "l"]<br></font></div>
<div> </div>
<div>In contrast, CRuby gives this:</div>
<div><font face="courier new,monospace">irb(main):001:0> "hello world".scan("l")<br>=> ["l", "l", "l"]<br>irb(main):002:0> "hello world".scan("l") {|x| print x}
<br>lll=> "hello world"</font></div>
<div> </div>
<div>Am I doing something wrong, or is this a bug? (I have obviously updated Initializer.Generated.cs, or neither scan would have been found :).</div>
<div> </div>
<div>2) My implementation of String.scan <regexp>, <block> is incomplete. This function is defined to behave as follows:</div><font face="courier new,monospace"> a.scan(/\w+/) {|w| print "<<#{w}>> " }
<br> a.scan(/(.)(.)/) {|x,y| print y, x }<br></font>
<div> </div>
<div>In other words, the number of parameters being passed to the block is equal to the number of groups defined in the regular expression -- or 1 if there are no groups defined. I haven't been able to find way to pass parameters or define a call site or that would support this.
</div>
<div> </div>
<div> </div>
<div>Finally, it's a bit annoying to rebuild Initializer.Generated.cs. Whenever you change a method signature, you have to manually delete the appropriate part of the old file in order to regenerate it, or you'll get an error. I've made an empty version of that source file and a batch file that copies it on top of the previous version before rebuilding ClassInitGenerator. Assuming that the architecture is going to be here for a while, it would be nice if there were a target in the Rakefile that performed these steps.
</div>
<div> </div>
<div>After a few more hours of this, I may have to figure out how to do that myself. :)</div>
<div> </div>
<div>--</div>
<div>Curt Hagenlocher</div>
<div><a href="mailto:curt@hagenlocher.org">curt@hagenlocher.org</a></div>