I got Boo SVN access. My first commit was a feature, BOO-675 I think, basically better delegate adaption. Boo is smarter now.
In .NET 2.0, the Thread constructor has can accept two kinds of delegates. One of them is parameterless, one takes one object as a parameter.
This meant that Boo had ambiugation problems with this kind of code:
t = Thread( { print 'Boo!' } ) because it wasn't sure if the closure was a ThreadStart delegate or a ParameterizedThreadStart delegate. I modified the scoring system so that Boo would check a callable (closure, first class function, etc) compared to any delegates it might match. In the example I just gave you, the scoring algorithm would give higher precedence to ThreadStart instead of ParameterizedThreadStart, since ParameterizedThreadStart takes one parameter, while ThreadStart takes no parameter--and this matches, perfectly, the callable, that does not accept a parameter either.
In the case of t = Thread( { i| print i } ) Boo would pick ParameterizedThreadStart instead, since they both match the best (one parameter!)
I also added the any() and all() functions. BOO-604. Here's a quick self-explaintory sample.
import System
import Useful.Functional from 'Boo.Lang.Useful'
class Vector:
public X as int
public Y as int
static id as int
def constructor():
id++
def constructor(x as int, y as int):
self()
X = x
Y = y
def ToString():
return "Vector #${id}; (${X}, ${Y})"
Above:
get:
return X >= 0
vectors = []
r = Random(DateTime.Now.Second)
gimmie = { return r.Next(-5, 5) }
for index in range(10):
vectors.Add(Vector(gimmie(), gimmie()))
#for the sake of argument let's say this is a videogame.
#we're making sure none of our vectors are in the negative, since that means they're underwater or something.
result = all(vectors).Above
if result:
print 'All vectors above ground'
print result
else:
print 'There are vectors not above ground!'
print 'The following vectors failed.'
print result.Failed
#Let's assume this is a vehicle coordinate system. At least one of the vehicle's vectors has to be above ground
#for it to be working correctly.
result = any(vectors).Above
if result:
print 'At least one vector above ground'
print result
else:
print 'None of the vectors above ground!'
print 'The following vectors failed'
print result.Failed
Here's some sample output.
There are vectors not above ground!
The following vectors failed.
[Vector #10; (-2, 0), Vector #10; (-4, 2), Vector #10; (-4, 0), Vector #10; (-5,
-1), Vector #10; (-5, 1)]
At least one vector above ground
Passed (5): [Vector #10; (3, -1), Vector #10; (2, -3), Vector #10; (2, -3), Vect
or #10; (4, -3), Vector #10; (3, 4)]
Failed (5): [Vector #10; (-2, 0), Vector #10; (-4, 2), Vector #10; (-4, 0), Vect
or #10; (-5, -1), Vector #10; (-5, 1)]
Its a bit more useful in actual practice.
EDIT: oops. You'll notice I made a juvenile mistake with the id. I meant to have a private _id property to go with the static id property, but I got bogged down in tracking down a bug I found in the any/all implementation concerning null values. Tch. Oh well. Go ahead, laugh, jackass.
The upside is that the anyall module is now minus 1 bug. ;)
Dolla Dolla Bills
Haven't gotten much love on the code front, lately. Not surprised--the usual suspects seem to be busy or not in desperate need of a code mercenary. However, the prospect of having to float a resume'--an actual, genuine resume'--on somewhere like Monster.com does not strike a chord with me. Hopefully something comes my way, as I'm not looking to get my fingers into anything seriously long term--I like the short-term hit-and-run kind of stuff, myself.
We'll see what happens.
No comments:
Post a Comment