<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Bamboozled</title><link>http://bamboo.github.com/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Bamboozled" /><language>en</language><managingEditor>rbo@acm.org (Rodrigo B. de Oliveira)</managingEditor><lastBuildDate>Wed, 19 Oct 2011 11:16:37 PDT</lastBuildDate><feedburner:info uri="bamboozled" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><description></description><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><item><title>boo metaprogramming facilities I - the ast</title><link>http://bamboo.github.com/2010/07/11/boo-meta-programming-facilities-I-the-ast.html</link><pubDate>Sun, 11 Jul 2010 00:00:00 PDT</pubDate><guid isPermaLink="false">tag:bamboo.github.com:/2010/07/11/boo-meta-programming-facilities-I-the-ast</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[The boo compiler follows the common design of internally representing code using what’s usually called a heterogeneous abstract syntax tree, ast for short. Code constructs such as class and method definitions, if and while statements, references and all sorts of expressions are represented by specific concrete types such as ClassDefinition, Method, IfStatement, WhileStatement, ReferenceExpression, etc.

In other words, given an arbitrary fragment of boo code:
    def ltuae():
        return 42


Its internal representation can be obtained through the chained instantiation of the right ast types:
    import Boo.Lang.Compiler.Ast
    fragment = Method(Name: "ltuae", Body: Block(ReturnStatement(IntegerLiteralExpression(42))))
    print fragment.ToCodeString()


Such an approach to ast construction however fundamental might lead very rapidly to unintelligible code so boo provides a more natural way of constructing and manipulating ast fragments through the use of code literals:
    fragment = [|
        def ltuae():
            return 42
    |]
    print fragment.ToCodeString()


[| and |] are the quasi-quotation markers and they instruct the compiler to produce the proper ast instantiation chain for the delimited code.

They can be used with expressions:
    expression = [| question is ltuae |]
    print expression.Operator         # ReferenceEquality
    print expression.Left.GetType()   # ReferenceExpression
    print expression.Right.GetType()  # ReferenceExpression


They can be used with statements:
    statement = [| 
        if question is ltuae:
            return 42
    |]
    print statement.Condition # (question is ltuae)


As well as with complete type definitions:
    type = [|
         class BigThinker:
             def ltuae():
                 return 42
    |]
    for member in type.Members:
        print member.Name


Code literals also provide for a simple way of assembling larger code structures out of smaller fragments:
    def bigThinkerOf(thought as Boo.Lang.Compiler.Ast.Expression):
        return [|
            class BigThinker:
                def ltuae():
                    return $thought
        |]
        
    for member in bigThinkerOf([| 42 |]).Members:
        print member.ToCodeString()


$ is the splicing operator and it instructs the compiler to inject the marked expression into the ast instantiation chain.

Primitive values can also be spliced in:
    primitive = 42
    fragment = [| $primitive |]
    print fragment.GetType() # IntegerLiteralExpression


Getting an ast fragment out of a primitive value is called lifting and can be more directly achieved through one of the many Expression.Lift, Statement.Lift and TypeReference.Lift overloads:
    fragment = Boo.Lang.Compiler.Ast.Expression.Lift(42)
    print fragment.GetType() # IntegerLiteralExpression


Complex expressions can be spliced in but must be parenthesized for disambiguation:
    primitive = 42
    fragment = [| $(primitive.ToString()) |] # in contrast to [| $primitive.ToString() |] 
    print fragment.GetType() # StringLiteralExpression


And finally an ast fragment can be compiled into runnable code using one of the compile primitives available in the Boo.Lang.Compiler.MetaProgramming namespace:
    import Boo.Lang.Compiler.MetaProgramming
    
    ast = [|
        class BigThinker:
    	    def ltuae():
                return 42
    |]
    type = compile(ast)
    instance as duck = type() # duck typing to the rescue
    print instance.ltuae()


Runtime code generation is a useful technique but most really interesting metaprogramming opportunities manifest themselves at compile time through one of the extension points provided by boo: attributes, macros, metafunctions and the compilation pipeline which shall all be covered next.]]></content:encoded><description>The boo compiler follows the common design of internally representing code using what’s usually called a heterogeneous abstract syntax tree, ast for short. Code constructs such as class and method definitions, if and while statements, references and all sorts of expressions are represented by specific concrete types such as ClassDefinition, Method, IfStatement, WhileStatement, ReferenceExpression, etc.

In other words, given an arbitrary fragment of boo code:
    def ltuae():
        return 42


Its internal representation can be obtained through the chained instantiation of the right ast types:
    import Boo.Lang.Compiler.Ast
    fragment = Method(Name: "ltuae", Body: Block(ReturnStatement(IntegerLiteralExpression(42))))
    print fragment.ToCodeString()


Such an approach to ast construction however fundamental might lead very rapidly to unintelligible code so boo provides a more natural way of constructing and manipulating ast fragments through the use of code literals:
    fragment = [|
        def ltuae():
            return 42
    |]
    print fragment.ToCodeString()


[| and |] are the quasi-quotation markers and they instruct the compiler to produce the proper ast instantiation chain for the delimited code.

They can be used with expressions:
    expression = [| question is ltuae |]
    print expression.Operator         # ReferenceEquality
    print expression.Left.GetType()   # ReferenceExpression
    print expression.Right.GetType()  # ReferenceExpression


They can be used with statements:
    statement = [| 
        if question is ltuae:
            return 42
    |]
    print statement.Condition # (question is ltuae)


As well as with complete type definitions:
    type = [|
         class BigThinker:
             def ltuae():
                 return 42
    |]
    for member in type.Members:
        print member.Name


Code literals also provide for a simple way of assembling larger code structures out of smaller fragments:
    def bigThinkerOf(thought as Boo.Lang.Compiler.Ast.Expression):
        return [|
            class BigThinker:
                def ltuae():
                    return $thought
        |]
        
    for member in bigThinkerOf([| 42 |]).Members:
        print member.ToCodeString()


$ is the splicing operator and it instructs the compiler to inject the marked expression into the ast instantiation chain.

Primitive values can also be spliced in:
    primitive = 42
    fragment = [| $primitive |]
    print fragment.GetType() # IntegerLiteralExpression


Getting an ast fragment out of a primitive value is called lifting and can be more directly achieved through one of the many Expression.Lift, Statement.Lift and TypeReference.Lift overloads:
    fragment = Boo.Lang.Compiler.Ast.Expression.Lift(42)
    print fragment.GetType() # IntegerLiteralExpression


Complex expressions can be spliced in but must be parenthesized for disambiguation:
    primitive = 42
    fragment = [| $(primitive.ToString()) |] # in contrast to [| $primitive.ToString() |] 
    print fragment.GetType() # StringLiteralExpression


And finally an ast fragment can be compiled into runnable code using one of the compile primitives available in the Boo.Lang.Compiler.MetaProgramming namespace:
    import Boo.Lang.Compiler.MetaProgramming
    
    ast = [|
        class BigThinker:
    	    def ltuae():
                return 42
    |]
    type = compile(ast)
    instance as duck = type() # duck typing to the rescue
    print instance.ltuae()


Runtime code generation is a useful technique but most really interesting metaprogramming opportunities manifest themselves at compile time through one of the extension points provided by boo: attributes, macros, metafunctions and the compilation pipeline which shall all be covered next.</description></item><item><title>Agile Development Ethics</title><link>http://bamboo.github.com/2009/11/07/agile-development-ethics.html</link><pubDate>Sat, 07 Nov 2009 00:00:00 PST</pubDate><guid isPermaLink="false">tag:bamboo.github.com:/2009/11/07/agile-development-ethics</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[Basic Assumptions

The purpose of a system is to maximize a user’s capacity for creative expression.

“There is nothing so stable as change.”

Values

Learning. The more the team learns the faster the system converges to its purpose. Learning is the smooth embracing of change.

Courage. It takes courage to accept ignorance, one’s own and someone else’s. It might take courage to trust one’s best informed judgement at times. Courage keeps the team moving forward.

Principles

Automate Answers to Important Questions: the most important of which would arguably be “Is the system ready to provide a better experience for its users?” commonly phrased as “Can we ship it?”.

Don’t Repeat Yourself. Repeatition hinders one’s ability to respond to change.

Code of Ethics

Team comprises everyone that care to contribute to the system’s fulfillment of its purpose.

Actions that hurt a user’s ability for creative expression are unethical.

Actions that diminish a team’s ability to respond to change are unethical.

Actions that neither diminish nor improve a team’s ability to respond to change are neutral.

Actions that improve a team’s ability to respond to change are ethical given they don’t hurt a user’s ability for creative expression.]]></content:encoded><description>Basic Assumptions

The purpose of a system is to maximize a user’s capacity for creative expression.

“There is nothing so stable as change.”

Values

Learning. The more the team learns the faster the system converges to its purpose. Learning is the smooth embracing of change.

Courage. It takes courage to accept ignorance, one’s own and someone else’s. It might take courage to trust one’s best informed judgement at times. Courage keeps the team moving forward.

Principles

Automate Answers to Important Questions: the most important of which would arguably be “Is the system ready to provide a better experience for its users?” commonly phrased as “Can we ship it?”.

Don’t Repeat Yourself. Repeatition hinders one’s ability to respond to change.

Code of Ethics

Team comprises everyone that care to contribute to the system’s fulfillment of its purpose.

Actions that hurt a user’s ability for creative expression are unethical.

Actions that diminish a team’s ability to respond to change are unethical.

Actions that neither diminish nor improve a team’s ability to respond to change are neutral.

Actions that improve a team’s ability to respond to change are ethical given they don’t hurt a user’s ability for creative expression.</description></item><item><title>Environment Based Programming Design Pattern</title><link>http://bamboo.github.com/2009/02/16/environment-based-programming.html</link><pubDate>Mon, 16 Feb 2009 00:00:00 PST</pubDate><guid isPermaLink="false">tag:bamboo.github.com:/2009/02/16/environment-based-programming</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[Motivations:


You want to decouple the different components of a system;

You want to minimize the scope of their dependencies;

You are developing a system that needs to support dynamic reconfigurability;

You want a simple programming model that stirs you in the direction of better dependency management.


Environment Based Programming* is a design pattern founded on a very simple principle:



Code executes in an environment that provides it with all its needs.

This principle can be completely captured in C# with the following API:


        namespace EnvironmentBasedProgramming
        {
            public delegate void Code();
            
            public interface IEnvironment
            {
                Need Provide<Need>();
            }
        
            public static class Environments
            {   
                /// <summary>
                /// Executes code in a given environment.
                /// </summary>
                public static void With(IEnvironment environment, Code code);
            }
        
            /// <summary>
            /// Used by code to fulfill its needs.
            /// </summary>
            public static class My<Need>
            {
                public static Need Instance { get; }
            }
        }


To make it all concrete I’ll use Martin Fowler’s naive example specially for the contrast with the dependency management approaches he documents in his article. The MovieLister component provides a list of movies directed by a particular director. In order to fulfill its contract it needs the list of all known movies, something that a MovieFinder service would provide:
        interface IMovieFinder
        {
            IEnumerable<Movie> FindAll();
        }
        
        class MovieLister
        {
            public IEnumerable<Movie> MoviesDirectedBy(string directorName)
            {
                var movies = My<IMovieFinder>.Instance.FindAll();
                foreach (var movie in movies)
                    if (movie.Director == directorName)
                        yield return movie;
            }
        }


Notice how the code express its needs using the My idiom.

MovieLister can now be executed in a suitable environment using the With primitive:
        Environments.With(environment, delegate
        {
            foreach (var movie in new MovieLister().MoviesDirectedBy("Terry Jones"))
                Console.WriteLine(movie.Title);
        });


A suitable environment in this case would have to deliver a valid IMoveFinder instance upon request. The following implementation should suffice:
        class DummyMovieFinder : IMovieFinder
        {   
            public IEnumerable<Movie> FindAll()
            {
                yield return new Movie {Director = "Terry Jones", Title = "Erik The Viking"};
                yield return new Movie {Director = "Terry Gilliam", Title = "Fear and Loathing in Las Vegas"};
            }
        }


The missing piece in the puzzle is the final EBP building block - ClosedEnvironment:
        public class ClosedEnvironment : IEnvironment
        {
            private readonly object[] _bindings;
    
            public ClosedEnvironment(params object[] bindings)
            {
                _bindings = bindings;
            }
            
            public T Provide<T>()
            {
                foreach (var binding in _bindings)
                    if (binding is T)
                        return (T) binding;
                return default(T);
            }
        }


Which allows the environment for the example to be defined as:
    var environment = new ClosedEnvironment(new DummyMovieFinder());


Component activation and lifetime are not aspects dealt directly with by EBP and are better treated as different environment strategies (one can easily imagine an environment that automatically instantiates components based on naming conventions or metadata).

The complete listings follow.

The example:
        namespace EnvironmentBasedProgramming.NaiveExample
        {
            using System;
            using System.Collections.Generic;
        
            class Movie
            {
                public string Title { get; set; }
                public string Director { get; set; }
            }
        
            interface IMovieFinder
            {
                IEnumerable<Movie> FindAll();
            }
        
            class MovieLister
            {
                public IEnumerable<Movie> MoviesDirectedBy(string directorName)
                {
                    var movies = My<IMovieFinder>.Instance.FindAll();
                    foreach (var movie in movies)
                        if (movie.Director == directorName)
                            yield return movie;
                }
            }
        
            class Program
            {
                static void Main(string[] args)
                {
                    var environment = new ClosedEnvironment(new DummyMovieFinder());
                    Environments.With(environment, delegate
                    {
                        PrintMoviesDirectedBy("Terry Jones");
                    });
                }
        
                private static void PrintMoviesDirectedBy(string directorName)
                {
                    foreach (var movie in new MovieLister().MoviesDirectedBy(directorName))
                        Console.WriteLine(movie.Title);
                }
        
                class DummyMovieFinder : IMovieFinder
                {   
                    public IEnumerable<Movie> FindAll()
                    {
                        yield return new Movie {Director = "Terry Jones", Title = "Erik The Viking"};
                        yield return new Movie {Director = "Terry Gilliam", Title = "Fear and Loathing in Las Vegas"};
                    }
                }
            }
        }


The minimalist EBP framework written for this article:
        namespace EnvironmentBasedProgramming
        {
            using System;
        
            public delegate void Code();
        
            public interface IEnvironment
            {
                Need Provide<Need>();
            }
        
            public static class Environments
            {   
                /// <summary>
                /// Executes code in a given environment.
                /// </summary>
                public static void With(IEnvironment environment, Code code)
                {
                    IEnvironment previous = _environment;
                    _environment = environment;
                    try
                    {
                        code();
                    }
                    finally
                    {
                        _environment = previous;
                    }
                }
        
                private static IEnvironment _environment;
        
                internal static IEnvironment Current
                {
                    get { return _environment; }
                }
            }
        
            /// <summary>
            /// Used by code to fulfill its needs.
            /// </summary>
            public static class My<Need>
            {
                public static Need Instance
                {
                    get
                    {
                        var current = Environments.Current;
                        if (current == null)
                            throw new InvalidOperationException("No environment to provide '" + typeof(Need) + "'.");
                        return current.Provide<Need>();
                    }
                }
            }
        
            public class ClosedEnvironment : IEnvironment
            {
                private readonly object[] _bindings;
        
                public ClosedEnvironment(params object[] bindings)
                {
                    _bindings = bindings;
                }
                
                public T Provide<T>()
                {
                    foreach (var binding in _bindings)
                        if (binding is T)
                            return (T) binding;
                    return default(T);
                }
            }
        }


In a future article I’ll explore environment chaining and convention based service discovery. Thoughts?


or to use a name more to the style of Martin Fowler: Dynamically Scoped Service Locator (not to be confused with Dynamic Service Locator)
]]></content:encoded><description>Motivations:


You want to decouple the different components of a system;

You want to minimize the scope of their dependencies;

You are developing a system that needs to support dynamic reconfigurability;

You want a simple programming model that stirs you in the direction of better dependency management.


Environment Based Programming* is a design pattern founded on a very simple principle:



Code executes in an environment that provides it with all its needs.

This principle can be completely captured in C# with the following API:


        namespace EnvironmentBasedProgramming
        {
            public delegate void Code();
            
            public interface IEnvironment
            {
                Need Provide&amp;lt;Need&amp;gt;();
            }
        
            public static class Environments
            {   
                /// &amp;lt;summary&amp;gt;
                /// Executes code in a given environment.
                /// &amp;lt;/summary&amp;gt;
                public static void With(IEnvironment environment, Code code);
            }
        
            /// &amp;lt;summary&amp;gt;
            /// Used by code to fulfill its needs.
            /// &amp;lt;/summary&amp;gt;
            public static class My&amp;lt;Need&amp;gt;
            {
                public static Need Instance { get; }
            }
        }


To make it all concrete I’ll use Martin Fowler’s naive example specially for the contrast with the dependency management approaches he documents in his article. The MovieLister component provides a list of movies directed by a particular director. In order to fulfill its contract it needs the list of all known movies, something that a MovieFinder service would provide:
        interface IMovieFinder
        {
            IEnumerable&amp;lt;Movie&amp;gt; FindAll();
        }
        
        class MovieLister
        {
            public IEnumerable&amp;lt;Movie&amp;gt; MoviesDirectedBy(string directorName)
            {
                var movies = My&amp;lt;IMovieFinder&amp;gt;.Instance.FindAll();
                foreach (var movie in movies)
                    if (movie.Director == directorName)
                        yield return movie;
            }
        }


Notice how the code express its needs using the My idiom.

MovieLister can now be executed in a suitable environment using the With primitive:
        Environments.With(environment, delegate
        {
            foreach (var movie in new MovieLister().MoviesDirectedBy("Terry Jones"))
                Console.WriteLine(movie.Title);
        });


A suitable environment in this case would have to deliver a valid IMoveFinder instance upon request. The following implementation should suffice:
        class DummyMovieFinder : IMovieFinder
        {   
            public IEnumerable&amp;lt;Movie&amp;gt; FindAll()
            {
                yield return new Movie {Director = "Terry Jones", Title = "Erik The Viking"};
                yield return new Movie {Director = "Terry Gilliam", Title = "Fear and Loathing in Las Vegas"};
            }
        }


The missing piece in the puzzle is the final EBP building block - ClosedEnvironment:
        public class ClosedEnvironment : IEnvironment
        {
            private readonly object[] _bindings;
    
            public ClosedEnvironment(params object[] bindings)
            {
                _bindings = bindings;
            }
            
            public T Provide&amp;lt;T&amp;gt;()
            {
                foreach (var binding in _bindings)
                    if (binding is T)
                        return (T) binding;
                return default(T);
            }
        }


Which allows the environment for the example to be defined as:
    var environment = new ClosedEnvironment(new DummyMovieFinder());


Component activation and lifetime are not aspects dealt directly with by EBP and are better treated as different environment strategies (one can easily imagine an environment that automatically instantiates components based on naming conventions or metadata).

The complete listings follow.

The example:
        namespace EnvironmentBasedProgramming.NaiveExample
        {
            using System;
            using System.Collections.Generic;
        
            class Movie
            {
                public string Title { get; set; }
                public string Director { get; set; }
            }
        
            interface IMovieFinder
            {
                IEnumerable&amp;lt;Movie&amp;gt; FindAll();
            }
        
            class MovieLister
            {
                public IEnumerable&amp;lt;Movie&amp;gt; MoviesDirectedBy(string directorName)
                {
                    var movies = My&amp;lt;IMovieFinder&amp;gt;.Instance.FindAll();
                    foreach (var movie in movies)
                        if (movie.Director == directorName)
                            yield return movie;
                }
            }
        
            class Program
            {
                static void Main(string[] args)
                {
                    var environment = new ClosedEnvironment(new DummyMovieFinder());
                    Environments.With(environment, delegate
                    {
                        PrintMoviesDirectedBy("Terry Jones");
                    });
                }
        
                private static void PrintMoviesDirectedBy(string directorName)
                {
                    foreach (var movie in new MovieLister().MoviesDirectedBy(directorName))
                        Console.WriteLine(movie.Title);
                }
        
                class DummyMovieFinder : IMovieFinder
                {   
                    public IEnumerable&amp;lt;Movie&amp;gt; FindAll()
                    {
                        yield return new Movie {Director = "Terry Jones", Title = "Erik The Viking"};
                        yield return new Movie {Director = "Terry Gilliam", Title = "Fear and Loathing in Las Vegas"};
                    }
                }
            }
        }


The minimalist EBP framework written for this article:
        namespace EnvironmentBasedProgramming
        {
            using System;
        
            public delegate void Code();
        
            public interface IEnvironment
            {
                Need Provide&amp;lt;Need&amp;gt;();
            }
        
            public static class Environments
            {   
                /// &amp;lt;summary&amp;gt;
                /// Executes code in a given environment.
                /// &amp;lt;/summary&amp;gt;
                public static void With(IEnvironment environment, Code code)
                {
                    IEnvironment previous = _environment;
                    _environment = environment;
                    try
                    {
                        code();
                    }
                    finally
                    {
                        _environment = previous;
                    }
                }
        
                private static IEnvironment _environment;
        
                internal static IEnvironment Current
                {
                    get { return _environment; }
                }
            }
        
            /// &amp;lt;summary&amp;gt;
            /// Used by code to fulfill its needs.
            /// &amp;lt;/summary&amp;gt;
            public static class My&amp;lt;Need&amp;gt;
            {
                public static Need Instance
                {
                    get
                    {
                        var current = Environments.Current;
                        if (current == null)
                            throw new InvalidOperationException("No environment to provide '" + typeof(Need) + "'.");
                        return current.Provide&amp;lt;Need&amp;gt;();
                    }
                }
            }
        
            public class ClosedEnvironment : IEnvironment
            {
                private readonly object[] _bindings;
        
                public ClosedEnvironment(params object[] bindings)
                {
                    _bindings = bindings;
                }
                
                public T Provide&amp;lt;T&amp;gt;()
                {
                    foreach (var binding in _bindings)
                        if (binding is T)
                            return (T) binding;
                    return default(T);
                }
            }
        }


In a future article I’ll explore environment chaining and convention based service discovery. Thoughts?


or to use a name more to the style of Martin Fowler: Dynamically Scoped Service Locator (not to be confused with Dynamic Service Locator)
</description></item><item><title>boo, ometa and extensible parsing I</title><link>http://bamboo.github.com/2008/08/05/boo-ometa-and-extensible-parsing-I.html</link><pubDate>Tue, 05 Aug 2008 00:00:00 PDT</pubDate><guid isPermaLink="false">tag:bamboo.github.com:/2008/08/05/boo-ometa-and-extensible-parsing-I</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[Meanwhile in a repository not far away:
namespace metaboo

import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast
import Boo.OMeta
import Boo.OMeta.Parser

syntax Units:
	atom = mass | super
	mass = (integer >> value as Expression, "kg") ^ [| Mass($value, "kg") |]

syntax Ranges:
	atom = integer_range | super
	integer_range = (integer >> begin as Expression, DOT, DOT, integer >> end as Expression) ^ [| range($begin, $end) |]

def parse(code as string):
	compiler = BooCompiler()
	compiler.Parameters.References.Add(System.Reflection.Assembly.GetExecutingAssembly())
	compiler.Parameters.Input.Add(IO.StringInput("code", code))
	compiler.Parameters.Pipeline = CompilerPipeline()
	compiler.Parameters.Pipeline.Add(BooParserStep())
	return compiler.Run()

code = """
import metaboo.Units
import metaboo.Ranges
a = 3kg
print a
for i in 1..3:
	print i
"""

result = parse(code)
assert 0 == len(result.Errors), result.Errors.ToString()
assert 1 == len(result.CompileUnit.Modules)
print result.CompileUnit.Modules[0].ToCodeString()


And the output is, of course:

import metaboo.Units
import metaboo.Ranges

a = Mass(3, 'kg')
print a
for i in range(1, 3):
    print i]]></content:encoded><description>Meanwhile in a repository not far away:
namespace metaboo

import Boo.Lang.Compiler
import Boo.Lang.Compiler.Ast
import Boo.OMeta
import Boo.OMeta.Parser

syntax Units:
	atom = mass | super
	mass = (integer &amp;gt;&amp;gt; value as Expression, "kg") ^ [| Mass($value, "kg") |]

syntax Ranges:
	atom = integer_range | super
	integer_range = (integer &amp;gt;&amp;gt; begin as Expression, DOT, DOT, integer &amp;gt;&amp;gt; end as Expression) ^ [| range($begin, $end) |]

def parse(code as string):
	compiler = BooCompiler()
	compiler.Parameters.References.Add(System.Reflection.Assembly.GetExecutingAssembly())
	compiler.Parameters.Input.Add(IO.StringInput("code", code))
	compiler.Parameters.Pipeline = CompilerPipeline()
	compiler.Parameters.Pipeline.Add(BooParserStep())
	return compiler.Run()

code = """
import metaboo.Units
import metaboo.Ranges
a = 3kg
print a
for i in 1..3:
	print i
"""

result = parse(code)
assert 0 == len(result.Errors), result.Errors.ToString()
assert 1 == len(result.CompileUnit.Modules)
print result.CompileUnit.Modules[0].ToCodeString()


And the output is, of course:

import metaboo.Units
import metaboo.Ranges

a = Mass(3, 'kg')
print a
for i in range(1, 3):
    print i</description></item><item><title>Back from Mono Summit 2007</title><link>http://bamboo.github.com/2007/12/04/back-from-mono-summit-07.html</link><pubDate>Tue, 04 Dec 2007 00:00:00 PST</pubDate><guid isPermaLink="false">tag:bamboo.github.com:/2007/12/04/back-from-mono-summit-07</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[

What a great experience.

A chance to interact live with a dear friend. Free Software, Hacking, Women, Futurama, McDonalds, love spreading, Militant Atheism, Monty Python, Douglas Adams and the French Way.

Had lots of interesting exchange of ideas with Massi, ranging from “extensible parsing through composeable PEGs with optimal performance” to Carlos Castañeda, Jesus Christ, meta-physics, religion and Pink Floyd. The Cryptonomicon really got me.

Got to put a face on Joachim and see how really cool Unity is.

Jeroen IKVM Frijters is a funny guy!

On Thursday I got to talk about db4o which led me to meet a few db4o users hanging around the conference.


Pedro Santos had an interesting question, how to monitor and control the usage of computational resources in a managed client/server application? In other words, how a sysadmin can make sure a specific client won’t DOS the application?



For .NET servers running on Windows there are performance counters, what about Mono servers running on Linux?


I’ve also got to spread the gospel about boo for which I got a hugely positive response.


Thomas “Gaia” Hansen seemed to really get it and so we had lots of interesting discussions on how to take over the world boo style.



Jackson wants to hack on better nullable type support for boo!



Mark wants an extensible language where NullReferenceExceptions are impossible.



Miguel reassured me once again mcs won’t be rewritten on top of the boo compiler infrastructure :)


The presentation material is here.

Looking forward to the next one.]]></content:encoded><description>

What a great experience.

A chance to interact live with a dear friend. Free Software, Hacking, Women, Futurama, McDonalds, love spreading, Militant Atheism, Monty Python, Douglas Adams and the French Way.

Had lots of interesting exchange of ideas with Massi, ranging from “extensible parsing through composeable PEGs with optimal performance” to Carlos Castañeda, Jesus Christ, meta-physics, religion and Pink Floyd. The Cryptonomicon really got me.

Got to put a face on Joachim and see how really cool Unity is.

Jeroen IKVM Frijters is a funny guy!

On Thursday I got to talk about db4o which led me to meet a few db4o users hanging around the conference.


Pedro Santos had an interesting question, how to monitor and control the usage of computational resources in a managed client/server application? In other words, how a sysadmin can make sure a specific client won’t DOS the application?



For .NET servers running on Windows there are performance counters, what about Mono servers running on Linux?


I’ve also got to spread the gospel about boo for which I got a hugely positive response.


Thomas “Gaia” Hansen seemed to really get it and so we had lots of interesting discussions on how to take over the world boo style.



Jackson wants to hack on better nullable type support for boo!



Mark wants an extensible language where NullReferenceExceptions are impossible.



Miguel reassured me once again mcs won’t be rewritten on top of the boo compiler infrastructure :)


The presentation material is here.

Looking forward to the next one.</description></item><item><title>Introducing boojay</title><link>http://bamboo.github.com/2007/10/23/introducing-boojay.html</link><pubDate>Tue, 23 Oct 2007 00:00:00 PDT</pubDate><guid isPermaLink="false">tag:bamboo.github.com:/2007/10/23/introducing-boojay</guid><content:encoded xmlns:content="http://purl.org/rss/1.0/modules/content/"><![CDATA[    import org.eclipse.swt
    import org.eclipse.swt.widgets
    
    display = Display()
    shell = Shell(display)
    shell.setText("Hello!")
    shell.setSize(200, 200)
    shell.open()
    while not shell.isDisposed():
        if not display.readAndDispatch():
            display.sleep()
            
    display.dispose()


A boo application using the SWT java GUI library. Thanks to IKVM that’s not only possible but very simple as well.

So what’s the news? Well, Friday morning I was chatting with Klaus and he said to me “if you get boo to emit java bytecodes I’ll do all my stuff in boo”. How’s that for a challenge? :)

Thanks again to IKVM, ObjectWeb ASM and the extensible boo pipeline architecture after a weekend of relaxed hacking boojay was born.

UPDATE: Just in case it’s not clear, the generated class files DO NOT require IKVM in any way and can be executed in any compliant JVM.]]></content:encoded><description>    import org.eclipse.swt
    import org.eclipse.swt.widgets
    
    display = Display()
    shell = Shell(display)
    shell.setText("Hello!")
    shell.setSize(200, 200)
    shell.open()
    while not shell.isDisposed():
        if not display.readAndDispatch():
            display.sleep()
            
    display.dispose()


A boo application using the SWT java GUI library. Thanks to IKVM that’s not only possible but very simple as well.

So what’s the news? Well, Friday morning I was chatting with Klaus and he said to me “if you get boo to emit java bytecodes I’ll do all my stuff in boo”. How’s that for a challenge? :)

Thanks again to IKVM, ObjectWeb ASM and the extensible boo pipeline architecture after a weekend of relaxed hacking boojay was born.

UPDATE: Just in case it’s not clear, the generated class files DO NOT require IKVM in any way and can be executed in any compliant JVM.</description></item></channel></rss>

