BOO语言和基础 5

简介: Boo is an object-oriented, statically typed programming language for the Common Language Infrastructure (CLI) with a Python-inspired syntax and a spe...

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 可以参考前面的几个文章 

相关文章
|
6月前
|
存储 安全 Java
C#语言特点及基础
C#语言特点及基础
|
程序员 编译器 Linux
V 语言
V 是一门通用的编程语言,也可以作为系统语言,其网站说它非常简单,你可以在一个周末学会,它还说 Go 程序员会对该语言非常熟悉,因为 V 语言在很多方面借鉴了 Go。
188 2
|
4月前
|
存储 Rust 编译器
【Rust学习】03_通用编程概念
您成功了!这是一个相当大的章节:您了解了变量、标量和复合数据类型、函数、注释、 if 表达式和循环!若要练习本章中讨论的概念。
50 2
|
11月前
|
自然语言处理 JavaScript 前端开发
【100 种语言速成】第 2 节:Emojicode
【100 种语言速成】第 2 节:Emojicode
86 0
|
JavaScript 前端开发 Unix
1.C 语言简介
1.C 语言简介
167 0
|
Rust 前端开发 JavaScript
2023年语言和框架我们值得关注什么?
前端新技术一如既往的更新迭代快:前几天 Next.js 大会,邀请了 vercel 的 CEO 来讲 vercel 的认知。顺带推出了 turbopack,号称比 webpack 快 700 倍,比 vite 快 10 倍。又有很多前端同学在问,我们要学 Rust 了吗?新的内容更新迭代太快了,我们跟不上?今年的终端 D2 会有哪些内容?会不会讲 Rust?
209 0
|
Rust 安全 JavaScript
Rust通用编程概念
Rust通用编程概念
|
存储 开发框架 Cloud Native
【C#基础】初识编程语言C#
编程语言C#和.NET平台的介绍以及如何写出自己第一个C#程序。
115 0
|
Rust 前端开发 JavaScript
2022年语言和框架我们值得关注什么?
前端新技术一如既往的更新迭代快:前几天Next.js大会,邀请了vercel的CEO来讲vercel的认知。顺带推出了turbopack,号称比webpack快700倍,比vite快10倍。又有很多前端同学在问,我们要学Rust了吗?新的内容更新迭代太快了,我们跟不上?今年的终端D2会有哪些内容?会不会讲Rust?
131 0
|
SQL 关系型数据库 MySQL
msq语言
控制语言,定义语言,操纵语言
304 0