BOO语言和基础 5

Boo is an object-oriented, statically typed programming language for the Common

Language Infrastructure (CLI) with a Python-inspired syntax and a special focus on

language and compiler extensibility. It’s this focus on extensibility that makes it ideally

suited for building DSLs.

Boo is not just a CLR language; it’s also a JVM language–BooJay

 

http://boo.codehaus.org

特点

BooManifesto.pdf

Ø Syntactic sugar for common programming patterns

Ø Automatic variable declaration and type inference

Ø Automatic typecasting

Ø Duck typing

http://boo.codehaus.org/Language+Guide)

Boo能干哪些事的参考

http://docs.codehaus.org/display/BOO/Useful+things+about+Boo

关键特性

Boo’s language-oriented features

Ø String interpolation

name = "dear reader"

print "Hello ${name}"

Ø Is, and, not, and or

customer.CurrentPlan is null and customer.RegisteredAt>SixMonthsAgo

Ø Optional parentheses

SuggestRegisterToClub("Preferred")

SuggestRegisterToClub "Preferred"

Ø Anonymous blocks

ints = GetListOfIntegers()

ints.ForEach do(i): print i

ints.ForEach:

print "foo"

Ø Statement modifiers:turn several statements into a single sentence有:if, unless, and while.

ApplyDiscount(0.5) if customer.IsPreferred

apply_discount_of 0.5 if customer.IsPreferred

Ø Naming conventions

multiple names for a single method is to extend the Boo

compiler in such a way that it automatically translates from one naming convention to

the other

Ø Extension methods

System.String:

classStringExtensions:

[Extension]

staticdefToPascalCase(str as string):

returnchar.ToUpper(str[0]) + str.Substring(1)

使用

importStringExtensions

"some string".ToPascalCase()

Ø Extension properties

classListExtensions:

[Extension]

static Length[list as IList]:

get:

returnlist.Count

importSystem.Collections

importListExtensions

a = ArrayList()

printa.Length

Ø The IQuackFu interface

If it walks like a duck and it quacks like a duck, then it must be an IQuackFu.

Otherlanguages call it duck typing or method missing (or message not understood) and

many dynamic languages support it.

Duck typing basically means that you don’t care what the actual type of an object is.

As long as it supports the operations you need (as long as it walks like a duck), you can

treat it as a valid object (it is a duck).

Rails’ ActiveRecord:

user as User = Users.FindByNameAndPassword("foo", "bar")

That will be translated by the compiler to this:

user as User = Users.QuackInvoke("FindByNameAndPassword", "foo", "bar")

 

Boo interactive shell

Boo interactive shell by just entering booish.exe

Boo interpreter

booi test1.boo

Boo compiler

booc test1.boo

http://home.comcast.net/~brent.hughes/BooWho.htm

控制语句结构

if<BooleanExpression>:

<StatementBlock>

elif<BooleanExpression>:

<StatementBlock>

<moreelif's>

else:

<StatementBlock>

while<BooleanExpression>:

<StatementBlock>

for<Variable> in <RangeOrSequence>:

<StatementBlock>

List Array Hash

a = [4, 9.82, "Help"]

MyArray = (3, 5, 7, 9)

MyStrArray = ("one", "two", "three")

MyHash = { "Susan":3, "Melanie":9, "Cathy":27 }

 

关于DSL 可以参考前面的几个文章 

posted @   2012  阅读(2041)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
历史上的今天:
2011-10-09 ALM TFS/VSTS工具 的Java集成
2010-10-09 ExtJS使用总结和参考
2010-10-09 Microsoft AJAX Client Library规范的实例
2010-10-09 Microsoft AJAX版本历史、功能和参考资源
点击右上角即可分享
微信分享提示