August 2004
[ bamboo ] 09:52, Tuesday, 31 August 2004

Simply amazing!

Just watch and check the coincidences for yourself. It's quite a trip.

[ bamboo ] 09:05, Monday, 30 August 2004

Edd Dumbill talks about one of the IronPython niceties here.

boo also allows it and it works not only with properties but with events and fields too:

import System

class Button:

    [property(Text)]
    _text = ""

    public Width = 0

    event Click as EventHandler
	
    def RaiseClick():
        self.Click(self, EventArgs.Empty)

b = Button(Text: "Click me", Width: 10, Click: )
print(b.Text)
print(b.Width)
b.RaiseClick()

Cool or what?

[ bamboo ] 13:45, Monday, 9 August 2004
It's been some time now since my notebook (as in "A light, portable computer that is generally thinner than a laptop") went to the repair shop and I feel extremely free.

I've been spending much more time with my family and friends ( including my books, comics and CDs). I still haven't got back to playing the drums but I'm sure I will... eventually.

Cutting straight to the chase I decided to finally work on issue BOO-17 (automatic callable type conversion and adaptation) so I grabbed my notebook (as in "A book of blank pages for notes") and programmed away. Programming on paper can be so much easier sometimes! A simple solution was already there just waiting for me to uncover it.

The problem I was trying to solve was twofold: first, delegate types (callables) are name equivalent not structurally equivalent in the CLI type system, in other words, the following valid boo code can not be directly translated to IL for being deemed unverifiable:
callable Function()

def foo():
   pass
   
# the following line silently generates a
# new (anonymous) callable type structurally
# equivalent to the declared callable Function1
# above
a = foo

fn as Function
fn = a
fn()
Second, boo compatibility rules for callable references go beyond simple structural equivalence, a RVALUE callable reference can be assigned to any LVALUE reference if any of the following conditions is true:
  • their types are the same (name equivalence)
  • their types are structurally equivalent (same number of arguments, arguments all of the same type, same return type)
  • the callable on the right takes the same number of arguments or less and all of them are assignment compatible with the arguments of the callable on the left
Example:
import System

def click1():
    print("clicked!")
	
def click2(sender):
	print("${sender} clicked!")
	
def click3(sender as string):
	print("${sender} clicked!")
	
handler as EventHandler

handler = click1
handler(null, EventArgs.Empty)

handler = click2
handler("foo", EventArgs.Empty)

handler = click3
handler("bar", EventArgs.Empty)

The Solution

It's actually pretty simple and it works for both cases: get the compiler to generate an adaptor class containing:
      a single argument constructor taking the RVALUE reference
      a method strictly compatible with the LVALUE reference
      a factory method that will take the RVALUE reference and return a LVALUE compatible reference
The only thing left to do is to replace the RVALUE reference by the factory method invocation. Making it all more concrete, the compiler must transform code like this:
callable Function()

def click():
    print("clicked!")
	
fn as Function = click

handler as EventHandler = fn
Into something like this:
callable Function()

class __Adaptor0__:

    __callable__ as Function

    def constructor(value as Function):
        self.__callable__ = value

    def Invoke(sender as object, args as System.EventArgs) as void:
        self.__callable__()

    static def Adapt(value as Function) as System.EventHandler:
        adapted = __Adaptor0__(value)
        return adapted.Invoke

def click():
    print("clicked!")

fn as Function = click
handler as EventHandler = __Adaptor0__.Adapt(fn)
Unfortunately my current notebook can't run unit tests yet :)
[ bamboo ] 11:35, Monday, 9 August 2004
Nice essay on Patents and Linux.
And just in case you are wondering I totally agree.
[ bamboo ] 15:28, Thursday, 5 August 2004

I've finally had the chance to watch Fahrenheit 9/11 last night. One of the funniest pieces I've seen in a long time.
The americans on the line behind us didn't seem to understand why I laughed all the way through.
Homer Simpson puts it best: "It's funny because it's true!".