More Moto 19 examples
David Hakim <dhakim-Gkm/TONP9n1Wk0Htik3J/[email protected]> Fri, 7 Mar 2003 16:40:13 -0500
| Newsgroups | gmane.comp.lang.moto.devel |
|---|---|
| Message-ID | <[email protected]> |
The following example works just fine in the interpreter at this point:
$use("cstdlib")
$use("codex.util")
${
double(double) square = pow(?,2);
double(double) twoToThePow = pow(2,?);
print "square(3) = "+ square(3) + "\n";
print "twoToThePow(4) = "+ twoToThePow(4) + "\n";
SymbolTable s = new SymbolTable();
void(Object) setFoo = s.put("foo",?);
setFoo("bar");
print "The value of foo is: "+<String>s.get("foo") +"\n";
}$
The following example works in both the interpreter and compiler:
$use("codex.util")
$use("cstdlib")
${
// Method Identification
Vector v1 = new Vector();
Vector v2 = new Vector();
Stringset s1 = new Stringset();
void(Object) add = v1.add;
Object(int) get = v1.get;
add("hello");
add("goodbye");
add("hello");
add("goodbye");
add("so");
add("long");
print <String>get(0) + "\n";
print <String>get(1) + "\n";
v1.elements().each(v2.add);
print "Cloned: "+ join(<String[]><Object>v2.toArray(),",") + "\n";
v2.sort(<int(Object,Object)>strcmp);
print "Sorted: "+ join(<String[]><Object>v2.toArray(),",") + "\n";
v2.clear();
v1.elements().each(<void(Object)>s1.add);
s1.elements().each(v2.add);
print "Unique: "+ join(<String[]><Object>v2.toArray(),",") + "\n";
}$