I just got done reaing a very intesting article about domain specific languages:
His examples are in Boo, I would highly recommend at least looking through his code snippets, especially the one towards the end related to the “ensure” attribute.
I just got done reaing a very intesting article about domain specific languages:
His examples are in Boo, I would highly recommend at least looking through his code snippets, especially the one towards the end related to the “ensure” attribute.
One interesting feature of boo is the ability to do dynamic typing. To do dynamic typing in boo you simply have to declare a variable as type “duck”, which is a reference to Ruby’s duck typing concept (“if it walks like a duck and quacks like a duck… then it must be a duck!”). The fact that they named the type “duck” in boo reveals the light hearted and humorous style that went into the creation of boo. I think it makes programming feel a little more casual and fun, boo is not a very self important language.
|
namespace Boo1
import System
import System.Collections
import System.Xml
doc as XmlDocument = XmlDocument()
doc.LoadXml(“<root><child1 att=\”hello\” /><child2 att=\”world!\” /></root>”)
xml as duck = XmlDocumentFu(doc)
hello = xml.root.child1.att.Value
world = xml.root.child2.att.Value
print “${hello} ${world}”
print “Press any key to continue . . . “
Console.ReadKey(true)
|
|
namespace Boo1
import System
import System.Reflection
import Boo.Lang
import System.Xml
class XmlDocumentFu(IQuackFu):
_document as XmlDocument
def constructor(document as XmlDocument):
_document = document
def QuackInvoke(name as string, o as (object)) as object:
return null
def QuackGet(name as string, params as (object)) as object:
node as XmlNode
for child as XmlNode in _document.ChildNodes:
if child.Name == name:
node = child
break
if node is not null:
return XmlNodeFu(node)
ret as duck #this is type duck so you can call indexers optionally below
prop as PropertyInfo = _document.GetType().GetProperty(name, BindingFlags.Instance | BindingFlags.Public)
if prop is not null:
ret = prop.GetValue(_document, null)
if params is not null:
for p in params:
ret = ret[p]
return ret
def QuackSet(name as string, o as (object), value as object) as object:
return null
class XmlNodeFu(IQuackFu):
_node as XmlNode
def constructor(node as XmlNode):
_node = node
def QuackInvoke(name as string, o as (object)) as object:
return null
def QuackGet(name as string, params as (object)) as object:
node as XmlNode
for child as XmlNode in _node.ChildNodes:
if child.Name == name:
node = child
break
if node is not null:
return XmlNodeFu(node)
attribute as XmlAttribute
for att as XmlAttribute in _node.Attributes:
if att.Name == name:
attribute = att
break
if attribute is not null:
return attribute
ret as duck
prop as PropertyInfo = _node.GetType().GetProperty(name, BindingFlags.Instance | BindingFlags.Public)
if prop is not null:
ret = prop.GetValue(_node, null)
if params is not null:
for p in params:
ret = ret[p]
return null
def QuackSet(name as string, params as (object), value as object) as object:
return null
|
For the next Twin Cities Code Camp I am planning on talking about Boo, a very new and interesting .NET language.

It’s truly blowing my mind, check out this example of Syntactic Macros for an example of what I’m talking about. If you want to try boo out for yourself the easiest way to get started is to just install SharpDevelop. Boo comes compeltely integrated out of the box and that’s all you need to do to get going.
My mind is reeling with the possibilities… is this truly the solution to the intentional programming with N levels of embedded DSL’s I’ve been wanting?
You must be logged in to post a comment.