Core APIs
Class Hierarchy
<type><class>
<function><class><lambda><form><attribute><combination><attribute-name><identifier><index><block>
<quote><argument-list><literal><string-literal><number-literal>
<boolean>
<macro><scope><static-scope><function-scope><method-scope>
<container><enumerable><sequence><string><pair><list><range><ordered-hash><ordered-set><sequence-map><sequence-cycle>
<set><ordered-set>
<hash><map><filter><cycle><sequence-cycle>
<associative><hash><ordered-hash>
Internal DSLs
Lambda
>>> \(a, b) { a + b }
==> (\(a, b) { a.+(b) })
\ is an another name of <argument-list> which is a class to handle expressions of parameters at calling function.
>>> \
==> <argument-list>
Usually it is used to pass the expression of arguments from the calling form to the macro. You can access it via arguments attribute of the <call> instance in the macro body.
>>> mac := <macro> { call.arguments }
==> <macro> { ... }
>>> args := mac(a, name: b, c, 1, plus: 2 + 3)
==> \(a, name: b, c, 1, plus: 2 + 3)
>>> args[0]
==> :a
>>> [args[:name], args[:1]]
==> [:b, :b]
>>> args[:plus]
==> :(2 + 3)
>>> args.identifiers
==> [nil, :name, nil, nil, :plus]
Anyway, it is used to create a new lambda also and defines curly brackets that take function body then return a new function.
>>> signature := \(a, b)
==> \(a, b)
>>> signature { a + b }
==> (\(a, b) { a + b })
Function Declaration (Pattern Matching?)
f(x, y) := x + y
It is translated to the following code.
f := \(x, y) { x + y }
Reference implementation is here.
<call>.prototype.define := \(rvalue: <expression>, context) {
self.function.define(<function>(self.arguments, rvalue), context);
};
Simpler Map Literal
>>> [a: 1, b: 2]
==> Map([:a -> 1, :b -> 2])
List Comprehension
>>> [ x + 1, x: [1, 2, 3, 4], x < 3 ]
==> [2, 3]
BNF is not needed. It can be implemented with macro.
Operators
And
<object>.prototype.and := <macro> {
(self as <boolean>)(
call.arguments[0](call.context),
<constant-function>(self)
)()
}
Or
<object>.prototype.or := <macro> {
(self as <boolean>)(
<constant-function>(self),
call.arguments[0](call.context)
)()
}
Object
<object>.prototype.get-attribute
Memo
<linear-order>
changed October 9, 2010