Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,62 @@
import morfa.base;
template <T>
public struct Dynamic
{
var data: Dict<text, T>;
}
// convenience to create new Dynamic instances
template <T>
public property dynamic(): Dynamic<T>
{
return Dynamic<T>(new Dict<text,T>());
}
// introduce replacement operator for . - a quoting ` operator
public operator ` { kind = infix, precedence = max, associativity = left, quoting = right }
template <T>
public func `(d: Dynamic<T>, name: text): DynamicElementAccess<T>
{
return DynamicElementAccess<T>(d, name);
}
// to allow implicit cast from the wrapped instance of T (on access)
template <T>
public func convert(dea: DynamicElementAccess<T>): T
{
return dea.holder.data[dea.name];
}
// cannot overload assignment - introduce special assignment operator
public operator <- { kind = infix, precedence = assign }
template <T>
public func <-(access: DynamicElementAccess<T>, newEl: T): void
{
access.holder.data[access.name] = newEl;
}
func main(): void
{
var test = dynamic<int>;
test`a <- 10;
test`b <- 20;
test`a <- 30;
println(test`a, test`b);
}
// private helper structure
template <T>
struct DynamicElementAccess
{
var holder: Dynamic<T>;
var name: text;
import morfa.io.format.Formatter;
public func format(formatt: text, formatter: Formatter): text
{
return getFormatFunction(holder.data[name])(formatt, formatter);
}
}

View file

@ -0,0 +1,11 @@
person: make object! [
name: none
age: none
]
people: reduce [make person [name: "fred" age: 20] make person [name: "paul" age: 21]]
people/1: make people/1 [skill: "fishing"]
foreach person people [
print reduce [person/age "year old" person/name "is good at" any [select person 'skill "nothing"]]
]

View file

@ -0,0 +1,6 @@
o1 = new point
addattribute(o1,"x")
addattribute(o1,"y")
addattribute(o1,"z")
see o1 {x=10 y=20 z=30}
class point

View file

@ -0,0 +1,4 @@
class Empty{};
var e = Empty(); # create a new class instance
e{:foo} = 42; # add variable 'foo'
say e{:foo}; # print the value of 'foo'

View file

@ -0,0 +1,16 @@
import Foundation
let fooKey = UnsafeMutablePointer<UInt8>.alloc(1)
class MyClass { }
let e = MyClass()
// set
objc_setAssociatedObject(e, fooKey, 1, .OBJC_ASSOCIATION_RETAIN)
// get
if let associatedObject = objc_getAssociatedObject(e, fooKey) {
print("associated object: \(associatedObject)")
} else {
print("no associated object")
}

View file

@ -0,0 +1 @@
{"a":1} as $a | ($a + {"b":2}) as $a | $a

View file

@ -0,0 +1,3 @@
$a|.c = 3
# or equivalently:
$a|.["c"] = 3